融合其他传感器时,为什么相机帧频会波动? [英] Why does camera frame rate fluctuate when fusing another sensor?

查看:125
本文介绍了融合其他传感器时,为什么相机帧频会波动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android编程的新手,因此在进行研究项目时遇到与视频相关的问题。在该项目中,我们希望构建一个应用程序,该应用程序既使用内置前置摄像头录制的视频,又使用内置加速度计感应的加速度。

I am a new baby in Android programming so that I am facing a problem related to videos when doing my research project. In the project, we would like to build an application which uses both videos recorded by a built-in front camera and acceleration sensed by a built-in accelerometer.

我的问题即使我在源代码中将摄像机固定为30 fps,这些视频的帧速率通常也会从15 fps波动到30 fps。我试图关闭加速度计的数据流以测试帧速率的一致性。但是,它仍然在波动。我在Note 3,Galaxy S4和S5上都测试了这个问题。

My problem is that the frame rate of these videos usually fluctuates from 15 fps to 30 fps even though I have set the camera fixed at 30 fps in the source code. I tried to close the data stream of the accelerometer to test the consistency of the frame rate. However it has been still fluctuated. I tested this problem in both Note 3, Galaxy S4, and S5.

以下代码是我用来在设备中设置前置摄像头的功能

The following code is the function I used to set up the front camera in my devices

private boolean prepareVideoRecorder(String filename, boolean isFrontCam){
    mCamera = Camera.open;
    mMediaRecorder = new MediaRecorder();

    if(mCamera == null) return false;

    Camera.Size size = getBestPreviewSize(1280, 720, mCamera.getParameters());

    if(IS_TABLET){
        mCamera.setDisplayOrientation(0);
    }else{
        mCamera.setDisplayOrientation(90);
    }

    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);

    // Step 2: Set sources
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);

    mMediaRecorder.setOutputFormat(profile.fileFormat);
    mMediaRecorder.setVideoEncoder(profile.videoCodec);
    mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
    mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
    mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);

    // Step 4: Set output file
    mMediaRecorder.setOutputFile(filename);

    // Step 5: Set the preview output
    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

    if(isFrontCam){

        if(IS_TABLET){
            mMediaRecorder.setOrientationHint(180);
        }else{
            mMediaRecorder.setOrientationHint(270);
        }
    }
    else{
        if(IS_TABLET){
            mMediaRecorder.setOrientationHint(0);
        }else{
            mMediaRecorder.setOrientationHint(90);
        }
    }

    mMediaRecorder.setVideoSize(size.width, size.height);
    mMediaRecorder.setVideoFrameRate(30);

    // Step 6: Prepare configured MediaRecorder
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
        Toast.makeText(getBaseContext(), "IllegalStateException preparing MediaRecorder", Toast.LENGTH_SHORT).show();
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
        Toast.makeText(getBaseContext(), "IOException preparing MediaRecorder", Toast.LENGTH_SHORT).show();
        releaseMediaRecorder();
        return false;
    }
    return true;
}

有人可以向我解释为什么视频帧频在这样的情况下会波动吗?编程与相机相关的Android应用程序时的方法?您可以建议我解决这个问题吗?我也已经在其他网站上阅读过该主题,但是不清楚,我也很难理解。

Could anyone explain to me why the frame rate of the video fluctuates in such a way when programming an Android application related to the camera? Is there any solution for this problem that you can suggest me? I have read this topic in other websites as well but it is not clear and hard for me to understand.

谢谢。

推荐答案

我刚刚通过对Camera.Parameters使用setAutoExposureLock(true)和setAutoWhiteBalanceLock(true)来解决此问题。经过一番搜索后,我发现帧频波动的原因与光线条件有关……与照相机的曝光控制有关。

I have just fixed this problem by using setAutoExposureLock(true) and setAutoWhiteBalanceLock(true) for the Camera.Parameters. After some searching efforts, I found that the reason why the frame rate fluctuates was related to the light condition ... so as the exposure control of the camera.

Camera.Parameters params = mCamera.getParameters();
params.setAutoExposureLock(true);
params.setAutoWhiteBalanceLock(true);
mCamera.setParameters(params);

这篇关于融合其他传感器时,为什么相机帧频会波动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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