Jacob.Wang
Jacob.Wang

Reputation: 1

EmguCV Mat change to LineSegment2D[]

I'm using emguCV houghines Method and get a Mat Object, how can I get LineSegment2D[] by this Mat. Sample of code:

Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(fileName);
UMat uimage = new UMat();
CvInvoke.CvtColor(img1, uimage, ColorConversion.Bgr2Gray);
UMat mat = new UMat();
CvInvoke.HoughLines(uimage, mat, 1, Math.PI / 180, 20);

here I can see the size is not 0, how can I get these lines, or other function to show them

Upvotes: 0

Views: 312

Answers (1)

Mnyikka
Mnyikka

Reputation: 1261

Here is the code to convert from Mat to LineSegment2D

private static LineSegment2D[] convertToLines2D(Mat lines)
    {
        Size s = lines.Size;
        LineSegment2D[] segments = new LineSegment2D[s.Height];
        GCHandle handle = GCHandle.Alloc(segments, GCHandleType.Pinned);
        using (Mat tmp = new Mat(s.Height, s.Width, Emgu.CV.CvEnum.DepthType.Cv32S, 4, handle.AddrOfPinnedObject(), sizeof(int) * 4))
        {
            lines.CopyTo(tmp);
        }
        handle.Free();
        return segments;
    }

     

Upvotes: 0

Related Questions