Ask Your Question

Phalcon's profile - activity

2017-02-21 13:55:15 -0600 commented answer Errors in Contour detection

I think I've got it, it's a misunderstanding on my part. I was expecting a contour to trace around the edge of a even a single pixel, i.e. a single pixel would return 4 coordinates. Seemingly it returns the centre points. This results in the reduced area than I was expecting. Any suggestions on how I would get the functionality I need? The code I'm running is above (opencvsharp 3.2)

2017-02-21 13:07:26 -0600 received badge  Editor (source)
2017-02-21 10:58:21 -0600 asked a question Errors in Contour detection

Hi

I am doing some simple contour detection, thresholding the images then using findcontours(). To test it, I've created a simple image in paint, manually colouring in 4 pixels hence having a known area and other more complex examples. When I run this through, everything seems offset slightly, in the case of a 2x2 square, this comes out to have an area of 1. Clearly I'm missing something. Any suggestions? Example below(to scale). I feed in the image on the left, 3x3 pixels wide. Looking at the coordinates after findcontours(), the result is only 2x2 pixels wide. I can see this in the raw polygons as well as the bitmap output.

Example attached

image description

    private void GeneratePolygon()
    {
        Mat img = Cv2.ImRead(RawImagePath, ImreadModes.GrayScale);
        Cv2.Threshold(img, img, Threshold, 255, ThresholdTypes.Binary);
        CvPoint[][] Contours;
        HierarchyIndex[] hierarchyIndexes;
        Cv2.FindContours(img, out Contours, out hierarchyIndexes, RetrievalModes.List, ContourApproximationModes.ApproxNone);