如何使用新的emgu版本实现打开和关闭图像处理?
我找到了这个: www.stackoverflow.com/questions/11567350/opening-and-closing-using-opencv/但我无法使用" StructuringElementEx"再和新的" image.MorphologyEx()"方法需要更多的价值。
我也尝试过.dilate和.erode,但这只能用3x3的矩形形状才能完成。
"更新"例子会很棒!
答案 0 :(得分:2)
使用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);
}
答案 1 :(得分:0)
此功能不会在EMGU 3.1中使用Mat
我正在使用这些。
// 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());