Transposing and Flipping Frames on Android Camera
Good morning. I am using Opencv4Android, ver 2.4.5, with Eclipse Juno. I have imported the opencv tutorial into Eclipse, and I have realized that face-detection sample, camera-control sample, ect, work only in landscape mode. I want to use these projects as base for my application, so I want to make possible to use that applications in all rotations of a device. So, I have found that it's possible to transpose and flip on the fly captured frames, in this way:
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screenOrientation = display.getRotation();
switch (screenOrientation){
default:
case ORIENTATION_0: // Portrait
Core.flip(mRgba.t(), mRgba, 1);
break;
case ORIENTATION_90: // Landscape right
// do smth.
break;
case ORIENTATION_270: // Landscape left
// do smth.
break;
}
return mRgba;
}
But the only result is that, in portrait mode, now the camera is only a black screen. The error in the logcat is:
05-24 12:05:55.168: ERROR/cv::error()(15219): OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97
05-24 12:05:55.168: ERROR/org.opencv.android.Utils(15219): nMatToBitmap catched cv::Exception: /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)
05-24 12:05:55.168: ERROR/CameraBridge(15219): Mat type: Mat [ 720*480*CV_8UC4, isCont=true, isSubmat=false, nativeObj=0x40e1f018, dataAddr=0x774c6010 ]
05-24 12:05:55.168: ERROR/CameraBridge(15219): Bitmap type: 720*480
05-24 12:05:55.168: ERROR/CameraBridge(15219): Utils.matToBitmap() throws an exception: /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)
Please help me, if possible.