How to return and show only cropped area on CameraView?

asked 2016-05-30 15:35:34 -0500

redleon80 gravatar image

I cand cropped CameraFrame. When I return the cropped area then I'm getting error.

 public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

        Mat imgSrc = inputFrame.rgba;

        Point fPoint = new Point(0, imgSrc.rows()/6);
        Point lPoint = new Point(imgSrc.cols(), imgSrc.rows()*5/6);
        Rect rect = new Rect(fPoint, lPoint);

        Imgproc.rectangle(imgSrc, fPoint, lPoint, new Scalar(0, 255, 0));

        Mat croppedImage = new Mat(imgSrc, rect);

        return croppedImage;
    }

And getting this error:

E/cv::error(): 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 /Volumes/Linux/builds/master_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp, line 97
E/org.opencv.android.Utils: nMatToBitmap catched cv::Exception: /Volumes/Linux/builds/master_pack-android/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)
E/CameraBridge: Mat type: Mat [ 320*864*CV_8UC4, isCont=true, isSubmat=true, nativeObj=0x5f773ff8, dataAddr=0x60cb4810 ]
E/CameraBridge: Bitmap type: 864*480
E/CameraBridge: Utils.matToBitmap() throws an exception: /Volumes/Linux/builds/master_pack-android/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)
edit retag flag offensive close merge delete