【问题标题】:OpenCV Assertion failed with ROIOpenCV 断言失败,投资回报率
【发布时间】:2015-12-23 16:36:00
【问题描述】:

我正在尝试在新窗口中获取每个圆圈,但是出现此错误; 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";
}

}

通过谷歌我找到了这个:OpenCv assertion failed

但是我看不出有什么问题。

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:

    错误意味着您的矩形region 超出了图像src 的范围。

    事实上,你正在用错误的值构造矩形,它应该是:

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

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

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

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

    【讨论】:

    • 绘制矩形时( rectangle(src, Point(x, y), Point(x + h, y + h), Scalar(0, 255, 0), 1, 8); )
    • 是的,这与使用构造函数相同:Rect region(Point(x,y), Point(x+h, y+h));。你也可以像这样画:rectangle(src, Rect(x,y,h,h), ...
    猜你喜欢
    • 2014-04-23
    • 2014-02-10
    • 2022-01-17
    • 1970-01-01
    • 2012-11-26
    • 2014-11-24
    • 2014-05-28
    • 2020-12-31
    • 2015-09-12
    相关资源
    最近更新 更多