Reputation: 1346
I am trying to implement Grabcut in Android from reference code. But when I run the code the following error is generated.
Error:
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat(const cv::Mat&, const Rect&), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp, line 323
I have also read Similar article on Stackoverflow and made following changes in the code but still got the same error.
Changed Part of reference code:
private void backgroundSubtracting(Mat img, Mat background) {
Mat firstMask = new Mat();
Mat bgModel = new Mat();
Mat fgModel = new Mat();
Mat mask;
Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3.0));
dst = new Mat();
Rect rect = new Rect(318,100,513,349); // <= Static value for checking
Imgproc.grabCut(img, firstMask, rect, bgModel, fgModel, 1, 0 /* GC_INIT_WITH_RECT */);
PS: This is my first question so sorry if there are any mistakes in formatting.
Upvotes: 0
Views: 887
Reputation: 836
In my point of view, assertion happens when grabcut rect isn't inside mat.
What is the image dimensions ?
Upvotes: 1