2015-10-13 138 views

回答

1

在使用Emgu CV 3.0的MorphologyEx時也有同樣的問題
我在Github中發現了這個測試代碼。
希望得到這個幫助!

[Test] 
    public void TestMorphEx() 
    { 
    Mat kernel1 = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross, new Size(3, 3), new Point(1, 1)); 
    Matrix<byte> kernel2 = new Matrix<byte>(new Byte[3, 3] { { 0, 1, 0 }, { 1, 0, 1 }, { 0, 1, 0 } }); 
    //StructuringElementEx element2 = new StructuringElementEx(new int[3, 3] { { 0, 1, 0 }, { 1, 0, 1 }, { 0, 1, 0 } }, 1, 1); 
    Image<Bgr, Byte> tmp = new Image<Bgr, byte>(100, 100); 
    Image<Bgr, Byte> tmp2 = tmp.MorphologyEx(Emgu.CV.CvEnum.MorphOp.Gradient, kernel1, new Point(-1, -1), 1, CvEnum.BorderType.Default, new MCvScalar()); 
    Image<Bgr, Byte> tmp3 = tmp.MorphologyEx(Emgu.CV.CvEnum.MorphOp.Gradient, kernel2, new Point(-1, -1), 1, CvEnum.BorderType.Default, new MCvScalar()); 
    //Image<Bgr, Byte> tmp2 = tmp.MorphologyEx(element1, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_GRADIENT, 1); 
    //Image<Bgr, Byte> tmp3 = tmp.MorphologyEx(element2, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_BLACKHAT, 1); 
    } 
0

此功能不會拿墊在EMGU 3.1

我使用的這個人。

// Opening (erode->dilate) para quitar ruido. 
// get rid of small objects 
Mat kernelOp = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3,3), new Point(-1, -1)); 
CvInvoke.MorphologyEx(ThresholdMask, _Morphology, MorphOp.Open, kernelOp, new Point(-1, -1), 1, BorderType.Default, new MCvScalar()); 

// Closing (dilate -> erode) para juntar regiones blancas. 
Mat kernelCl = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(11, 11), new Point(-1, -1)); 
CvInvoke.MorphologyEx(_Morphology, _Morphology, MorphOp.Close, kernelCl, new Point(-1, -1), 1, BorderType.Default, new MCvScalar());