Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 理解opencvc+中的Rect+;_C++_Opencv_Rect - Fatal编程技术网

C++ 理解opencvc+中的Rect+;

C++ 理解opencvc+中的Rect+;,c++,opencv,rect,C++,Opencv,Rect,我试图在矩形内标记像素。要标记的矩形在if-else构造中确定。我在使用if else块中定义的矩形时遇到以下错误: “当您计算(x,y)时,断言失败(0)内点和外点的坐标为了构建矩形,您必须检查通过添加或减去pt1或pt2 r.weight或r.height得到的坐标不会从图像中消失。当您的脸靠近图像边缘时,这种情况非常常见 这可以很容易地通过做以下事情来实现 pt1.x = r.x; pt1.y = r.y; pt2.x = pt1.x + r.width; if(pt2.x >= i

我试图在矩形内标记像素。要标记的矩形在if-else构造中确定。我在使用if else块中定义的矩形时遇到以下错误: “当您计算(x,y)时,断言失败(0)内点和外点的坐标为了构建矩形,您必须检查通过添加或减去pt1或pt2 r.weight或r.height得到的坐标不会从图像中消失。当您的脸靠近图像边缘时,这种情况非常常见

这可以很容易地通过做以下事情来实现

pt1.x = r.x;
pt1.y = r.y;
pt2.x = pt1.x + r.width;
if(pt2.x >= image.cols) //check that coordinate pt2.x doesn't get out of the image
    pt2.x = image.cols;

pt2.y = pt2.y + r.height;
if(pt2.y >= image.rows) //check that coordinate pt2.y doesn't get out of the image
    pt2.y = image.rows;
然后对计算的每个坐标重复检查。减法时,只需检查坐标是否大于等于0,如果不是,则将其设置为0


希望对您有所帮助。

如果((0对不起,我不太明白你的答案。你能详细说明一下吗?您好,我怀疑同样的问题,并对其进行了检查。坐标超出范围不是问题。我打印了矩形_内部和矩形_外部的坐标,它们都在范围内。问题似乎与我定义rec的事实有关一个块内的tangle_inner和矩形_outer。如果我在If/else块外做了完全相同的定义,代码似乎工作正常!因此如果你检查了else中的坐标,我猜问题可能在第一个
If(faces.size()==0){
。您是否检查了
矩形\u内\u旧
矩形\u外\u旧
值?在if块中分配值和在if块中分配值应该没有任何区别,所以问题一定在别处。我也检查了这些。这就是为什么我感到困惑的原因。我从以前的程序中知道,在我正在使用的视频,faces.size()!=0。此外,当我在else块外取消对声明的注释时,程序在前几帧运行良好,在这几帧中检测到人脸。之后它会给出相同的错误。很抱歉,我错了。值的范围本身有问题。但我还无法修复它。由于某些原因,人脸检测器返回一个rectan右上角点本身在帧外的gle。接下来我将应用您建议的检查。要调整rect,您可以执行以下操作:
cv::rect imageRect(0,0,imWidth,imHeight);adjustedRect=yourRect&imageRect;
pt1.x = r.x;
pt1.y = r.y;
pt2.x = pt1.x + r.width;
if(pt2.x >= image.cols) //check that coordinate pt2.x doesn't get out of the image
    pt2.x = image.cols;

pt2.y = pt2.y + r.height;
if(pt2.y >= image.rows) //check that coordinate pt2.y doesn't get out of the image
    pt2.y = image.rows;