Ask Your Question
0

Why my App crashes when i applied Imgproc.resize

asked 2019-10-20 03:36:37 -0500

wade wang gravatar image

updated 2019-10-20 03:42:52 -0500

berak gravatar image

As the illustration shows, now i have the 'original' frame, not fill fully the screen. And i expect to got a fullscreen frame like below part, so i choose using imgproc.resize to achieve this, but when i run my app on the mobilephone, the app quit unexpectedly, i don't know why, anyone can help me ? Thanks ! image description

Here is some related code:

    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

            Mat frame = inputFrame.rgba();
            Mat dst = new Mat();
            Imgproc.resize(frame,dst,new Size(),1.5,1.5,Imgproc.INTER_LINEAR);
            frame.release();
            return dst;
}

And this is debug error report:

E/cv::error(): OpenCV(3.4.7) 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 /build/3_4_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp, line 101
E/org.opencv.android.Utils: nMatToBitmap caught cv::Exception: OpenCV(3.4.7) /build/3_4_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp:101: error: (-215:Assertion failed) 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 [ 1620*2880*CV_8UC4, isCont=true, isSubmat=false, nativeObj=0xffffffffc9934a88, dataAddr=0xffffffffc3100000 ]
E/CameraBridge: Bitmap type: 1920*1080
E/CameraBridge: Utils.matToBitmap() throws an exception: OpenCV(3.4.7) /build/3_4_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp:101: error: (-215:Assertion failed) 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

Comments

1

please do not release the frame Mat (you did not construct it), and dst should be a class member and only initialized once, else you have a memleak there.

berak gravatar imageberak ( 2019-10-20 03:46:20 -0500 )edit

Thanks, berak ! I have move the ”Mat dst = new Mat();“ to outside, and delete "frame.release();". But in this way,i got another error: E/uardonxiaomi8s: No implementation found for long org.opencv.core.Mat.n_Mat() (tried Java_org_opencv_core_Mat_n_1Mat and Java_org_opencv_core_Mat_n_1Mat__) D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.iguardonxiaomi8se, PID: 5366 java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.core.Mat.n_Mat() (tried Java_org_opencv_core_Mat_n_1Mat and Java_org_opencv_core_Mat_n_1Mat__) ........ What's the wrong?

wade wang gravatar imagewade wang ( 2019-10-20 03:56:24 -0500 )edit

No implementation found

this means, you try to use opencv code, before the native libs are loaded. (put it into onCameraViewStarted() or such, NOT into the constructor)

berak gravatar imageberak ( 2019-10-20 03:59:48 -0500 )edit

I don't quite understand, you mean i can't use Imgproc.resize in public Mat onCameraFrame( ) ? But if i use Imgproc.cvtColor or Imgproc.threshold etc., it is OK. And if i put Imgproc.resize(frame,dst,new Size(),1.5,1.5,Imgproc.INTER_LINEAR); in onCameraViewStarted(), android studio cannot resolve symbol 'frame'. Please forgive me for such a elementary question ...

wade wang gravatar imagewade wang ( 2019-10-20 04:16:44 -0500 )edit

yea, it's complicated and painful.

you may do whatever you want in onCameraFrame() (and your resize() code has to stay there !), but the 1st possible place, where you can use opencv code is onCameraViewStarted(); (that's where you have to put the dst = new Mat(); . and again, dst should be a class member.

please have another look at opencv's android examples !

berak gravatar imageberak ( 2019-10-20 04:28:44 -0500 )edit

Sir, when I was about to give up resize, the miracle appeared. I ran the App without resize on the phone again. The preview size is exactly 1920*1080 that i expected !Previously my preview size is like the first image of above illustration, I don't know why this time preview size suddenly changed.Is it my previous resize command that forced the opencv to choose the largest preview size?

wade wang gravatar imagewade wang ( 2019-10-20 07:08:37 -0500 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2019-10-31 11:07:09 -0500

wade wang gravatar image

Add cameraBridgeViewBase.setMaxFrameSize(1280, 720); in protected void onCreate(Bundle savedInstanceState) {} is fine !

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-10-20 03:36:37 -0500

Seen: 40 times

Last updated: Oct 31