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
boundingrect不适用于opencv c++;_Opencv_Visual C++_Contour - Fatal编程技术网

boundingrect不适用于opencv c++;

boundingrect不适用于opencv c++;,opencv,visual-c++,contour,Opencv,Visual C++,Contour,{ #包括 #包括 #包括 使用名称空间std; 使用名称空间cv; int main() { int a=0; 垫框、diffimage、back、frame_gray; 视频捕获cap(“D:\\elance\\check\\Sent3.avi”); 矢量等值线; 背景:mog2-bg; 向量参数; 参数推回(CV\U IMWRITE\U PNG\U压缩); 参数推回(9); 对于(int i=0;i>框架; if(frame.empty()) 打破 背景(帧,背面); } 背景:getBa

{

#包括
#包括
#包括
使用名称空间std;
使用名称空间cv;
int main()
{
int a=0;
垫框、diffimage、back、frame_gray;
视频捕获cap(“D:\\elance\\check\\Sent3.avi”);
矢量等值线;
背景:mog2-bg;
向量参数;
参数推回(CV\U IMWRITE\U PNG\U压缩);
参数推回(9);
对于(int i=0;i<200;i++)
{
cap>>框架;
if(frame.empty())
打破
背景(帧,背面);
}
背景:getBackgroundImage(背面);
封盖设置(CV、封盖、属性、位置、框架,0);
CVT颜色(背面、背面、CV_bgr2灰色);
//对于(int f=0;f<20;f++)
而(1)
{
a=a+1;

是否可以“如果(smoothCont.rows>0&&smoothCont.rows<10000)”将其过滤掉?

对不起,先生,现在我已经编辑了代码。感谢Mat smoothCont我正在尝试查找轮廓向量的行数和列数,一些轮廓是负列,您能解释一下吗?更好地使用轮廓[i]。size()无论如何。但这仍然不能解决我的问题。这段代码应该适用于多个边界框。我已经尝试过这种方法,但它也不起作用,因为函数返回的边界矩形给出了矩形坐标的负值。我记得boundingRect采用向量,而不是Mat。转换的具体原因是什么它对Mat?我在程序中直接使用了轮廓,但它给出的是负值
 #include<opencv2\opencv.hpp>
 #include<iostream>
 #include<conio.h>

 using namespace std;
 using namespace cv;

 int main()
{
int a = 0;

Mat frame, diffimage,back,frame_gray;
VideoCapture cap("D:\\elance\\check\\Sent3.avi");
vector<vector<Point>> contours;
BackgroundSubtractorMOG2 bg;
vector<int> params;
params.push_back(CV_IMWRITE_PNG_COMPRESSION);
params.push_back(9);

for (int i = 0; i < 200;i++)
{
    cap >> frame;
    if (frame.empty())
        break;
    bg(frame,back);
}

bg.getBackgroundImage(back);
cap.set(CV_CAP_PROP_POS_FRAMES,0);
cvtColor(back, back, CV_BGR2GRAY);
//for (int f = 0; f < 20;f++)
while (1)
{
    a = a + 1;
    cout << "Frame no : " << a<<endl;
    cap >> frame;
    if (frame.empty())
        break;
    cvtColor(frame, frame_gray, CV_BGR2GRAY);
    absdiff(frame_gray, back, diffimage);
    threshold(diffimage, diffimage, 10, 255, CV_THRESH_BINARY);

    for (int i = 0; i < 2; i++)
    {
        cv::erode(diffimage, diffimage, cv::Mat());
        cv::dilate(diffimage, diffimage, cv::Mat());
    }
    findContours(diffimage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
    cout << "Contour Size : " << contours.size()<<endl;
    vector<Rect> boundRect(contours.size());
    for (int i = 0; i < contours.size(); i++)
    {
        drawContours(frame, contours, i, cv::Scalar(0, 255, 255), 1);
        Mat smoothCont;
        smoothCont = cv::Mat(contours[i]);
        cout << smoothCont.rows << "\t" << smoothCont.cols <<"\t"<<smoothCont.depth()<< endl << endl;
        if (smoothCont.rows > 0 && smoothCont.rows < 10000)
            boundRect[i] = boundingRect(Mat(contours[i]));
    }
    for (int i = 0; i < contours.size(); i++)
        rectangle(frame, boundRect[i], Scalar(0, 255, 255), 1, 8, 0);
    imshow("Diff", diffimage);
    imshow("frame", frame);
    imwrite("D:\\test.jpg", frame, params);
    waitKey(30);
    break;
}