繁体   English   中英

opencv findContours()使程序崩溃

[英]opencv findContours() crashes the program

我是图像处理的新手,我正在进行实时跟踪

但是我一直坚持使用findCountours函数。

cvtColor(*pImg, *pImg, CV_RGBA2GRAY); //convert to gray image
Mask = pImg->clone();  //clone the source
Mask.convertTo(Mask,CV_8UC1); //convert to 8UC1
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( Mask, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)  );
contours.clear();  
hierarchy.clear();

当我运行该程序时,它会崩溃,如果我注释了findCountours函数,那就很好了。

我已经检查了一些文件,但是不知道发生了什么。

Mask = pImg->clone();  //clone the source
Mask.convertTo(Mask,CV_8UC1); //convert to 8UC1

更换

pImg.convertTo(Mask, CV_8U, arg);

arg对于不同类型的输入图像可能会有所不同。 浮点数/双精度数为255。

找到轮廓之前,尝试使用“ Canny边缘检测器或阈值运算符 ”。 根据需要执行的任务选择操作员。

   `cvtColor(*pImg, *pImg, CV_RGBA2GRAY); //convert to gray image
    Mask = pImg->clone();  //clone the source
    Mask.convertTo(Mask,CV_8UC1); //convert to 8UC1
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;
    /*based on your need use any of these operator */
    threshold( input, output, threshold_value, max_BINARY_value,threshold_type );  
   Canny( input, canny_output, thresh, thresh*2, 3 );
    findContours( output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)  );
    contours.clear();  
    hierarchy.clear();`

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM