获取机器人的摄像头的手机架 [英] Get frames from camera's phone in android

查看:126
本文介绍了获取机器人的摄像头的手机架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得从相机的手机帧。所以,我试图捕捉视频和我使用MATLAB找出每这部影片的第二帧,我得到了每10秒250帧。但是,当我使用

 在previewFrame公共无效(byte []的数据,摄像头摄像头){}
 

在Android上,我只能得到每10秒70的帧。 你知道为什么吗?我把我的code如下:

 专用摄像头。previewCallback previewCallBack =新的相机。previewCallback(){
    @覆盖
    在previewFrame(byte []的数据,摄像头摄像头){公共无效

        的System.out.println(获取框架+ frameNumber的);
        如果(数据== NULL)
            抛出新的NullPointerException();
        Camera.Parameters p值= camera.getParameters();
        Camera.Size大小= p.get previewSize();
        如果(frameNumber的== 0){
            的startTime = System.currentTimeMillis的();
        }
        // Log.e(的GetData,获取框架+ frameNumber的);
        frameNumber的++;

        camera.addCallbackBuffer(数据);

            }
      }
 

解决方案

这是真的; Android的录像机不使用相机。previewCallback ,并且它可以是比你与Java回调得到快得多。其原因是,它可以从摄像机发送的图像帧的硬件连接在内核内codeR,而没有把像素到用户空间

不过,我确实在Java中先进的设备达到30 FPS,如Nexus 4和银河S3。秘诀是:避免垃圾回收利用的 Camera.set previewCallbackWithBuffer(),并通过使用的事件循环

自然地,preVIEW回调本身应尽可能彻底优化成为可能。在您的样品中,调用 camera.getParameters()是缓慢的,是可以避免的。不分配()应作出。

I would like to get frames from camera's phone. So, i try to capture video and i use matlab to find frames per second of this video, i got 250 frames per 10 seconds. But when i use

public void onPreviewFrame(byte[] data, Camera camera) {}

on Android, i only get 70 frames per 10 seconds. Do you know why? I put my code below:

private Camera.PreviewCallback previewCallBack = new Camera.PreviewCallback() {
    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {

        System.out.println("Get frame " + frameNumber);
        if (data == null)
            throw new NullPointerException();
        Camera.Parameters p = camera.getParameters();
        Camera.Size size = p.getPreviewSize();
        if (frameNumber == 0) {
            startTime = System.currentTimeMillis();
        }
        // Log.e("GetData", "Get frame " + frameNumber);
        frameNumber++;

        camera.addCallbackBuffer(data);

            }
      }

解决方案

That's true; Android video recorder does not use Camera.PreviewCallback, and it may be much faster than what you get with Java callbacks. The reason is that it can send the video frame from camera to the hardware encoder inside the kernel, without ever putting the pixels into user space.

However, I have reliably achieved 30 FPS in Java on advanced devices, like Nexus 4 or Galaxy S3. The secrets are: to avoid garbage collection by using Camera.setPreviewCallbackWithBuffer(), and to push the callbacks off the UI thread by using an eventLoop.

Naturally, the preview callback itself should be optimized as thoroughly as possible. In your sample, the calls to camera.getParameters() is slow and can be avoided. No allocations (new) should be made.

这篇关于获取机器人的摄像头的手机架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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