简体   繁体   English

OpenCV错误:断言在matrix.cpp第522行/matrix.cpp:522中失败:错误:(-215)

[英]OpenCV Error: Assertion failed in matrix.cpp line 522, /matrix.cpp:522: error: (-215)

I am trying to create an ROI above the face detected to place a hat like shown in the image: Plz click here : ROI created above face to place a hat 我正在尝试在检测到的面部上方创建ROI,如图所示:Plz单击此处: 在面部上方创建ROI以放置帽子

I have made sure that the ROI created is withing the bounds of the image. 我已确保创建的ROI与图像的边界一致。 It looks like this: // Create an ROI // where face is the detected face ROI 看起来像这样://创建ROI // //人脸是检测到的人脸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;
        }

There are no negative values and for every frame it says ROI is withing the bounds. 没有负值,并且对于每个框架来说,ROI都在极限范围之内。 But I still get assertion error: 但是我仍然得到断言错误:

OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in Mat, file /home/user/OpenCV_Installed/opencv-3.2.0/modules/core/src/ma‌​trix.cpp, line 522 terminate called after throwing an instance of 'cv::Exception' what(): /home/user/OpenCV_Installed/opencv-3.2.0/modules/core/src/ma‌​trix.cpp:522: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function Mat Aborted (core dumped) 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)在Mat中,文件/home/user/OpenCV_Installed/opencv-3.2.0/modules/core/src/ma‌trix.cpp,在抛出'cv实例后,第522行终止:: Exception'what():/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 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m。行在Mat Mat Aborted(core倾倒)

Can someone please tell me where I'm going wrong? 有人可以告诉我我要去哪里了吗?

The error means that your ROI is outside of the image, so your conditions are wrong. 该错误表示您的投资回报率在图像之外,因此您的条件是错误的。

Since it's pretty easy to get confused, I usually apply this small trick that is based on the intersection of the roi with a dummy roi roiImg that contains all the image: 由于很容易感到困惑,因此我通常会应用此小技巧,该技巧基于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
}

暂无
暂无

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

相关问题 opencv断言失败(matrix.cpp第508行) - opencv assertion failed (matrix.cpp line 508) OpenCV:Matrix.cpp中的未知数组类型错误 - OpenCV: Unknown Array Type error in Matrix.cpp 断言失败&lt;0 &lt;= i &amp;&amp; i &lt; <int> 未知函数中的vv.size &lt;&gt;&gt;,文件src \\ matrix.cpp,第912行 - Assertion Failed <0 <= i && i < <int>vv.size<>> in unknown function, file src\matrix.cpp, line 912 OpenCV错误:断言在cv :: Mat行522中失败 - OpenCV Error: Assertion failed in cv::Mat line 522 OpenCV错误:相机校准:断言matrix_wrap.cpp中失败 - OpenCV Error: Camera Calibration: Assertion failed in matrix_wrap.cpp OpenCV错误:断言失败,mat.cpp行537 - OpenCV Error: Assertion failed, mat.cpp line 537 OpenCV错误:断言失败(scn == 3 || scn == 4)在cv :: cvtColor中,文件.. \\ .. \\ .. \\ .. \\ opencv \\ modules \\ imgproc \\ src \\ color.cpp,第3737行 - OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv:: cvtColor, file ..\..\..\..\opencv\modules\imgproc\src\color.cpp, line 3737 OpenCV错误:重复断言失败(ny&gt; 0 &amp;&amp; nx&gt; 0),文件opencv / modules / core / src / copy.cpp, - OpenCV Error: Assertion failed (ny > 0 && nx > 0) in repeat, file opencv/modules/core/src/copy.cpp, opencv错误:校准摄像机时,convert.cpp(opencv)中的断言失败 - opencv error: assertion failed in convert.cpp (opencv) when i calibrate a camera cpp中的LEDA库“断言”错误? - LEDA library in cpp 'assertion' error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM