2017-04-06 74 views
0

我再次运行查找等高线功能,但总是返回空白。OpenCV FindContours return empty

我Xamarin的Android代码:

var frame = new Mat(); 

    bitmapOptions = new BitmapFactory.Options(); 
    bitmapOptions.InScaled = false; 

    var bitmapTemplateOrig = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.abi_canny, bitmapOptions); 
    OpenCV.Android.Utils.BitmapToMat(bitmapTemplateOrig, frame); 
    bitmapTemplateOrig.Dispose(); 

    Imgproc.CvtColor(frame, frame, Imgproc.ColorRgba2gray); 

    var contours = new List<MatOfPoint>(); 
    Imgproc.FindContours(frame, contours, new Mat(), Imgproc.RetrList, Imgproc.ChainApproxSimple, new Core.Point(0, 0)); 
    var size = contours.Count(); // returns 0 here? 

我的测试图像已经在这里应用精明的检测。 test image

任何想法?

+0

我能获得518组的轮廓为这个图象的一半大小。你如何运行它? –

+0

不知道。我为Android使用了Xamarin。我更新了我的代码。 –

+0

@JeruLuke:你可以发布你的代码吗? –

回答

1

下面是代码在python:

_, contours, hierarchy = cv2.findContours(th, cv2.RETR_TREE, 1) 

print 'Number of contours:', len(contours) 

cv2.drawContours(img1, contours, -1, (0,255,0), 2) 
cv2.imwrite("img1cnt.jpg", img1) 

结果:

Number of contours: 518 

enter image description here