-4
for (size_t i = 1; i < count + 1; i++) {

        Mat img = vFrames[i - 1].Image1;
        Mat half1(mFinalImage, cv::Rect(-final_vector[i - 1].x + minx + abs(minx), -final_vector[i - 1].y - miny + abs(maxy), img.cols, img.rows));
        img.copyTo(half1);
    }
Mat half1(mFinalImage, cv::Rect(-final_vector[i - 1].x + minx + abs(minx), -final_vector[i - 1].y - miny + abs(maxy), img.cols, img.rows)); in line 

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,

I often get such an error, what is the reason and solution

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • 1
    *what is the reason* -- The assertion is telling you the reason. That's the whole point of an assertion. – PaulMcKenzie Aug 25 '22 at 08:26
  • The reason is simple. The rectangle you are passing to the constructor has invalid bounds for `mFinalImage`. Use a debugger or print out the values to see which part is incorrect. – john Aug 25 '22 at 08:26
  • This code would be much simpler if the loop was `for (size_t i = 0; i < count; ++i)`. That way you wouldn't have to keep writing `i - 1`. Loops should almost always run from 0 to their upper limit. – Pete Becker Aug 25 '22 at 13:35

1 Answers1

1

The assertion error message explains it. One of the following statements in the constructor of Mat is false, however all should hold.

0 <= roi.x
0 <= roi.width
roi.x + roi.width <= m.cols
0 <= roi.y
0 <= roi.height
roi.y + roi.height <= m.rows

Probably the region of interest is not within the matrix. Ensure that the dimensions of rectangle stays in the matrix.

  • I realized my mistake, it was trying to place the picture at more than one point because different points were wrong. Thank you – omerkilicceker Aug 25 '22 at 12:11