Blinking contour line

只谈情不闲聊 提交于 2019-12-13 06:41:43

问题


My program's objective is to identify the largest contour from a video camera and draw it with red line.

I discovered that when the largest contour (aka largest_contours in my program) is detected, the contour's contour line will blink and sometime will interrupt the function to draw a red line around it (because the contour's line is not connected anymore so no more contour detected inside the image).

My questions are:

  1. What is the reason for this problem to happen?
  2. How to avoid (or can we avoid) this problem from happening?
  3. Any suggestions to improve my contour's detection program?

Thanks in advance.

PS: For the codes, pics and more info, click HERE. VIDEO HERE!!!


回答1:


findContours API of OpenCV modifies the image which it uses to find contours.You can try the following.

Mat displayContours = Mat::zeros(image.rows,image.cols,CV_8UC1);
for(int i = 1;i<(int)largest_contours[0].size();i++)
{
   line(displayContours,largest_contours[0][i-1],largest_contours[0][i],255,2,8,0);
   line(image,largest_contours[0][i-1],largest_contours[0][i],cv::Scalar(0,0,255),2,8,0);
}

Now display the displayContours instead of foreground



来源:https://stackoverflow.com/questions/14750464/blinking-contour-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!