Reputation: 1040
I'm currently developing an Android face detection app, and I'm wondering how I can slow down the capture frame rate purposefully. Currently it is around 30fps, and all I really require is 5-10fps. That way I don't need to use up additional processing which can be used on other tasks.
I'm wondering if a Thread.sleep()
is all that is needed to do the trick, or should I look into setting it via cvSetCaptureProperty(CvCapture* capture, int property_id, double value)
? I read that it only works on certain cameras though, and is, for the most part, useless...
I have also read about setting maximum frame size (e.g. mOpenCvCameraView.setMaxFrameSize(640, 480);
) but... it doesn't make sense to me to do that?..
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;
}
Any advice is greatly appreciated! Thanks.
Upvotes: 1
Views: 1476
Reputation: 16
Running:
SystemClock.sleep(...);
in onCameraFrame works well for me and reduces power usage of the app.
Upvotes: 0
Reputation: 5354
I don't recommend to you to use cvSetCaptureProperty()
because its behaviour is very rhapsodic.
You should rather register the timestamp of last frame arrived (and processed) to onCameraFrame()
and return from the event handler if the difference between last timestamp and now is less then ~100 ms.
Upvotes: 1
Reputation: 1238
You can use a counter. Let's say fps=30, and you want to process only 5fs, then we have:
class YourClass{
int counter = 0;
// Your code
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
counter++;
if (counter < 6)
return null;
counter = 0;
//Your processing code here
}
}
Upvotes: 0