close

專案名稱: EmguMorphologyEx

image

加入參考C:\Emgu\emgucv-windows-universal-cuda 3.0.0.2158\bin

Emgu.Util.dll

Emgu.CV.dll

Emgu.CV.UI.dll

image

GetStructuringElement

Returns a structing element of the specified size and shape for morpholigical operations

Parameters
shape
Type: Emgu.CV.CvEnum.ElementShape
Element shape
ksize
Type: System.Drawing.Size
Size of the structuring element.
anchor
Type: System.Drawing.Point
Anchor position within the element. The value (-1, -1) means that the anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor position. In other cases the anchor just regulates how much the result of the morphological operation is shifted.
===============================================
private void ErodeProc()
{
if (!bImageLoaded) return;
Size kSize = new System.Drawing.Size(kx, ky);
Point anchor = new Point(-1, -1);
Mat element = CvInvoke.GetStructuringElement(ElementShape.Cross, kSize, anchor);
dstImg = new Mat();
CvInvoke.Erode(srcImg, dstImg, element, anchor, 1, BorderType.Default, new MCvScalar(0, 0, 0));
imageBox2.Image = dstImg;
}

原始影像

image

垂直方向侵蝕

image

水平方向侵蝕

image

水平+垂直方向侵蝕

image

原始影像

image 

水平擴增(Dilate)

image

垂直擴增

image

水平+垂直方向擴增

image

blurred image

private void BlurProc()
{
if (!bImageLoaded) return;
Size kSize = new System.Drawing.Size(kx, ky);
Point anchor = new Point(-1, -1);
Mat element = CvInvoke.GetStructuringElement(ElementShape.Cross, kSize, anchor);
dstImg = new Mat();
CvInvoke.Blur(srcImg, dstImg, kSize, anchor, BorderType.Default);
imageBox2.Image = dstImg;
}

image

private void CannyProc()
{
if (!bImageLoaded) return;
dstImg = new Mat();
using(Mat gray = new Mat())
using(Mat edge = new Mat())
{
Size kSize = new System.Drawing.Size(kx, ky);
Point anchor = new Point(-1, -1);
Mat element = CvInvoke.GetStructuringElement(ElementShape.Cross, kSize, anchor);
srcImg.ConvertTo(gray, DepthType.Cv8U, 1);
CvInvoke.Blur(gray, edge, kSize, anchor, BorderType.Default);
CvInvoke.Canny(edge, dstImg, threshold1, threshold2, apertureSize);
imageBox2.Image = dstImg;
}
}

image

參考資料:

  1. 1. CvInvoke.GetStructuringElement Method
  2. 2. CvInvoke.Erode Method
  3. 3. CvInvoke.Blur Method
  4. 4. CvInvoke.Canny Method
arrow
arrow
    全站熱搜

    me1237guy 發表在 痞客邦 留言(0) 人氣()