在EmguCV C#中检测分段图像的长度

时间:2017-09-12 15:53:28

标签: c# emgucv

要求用于衡量程序中Canny Edged图像的距离。具体来说,我正在处理的图像是人脚。我已经通过Matlab完成了这个程序。

要做到这一点,我在VS2013上使用Matlab代码作为我的EmguCV c#代码算法。

这里是已经转换为C#的Matlab代码

 A = imread('feet1.jpg');
%// Some pre-processing. Treshold image and dilate it.
level = 0.9;
B = im2bw(A,level);
%// Detect edges
F = edge(B,'Canny');
figure; 
imshow(F);
hold on;   
 %Draw boundaries on Canny Edged image
    for k = 1:length(B),
     boundary = B{k};
     plot(boundary(:,2),boundary(:,1),'b','LineWidth',2);
    end

C#

private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog()==DialogResult.OK)
            {
                _imgInput = new Image<Bgr, byte>(ofd.FileName);
                imageBox1.Image = _imgInput;
            }
        }
public void ApplyCanny(double thresh=50.0, double threshLink = 20.0)
    {
        if (_imgInput == null)
        {
            return;
        }
        Image<Gray, byte> _imgCanny = new Image<Gray, byte>(_imgInput.Width, _imgInput.Height, new Gray(0));
        _imgCanny = _imgInput.Canny(thresh, threshLink);
        imageBox1.Image = _imgCanny;
    }

#region extract contours
        using (MemStorage storage = new MemStorage())
        {

            for (Contour<Point> contours = _imgCanny.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE, storage); contours != null; contours = contours.HNext)
            {

                Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.015, storage);
                if (currentContour.BoundingRectangle.Width > 20)
                {
                    CvInvoke.cvDrawContours(color, contours, new MCvScalar(255), new MCvScalar(255), -1, 2, Emgu.CV.CvEnum.LINE_TYPE.EIGHT_CONNECTED, new Point(0, 0));
                    color.Draw(currentContour.BoundingRectangle, new Bgr(0, 255, 0), 1);
                }
            }

        }

我转换的剩余代码:

%Measure boundaries
measurements = regionprops(F, 'Centroid', 'BoundingBox');
centroid = measurements(1).Centroid;
bb = measurements(1).BoundingBox;
y1 = bb(2); % Top of bounding box.
y2 = bb(2)+bb(4);  % Bottom of bounding box.
centroidToToe = y2 - centroid(2);

编辑:9/28/2017 - 我现在可以成功找到脚。最后一步是测量边界矩形。我研究了一些,看起来我需要使用方法CvMoments。

0 个答案:

没有答案