Reputation: 1
I am using OpenCV4Android version 2.4.11 I am detecting any rectangular shapes in frames retrieved by camera. for each detected rectangular shape I draw a rectangle arround it. Wha I am trying to do is, to convert the image inside the rectangle into a Mat object then convert that Mat object int Bitmap and display that Bitmap object inside an ImageView as shown below in the code.
The problem is, when i run the below code sometimes the App crashes and displays the below posted logcat output. Actually i could not understand what does that logcat output mean but, i tryed to fix it by specifiying some conditions in the if-statement shown in the code posted below but it did not solve the problem.
please let me know to solve this problem and why i am getting it?
code:
this.mBtnSet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (bounding_rect != null && bounding_rect.width > 0 && bounding_rect.height > 0 && bounding_rect.width > bounding_rect.height && mMatInputFrame != null) {
Mat roi = new Mat(mMatInputFrame, bounding_rect); //<<<<---------- Line 160
Log.w(TAG, "bounding_rectw: " + bounding_rect.width + ", bounding_recth: " + bounding_rect.height);
Log.w(TAG, "ROIw: " + roi.width() + ", ROIh: " + roi.height());
final Bitmap bitmap = Bitmap.createBitmap(roi.width(), roi.height(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(roi, bitmap);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mIVCapture.setImageBitmap(bitmap);
}
});
}
}
});
logcat:
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 /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/core/src/matrix.cpp, line 284
E/org.opencv.core.Mat: Mat::n_1Mat__JIIII() caught cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/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&)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.approxcontour_04, PID: 11436
CvException [org.opencv.core.CvException: cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/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.approxcontour_04.FragOpenCVCam$2.onClick(FragOpenCVCam.java:150)
at android.view.View.performClick(View.java:5721)
at android.widget.TextView.performClick(TextView.java:10930)
at android.view.View$PerformClick.run(View.java:22620)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7331)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
10-25 10:51:21.271 11436-11672/com.example.approxcontour_04 D/CameraBridge: mStretch value: 0.0
Upvotes: 0
Views: 760
Reputation: 1
I solved it by specifying the follwoing conditions in the if-statement
if (bounding_rect != null && mMatInputFrame.width() > bounding_rect.width
&& mMatInputFrame.height() > bounding_rect.height)
Upvotes: 1