【问题标题】:Android OpenCV: How to slow down camera capture frame rate (purposefully)Android OpenCV:如何降低相机捕捉帧率(有目的地)
【发布时间】:2015-03-04 07:01:55
【问题描述】:

我目前正在开发一款 Android 人脸检测应用,我想知道如何有目的地降低捕获帧速率。目前它大约是 30fps,而我真正需要的是 5-10fps。这样我就不需要用尽可用于其他任务的额外处理。

我想知道Thread.sleep() 是不是只需要or should I look into setting it via cvSetCaptureProperty(CvCapture* capture, int property_id, double value)?我读到它只适用于某些相机,并且在大多数情况下是无用的......

我还阅读了有关设置最大帧大小的信息(例如mOpenCvCameraView.setMaxFrameSize(640, 480);),但是……这样做对我来说没有意义吗?……

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    mRgba = inputFrame.rgba();
    mGray = inputFrame.gray();

    if (mAbsoluteFaceSize == 0) {
        int height = mGray.rows();
        if (Math.round(height * mRelativeFaceSize) > 0) {
            mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
        }
        mNativeDetector.setMinFaceSize(mAbsoluteFaceSize);
    }

    MatOfRect faces = new MatOfRect();

    if (mDetectorType == JAVA_DETECTOR) {
        if (mJavaDetector != null)
            mJavaDetector.detectMultiScale(mGray, faces, SCALE_FACTOR, MIN_NEIGHBOURS, 2, 
                    new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
    }
    else if (mDetectorType == NATIVE_DETECTOR) {
        if (mNativeDetector != null)
            mNativeDetector.detect(mGray, faces);
    }
    else {
        Log.e(TAG, "Detection method is not selected!");
    }

    //put thread to sleep to slow capture?  
    try {
        Thread.sleep(50);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return mRgba;
}

非常感谢任何建议!谢谢。

【问题讨论】:

    标签: android opencv android-camera frame-rate


    【解决方案1】:

    我不建议你使用cvSetCaptureProperty(),因为它的行为非常狂妄。

    您应该将最后一帧到达(和处理)的时间戳注册到onCameraFrame(),如果最后一个时间戳与现在之间的差异小于约 100 毫秒,则从事件处理程序返回。

    【讨论】:

      【解决方案2】:

      您可以使用计数器。假设 fps=30,而您只想处理 5fs,那么我们有:

      class YourClass{
         int counter = 0;
         // Your code
         public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
            counter++;
            if (counter < 6)
                return null;
            counter = 0;
            //Your processing code here
         }
      
      }
      

      【讨论】:

        【解决方案3】:

        跑步:

        SystemClock.sleep(...);

        在 onCameraFrame 中对我来说效果很好,并且可以减少应用程序的耗电量。

        【讨论】:

          猜你喜欢
          • 2017-02-10
          • 1970-01-01
          • 1970-01-01
          • 2018-02-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-11-20
          相关资源
          最近更新 更多