问题
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:
- What is the reason for this problem to happen?
- How to avoid (or can we avoid) this problem from happening?
- 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