首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV错误: matrix.cpp第522行断言失败,/matrix.cpp:522: Error:(-215)

OpenCV错误: matrix.cpp第522行断言失败,/matrix.cpp:522: Error:(-215)
EN

Stack Overflow用户
提问于 2017-03-31 13:12:00
回答 1查看 3.4K关注 0票数 2

我试图在检测到的面部上方创建一个ROI,以放置一顶帽子,如图中所示: Plz单击此处:在上面创建的ROI来放置帽子

我已经确保ROI创建的是与图像的界限。如下所示: //创建ROI //其中face是检测到的face ROI

代码语言:javascript
复制
    if (0<=face.x && 0<=face.x-face.width*0.08<=image.cols && 0<=face.x+face.width+face.width*0.08<=image.cols 
         && 0<=face.y && 0<=face.y-face.height*0.28<=image.rows)
    {
      Mat ROI_hat = image(Rect(abs(face.x-face.width*0.08),abs(face.y-face.height*0.28),abs(face.x+face.width+face.width*0.08),abs(face.y)));
      rectangle(image,Point(abs(face.x-face.width*0.08),abs(face.y-face.height*0.28)),Point(abs(face.x+face.width+face.width*0.08),abs(face.y)),Scalar(255, 0, 0), 1, 4);

      cout<<"Within the bounds of Image"<<endl;
    }
    else{
     cout<<" Out of bounds of Image "<<endl;
        }

没有负值,并且对于每一个帧,它说ROI是有界的。但我仍然得到断言错误:

/home/user/OpenCV_Installed/opencv-3.2.0/modules/core/src/ma‌​trix.cpp,文件中的OpenCV错误:断言失败(0 <= roi.x &0 <= roi.width && roi.x + roi.width <= m.cols &0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows)/home/user/OpenCV_Installed/opencv-3.2.0/modules/core/src/ma‌​trix.cpp:522:错误:(-215) 0 <= roi.x &0 <= roi.width && roi.x + roi.width <= m.cols &0 <= <= m.cols&0 <= roi.height && 0<= roi.height && roi.y +roi.height<= m.rows

谁能告诉我哪里出错了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-31 13:31:33

这个错误意味着你的ROI在图像之外,所以你的条件是错误的。

由于很容易混淆,所以我通常应用这个小技巧,它基于roi与包含所有图像的虚拟roi roiImg的交集:

代码语言:javascript
复制
Rect roiImg(0, 0, image.cols, image.rows);
Rect roi = ... // Very complex way of setting up the ROI

if( (roi.area() > 0) && ((roiImg & roi).area() == roi.area()) ) {
    // roi is inside the image, and is non-empty
    // VALID roi
} else {
    // roi is at least partially outside of the image, or it's empty
    // INVALID roi
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43141613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档