OpenCV Assertion因ROI而失败

时间:2015-12-23 16:36:01

标签: c++ opencv

我试图在新窗口中获取每个圆圈,但是我得到了这个错误; the error

我不知道为什么会发生这种情况。 Rect对象给出了正常值: rect values

代码:

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";
}

}

通过Google,我找到了这个:OpenCv assertion failed

但我不知道什么是错的。

1 个答案:

答案 0 :(得分:2)

错误表示您的矩形region超出了图片src的范围。

事实上,您正在构建具有错误值的矩形,它应该是:

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

因为第3和第4个参数是宽度和高度,而不是右下角的坐标。

或者您可以使用接受左上角和右下角点的构造函数:

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