Android OpenCV 3.4.1 DNN tutorial broken

asked 2018-05-16 12:48:44 -0500

https://docs.opencv.org/master/d0/d6c...

I am trying to follow this tutorial verbatim

Mat blob = Dnn.blobFromImage(frame, IN_SCALE_FACTOR,
                new Size(IN_WIDTH, IN_HEIGHT),
                new Scalar(MEAN_VAL, MEAN_VAL, MEAN_VAL), false   );

This blogFromImage method signature is no longer valid, it has two boolean values. I have added another boolean value to make the code compile

i.e

Mat blob = Dnn.blobFromImage(frame, IN_SCALE_FACTOR,
            new Size(IN_WIDTH, IN_HEIGHT),
            new Scalar(MEAN_VAL, MEAN_VAL, MEAN_VAL), false,false   );

I have installed the OpenCV Manager 3.4.1 from the SDK on to the Android Device.

When I run this tutorial code, I get the following exception thrown

E/cv::error(): OpenCV(3.4.1) Error: Unspecified error (FAILED: fs.is_open(). Can't open "") in bool cv::dnn::ReadProtoFromTextFile(const char, google::protobuf::Message), file /build/master_pack-android/opencv/modules/dnn/src/caffe/caffe_io.cpp, line 1119 E/org.opencv.dnn: dnn::readNetFromCaffe_10() caught cv::Exception: OpenCV(3.4.1) /build/master_pack-android/opencv/modules/dnn/src/caffe/caffe_io.cpp:1119: error: (-2) FAILED: fs.is_open(). Can't open "" in function bool cv::dnn::ReadProtoFromTextFile(const char, google::protobuf::Message) D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: nirmanamoha.jithasangayoga.passengercounter, PID: 13510 CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.1) /build/master_pack-android/opencv/modules/dnn/src/caffe/caffe_io.cpp:1119: error: (-2) FAILED: fs.is_open(). Can't open "" in function bool cv::dnn::ReadProtoFromTextFile(const char, google::protobuf::Message) ] at org.opencv.dnn.Dnn.readNetFromCaffe_0(Native Method) at org.opencv.dnn.Dnn.readNetFromCaffe(Dnn.java:108) at nirmanamoha.jithasangayoga.passengercounter.MainActivity.onCameraViewStarted(MainActivity.java:62) at org.opencv.android.CameraBridgeViewBase.processEnterState(CameraBridgeViewBase.java:323) at org.opencv.android.CameraBridgeViewBase.checkCurrentState(CameraBridgeViewBase.java:313) at org.opencv.android.CameraBridgeViewBase.surfaceChanged(CameraBridgeViewBase.java:198) at android.view.SurfaceView.updateWindow(SurfaceView.java:591) at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176) at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1970) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:550) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Can any one throw some help to get this going.

edit retag flag offensive close merge delete

Comments

According error message, the problem is in readNetFromCaffe method, please show how you load the model.

dkurt gravatar imagedkurt ( 2018-05-16 13:57:41 -0500 )edit

I have fixed this, the problem was the model files went missing from the build directory even though I copied them there - not sure whether Androidstudio deleted the folder when I was trying to rebuild. The tutorial says the model files need to be copied to build directory and not to the source directory assets - is it not supposed to be in the source directory assets?

ImageCounter gravatar imageImageCounter ( 2018-05-17 02:15:41 -0500 )edit