Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

CvException on OpenCV4Android

I try to get my ROI by touching on the screen and save ROI to a mat. This is the part where the error occur.

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    Mat rgba = inputFrame.rgba();
    Mat roi_mat = new Mat();

    if (startX!=0 && endX!=0){
        //Toast.makeText(this, "start:"+start_point+"   end:"+end_point, Toast.LENGTH_SHORT).show();
        Core.rectangle(rgba,start_point,end_point,border_colour,0,8, 0 );
        roi_rect = new Rect(startX,startY,(endX-startX),(endY-startY));
        Mat roi_mat_ref = new Mat(rgba,roi_rect);
        roi_mat_ref.copyTo(roi_mat);
        //rgba.copyTo(roi_mat);

    }
    return rgba;
}

Everything is okay when running the application. But when i want to get the ROI, it show an error.

10-04 20:19:18.754 6794-6859/com.example.tew.roi E/cv::error()﹕ OpenCV Error: Assertion failed (0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows) in cv::Mat::Mat(const cv::Mat&, const cv::Range&, const cv::Range&), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp, line 284

10-04 20:19:18.755 6794-6859/com.example.tew.roi E/org.opencv.core.Mat﹕ Mat::n_1Mat__JIIII() caught cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp:284: error: (-215) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function cv::Mat::Mat(const cv::Mat&, const cv::Range&, const cv::Range&)

10-04 20:19:18.755 6794-6859/com.example.tew.roi W/dalvikvm﹕ threadid=11: thread exiting with uncaught exception (group=0x40fbf258)

10-04 20:19:18.756 6794-6859/com.example.tew.roi E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-3348

     CvException [org.opencv.core.CvException: cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp:284: error: (-215) 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows in function cv::Mat::Mat(const cv::Mat&, const cv::Range&, const cv::Range&)
]

        at org.opencv.core.Mat.n_Mat(Native Method)
        at org.opencv.core.Mat.<init>(Mat.java:676)
        at com.example.tew.roi.MainActivity.onCameraFrame(MainActivity.java:154)
        at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)
        at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:346)
        at java.lang.Thread.run(Thread.java:856)

My full coding