安卓:访问硬件摄像头preVIEW帧数据,而不把他们拉 [英] Android: Accessing hardware camera preview frame data without drawing them

查看:231
本文介绍了安卓:访问硬件摄像头preVIEW帧数据,而不把他们拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据从Java SDK的一侧的机器人照相机的文档,相机preVIEW帧必须以访问该帧数据被提供一个(可见和活动的)表面被吸引到。我有联系的几个我所遇到这里的东西(我新,因此上限为2超链接),但我走过去吨各种事物文档清盘张贴我自己的问题在这里SO之前。

According to the android camera docs from the Java SDK side, the camera preview frames have to be supplied a (visible and active) surface to be drawn to in order to access the frame data. I have linked a few of the things I have come across here (I'm new so capped at 2 hyperlinks), but I went over tons of documentation of various things before winding up posting my own question here on SO.

一)我明确不希望绘制相机preVIEW到屏幕上,我只想字节的数据(我可以从这里得到),直接从相机缓冲如果可能的话。

a) I explicitly don't want to draw the camera preview to the screen, I just want the byte data (which I can get from here) straight from the camera buffer if possible.

b)是,我看到了这一点: Android摄像头没有preVIEW

b) Yes, I saw this: Android Camera without Preview.

不过,这决定了使用这个库的应用程序必须插入这个(貌似)任意查看到他们的应用程序布局,这已是可见的所有的时间(他们不能切换布局,父容器的变化知名度或使用子活动)期间的应用程序的生命周期。

However, this dictates that apps using this library have to insert this (seemingly) arbitrary view into their app layout, which has to be visible all the time (they can't switch layouts, change visibility of parent containers or use a subactivity) during app life-cycle.

其实,我的需求是类似<一个href="http://stackoverflow.com/questions/9744790/android-possible-to-camera-capture-without-a-$p$pview">this海报的,但我希望相机preVIEW数据的连续实时数据流,而不是捕捉保存到图像磁盘上。因此, PictureCallback 适用于他一起 myCamera.takePicture 通话。由于显而易见的原因,写连续捕捉到磁盘不是我一个解决方案,这样就不会在我的情况下工作。 myCamera.takePicture 比获得preVIEW框架也慢得多。

In fact, my needs are similar to this poster's, except I want continuous real-time stream of the camera preview data, not a capture saved to image on disk. Hence PictureCallback works for him together with the myCamera.takePicture call. For obvious reasons, writing continuous captures to disk is not a solution for me, so that won't work in my case. myCamera.takePicture is also much slower than getting the preview frames.

三)我已经开始与NDK涉足,并且已经获得了pretty的良好的感觉吧。然而,根据此内容通过本地访问相机数据只是不支持或推荐,并为设备兼容性一个巨大的麻烦,即使在当时。

c) I have started dabbling with the NDK, and have gotten a pretty good feel for it. However, according to this accessing camera data via native is just not supported or recommended, and a huge hassle for device compatibility even then.

如果这是过时的,并且有坚实的NDK航线上采集Android设备摄像头数据,我找不到他们,所以,如果你能指出来,我认为将是巨大的。

If this is outdated, and there are solid NDK routes to acquiring camera data from android devices, I couldn't find them, so if you could point them out to me that would be great.

D)我想使这个图书馆从像统一的工具访问(在一个统一的插件的形式),为此,我希望能够只编译成JAR(或者是.so本机),并期望它上班的导入方式,使他们可以使用相机而无需从应用程序开发者需要特定的UI /布局配置库中的Andr​​oid应用程序。

d) I want to make this library accessible from tools like Unity (in the form of a unity plugin), for which I want to be able to just compile it into a JAR (or .so for native) and expect it to work on android apps that import the library that way so that they can use the camera without specific UI/layout configurations needed from the app developer.

我希望能够建立在Android应用使用视觉处理库,并且不希望使用图书馆必须使用特定的应用程序布局和借鉴的具体意见屏幕,以限制应用程序利用视觉处理结果 - 一个非常简单的例子,如果一个应用程序要利用我的图书馆获得的摄像头看到的平均颜色,并希望着色的图像在屏幕上的颜色

I want to be able to create a vision-processing library for use in android apps, and don't want to limit the apps using the library to have to use specific app layouts and draw specific views to the screen in order to use the vision processing results - for a very simple example, if an app wants to use my library to get the average color of what the camera sees, and wants to tint an image on the screen that color.

无论建议我可以对任何我将是超级有帮助的分拿到。非常感谢您的时间!

Whatever suggestions I can get towards any of the points I have will be super-helpful. Thanks a lot for your time!

推荐答案

我完全忘了我有这个问题了。 2年,一对夫妇的Andr​​oid SDK版本后,我们有一个工作系统。

I completely forgot I had this question up. 2 years and a couple of Android SDK versions later, we have a working system.

我们正在使用扩展​​表面纹理 cameraSurface 与引用所需的摄像机。使用cameraSurface的表面纹理,我们称之为

We're using an extended SurfaceTexture, cameraSurface with a reference to the required camera. Using cameraSurface's SurfaceTexture, we call

mCamera.setPreviewTexture(mSurfaceTexture);
mCamera.startPreview();

然后覆盖当前活跃相机的 previewCallback 从你的活动或任何你需要它。

Then override the current active camera's previewCallback from your activity or wherever you need it.

mCamera.setPreviewCallback(new PreviewCallback() {

     public void onPreviewFrame(final byte[] data, final Camera camera) {
         // Process the contents of byte for whatever you need
     }
});

这可让您连续处理摄像头所看到的,而不是仅仅不必经过保存的图像。当然,这将是有限的,以你的相机的preVIEW分辨率(可能是从静止拍摄或视频分辨率不同)。

This allows you to continuously process what the camera sees, rather than just having to go through stored images. Of course, this will be limited to your camera's preview resolution (which may be different from the still capture or video resolutions).

如果我得到的时候,我会试着扔了一个准系统的工作演示。 BitGym免费提供的的Andr​​oid SDK 由code我上面提到的包裹,但它有很多其他的细节,使它更难梳理出只是你想使你的相机处理应用程序的部分。

If I get the time, I'll try to throw up a barebones working demo. BitGym's freely available Android SDK is wrapped by the code I mentioned above, but it has a lot of other details that make it harder to tease out just the parts you want to make your camera-processing app.

这篇关于安卓:访问硬件摄像头preVIEW帧数据,而不把他们拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆