简体   繁体   English

OpenCV 断言失败,投资回报率

[英]OpenCV Assertion failed with ROI

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 Rect 对象给出正常值: 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使用 Google 我发现了这个: OpenCv assertion failed

However I don't see whats wrong.但是我看不出有什么问题。

The error means that your rectangle region goes out of the bounds of the image src .该错误意味着您的矩形region超出了图像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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM