平滑手写数字中的极端点
我试图识别手写数字。说我有以下图像:
net/p4h8t.png“ rel =“ nofollow noreferrer”>
我首先应用cv2。 thresh_binary_inv
删除噪声。
现在我尝试使用cv2.erode()
np.ones(((5,5))作为内核,但是结果图仍然具有极端点。
我认为应用cv2.findContours()
可能有助于获得所需的形状,但我将最终得到两个轮廓,一个用于内部,另一个用于外部。任何想法都将不胜感激!
编辑: 多亏了@statemachine,我设法获得了数字的骨架。我应用了cv2.ximgproc.thinning()
,然后是cv2.gaussianblur()
和cv2.morph_close
。如果该图像的极端点可以稍微平滑一点,那么它将是完美的。我仍然对任何想法开放:)
I am trying to recognize hand written digits. Say that I have the following image:
My target is to smooth the extremal features of the contours, and keep only the shape of the white trace like below:
I first applied cv2.THRESH_BINARY_INV
to remove the noise.
Now I tried applying cv2.erode()
with np.ones((5,5))
as the kernel, but the resulting figure still had the extremal points.
I think applying cv2.findContours()
may help to get the desired shape, but I am going to end up with two contours, one for the inner and another for the outer part. Any ideas will be much appreciated!
Edit:
Thanks to @stateMachine, I managed to get a skeleton of the digit. I applied cv2.ximgproc.thinning()
, followed by cv2.GaussianBlur()
and cv2.MORPH_CLOSE
. If the extremal points of this image can be smoothened a bit then it would be perfect. I am still open to any ideas :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您正在寻找的是形状的骨架。骨架是OpenCV的扩展图像处理模块的一部分(
pip install opencv-contrib-python
)。您可以这样计算图像的骨架:这是结果:
骨架将图像的厚度归一化为
1 Pixel
。如果需要较厚的线,则可以应用一些扩张
。Maybe what you are looking for is the shape's skeleton. The skeleton is part of OpenCV's extended image processing module (
pip install opencv-contrib-python
). You can compute the skeleton of your image like this:This is the result:
The skeleton normalizes the thickness of the image to
1 pixel
. If you need a thicker line you can apply somedilations
.