我试图在检测到的面部上方创建一个ROI,以放置一顶帽子,如图中所示: Plz单击此处:在上面创建的ROI来放置帽子。
我已经确保ROI创建的是与图像的界限。如下所示: //创建ROI //其中face是检测到的face ROI
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/matrix.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/matrix.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
谁能告诉我哪里出错了吗?
发布于 2017-03-31 13:31:33
这个错误意味着你的ROI在图像之外,所以你的条件是错误的。
由于很容易混淆,所以我通常应用这个小技巧,它基于roi与包含所有图像的虚拟roi roiImg的交集:
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
}https://stackoverflow.com/questions/43141613
复制相似问题