I want to fill regions by setting thickness to -1.Result is Unbelievable:the second contour is filled ,but the first is not filled.
var result= new Image<Bgr, byte>(source.Width, source.Height);
result.SetValue(new Bgr(255,255,255));
VectorOfVectorOfPoint contours =new VectorOfVectorOfPoint();
var temp = source.Canny(128, 255);
CvInvoke.FindContours(temp , contours,null, RetrType.External,ChainApproxMethod.ChainApproxSimple);
CvInvoke.DrawContours(result, contours, 1, new MCvScalar(0,255,0),-1);
CvInvoke.DrawContours(result, contours, 0, new MCvScalar(0,255, 0), -1);
result =result.GetSubRect(getMaxRectangle(contours))
I tried to use different LineType but failed, especially LineType.Filled cause a error :OpenCV: connectivity == 8 || connectivity == 4. I want to know why it happened.
I'll just write the code in python, if it will help you:
And here is the result:
So basically no need to do Canny edge detection, your image is good to go with some threshold (remember to use
cv2.THRESH_BINARY_INV)Okay so I guess maybe for you, this will be something like this:
The drawing would not change anything, it is correct. I guess with canny detection something went wrong, can't say what exactly, but maybe the contour was broken or something. To make sure, can you please show us how your canny edges looked like?