且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

目标检测机器人的OpenCV

更新时间:2021-12-25 06:35:26

我不知道你是否尝试过这一点,但通常情况下,你可以先处理图像达到更好的效果。

I don't know if you tried this, but usually, you can achieve better results by processing the image first.

1)适用GuassianBlur以消除噪音

2)应用AdaptiveThreshold - >将图像转换成黑白

2) Apply AdaptiveThreshold -> to convert the image to black and white

3)应用扩张操作,填补缝隙

3) Apply Dilate operation, to fill the cracks

使用的AdaptiveThreshold和扩张操作不同的设置,你也许可以得到封闭轮廓......

By using different settings for the AdaptiveThreshold and the Dilate operation, you might be able to get closed contours...

我用一个例子是这样的:

An example I used is like this:

// 1) Apply gaussian blur to remove noise
Imgproc.GaussianBlur(mGraySubmat, mIntermediateMat, new Size(11,11), 0);

// 2) AdaptiveThreshold -> classify as either black or white
Imgproc.adaptiveThreshold(mIntermediateMat, mIntermediateMat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 5, 2);

// 3) Invert the image -> so most of the image is black
Core.bitwise_not(mIntermediateMat, mIntermediateMat);

// 4) Dilate -> fill the image using the MORPH_DILATE
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE, new Size(3,3), new Point(1,1));
Imgproc.dilate(mIntermediateMat, mIntermediateMat, kernel);