C# Emgucv CvInvoke.DrawContours run very slow

Viewed 29

I am using DrawContours method in emgucv package, but it's working very slow, it takes about "12" second

I do the same thing in python, it only takes maybe "2" second to do this.

  • The target is "Find out all external contour areas that is bigger than 800 pixels and Fill it up on a new canvas" (The number of contours here is 74 )

than I will use this image as a mask

Please tell me how can I improve the time consuming problem

Here's the C# code :

VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();             
CvInvoke.FindContours(img, contours, null, RetrType.External, ChainApproxMethod.ChainApproxSimple);
UMat mask = new UMat(img.Size, DepthType.Cv8U, 1);

int minArea = 800;
for (int i = 0; i < contours.Size; i++)
{
    int area = CvInvoke.ContourArea(contours[i]);
    if (area > minArea)
    {
        CvInvoke.DrawContours(mask, contours, i, new MCvScalar(255), -1);
    }
    else
       continue;
}

also show my python code :

contours,_ = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

C = len(contours)

for i in range(0, C):
    if cv2.contourArea(contours[i]) > 800 :
        cv2.drawContours(mask, contours, i, (255,255,255), -1)
    else:
        continue

Thank you

0 Answers
Related