2

I'm trying to get every circle in a new window, however I get this error; the error

I don't know why that happends. The Rect object gives normal values: rect values

Code:

void scanCircle(int x, int y, int h, Mat src, int rad) {
try {
    Rect region = Rect(x, y, x + h, y + h);
    Mat roi = src(region).clone();
}
catch (...) {
    cout << "Error";
}

}

With Google I found this one: OpenCv assertion failed

However I don't see whats wrong.

Community
  • 1
  • 1
Dylan
  • 33
  • 4

1 Answers1

2

The error means that your rectangle region goes out of the bounds of the image src.

In fact you're constructing the rectangle with wrong values, it should be:

Rect region(x, y, h, h);

since 3rd and 4th arguments are width and height, not the coordinates of the bottom right point.

Or you can use the constructor that accepts top-left and bottom-right points:

Rect region(Point(x,y), Point(x+h, y+h));
Miki
  • 40,887
  • 13
  • 123
  • 202
  • When you draw a rectangle ( rectangle(src, Point(x, y), Point(x + h, y + h), Scalar(0, 255, 0), 1, 8); ) – Dylan Dec 23 '15 at 16:54
  • Yes, that's the same as using constructor: `Rect region(Point(x,y), Point(x+h, y+h));`. You can also draw like: `rectangle(src, Rect(x,y,h,h), ...` – Miki Dec 23 '15 at 16:56