python-3.x - 如何在 Python 中使用 OpenCV 正确过滤此图像
问题描述
我有一个计算机视觉项目,我需要识别一些包含方向标志的图腾上的数字,示例图像在这里:
所以我尝试了很多方法比如服用拉普拉斯,
img = cv2.imread(imgpath)
img = cv2.resize(img,(600,600))
imaj = cv2.GaussianBlur(img,(11,11),0)
imaj = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
laplas = cv2.Laplacian(imaj,cv2.CV_16SC1,ksize=5,scale=5,delta=1)
应用此功能后,我可以很好地区分背景和数字,但由于输出变为 16SC1,我无法获取图像中的轮廓。我尝试对此进行阈值处理,但仍然无法弄清楚任何事情。
这就是我从范围(5000,8000)阈值并将其转换为uint8后得到的,
最后,我尝试在此处使用以下代码从中获取轮廓:
def drawcntMap(filteredimg):
"""
Draws bounding boxes on the contour map for each image
"""
contour = cv2.findContours(filteredimg, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1]
digitCnts = []
# draw bounding boxes for contour areas, then filter them approximately on
# digit size and append filtered ones to a list
for c in contour:
(x, y, w, h) = cv2.boundingRect(c)
if w >= 7 and h >= 10 and w <=50 and h <=70:
digitCnts.append(c)
#create another contour map with filtered contour areas
cnt2 = cv2.drawContours(img.copy(), digitCnts, -1, (0,0,255),2)
#draw bounding boxes again on the filtered contour map.
for c in digitCnts:
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(cnt2, (x, y), (x+w, y+h), (0,255,0), 2)
return cnt2,digitCnts
结果将是:
我怎样才能改进我的解决方案来完成这项任务并获得所有数字?除了拉普拉斯滤波器,我尝试通过降低对比度和提取白色区域来使图像变暗(它确实有点好,但仍然无法获得所有数字),我尝试了高斯模糊和精巧边缘,但在图腾和背景的某些地方是在相同的像素值轮廓合并。
解决方案
推荐阅读
- node.js - 使用 passport-saml 的 SSO 回调不起作用
- android - 无法解析符号“SpotsDialog”
- algorithm - 图形中的简单路径,具有最大数量的特殊节点的特殊节点
- vue.js - 我在使用 Vue-apollo 库查询 GraphQl 端点时出错
- u-boot - PCIEx4 的 Uboot SERDES 配置
- typescript - 打字稿联合类型坏了?(当使用对象类型 + 对象文字时)
- css - 标签对齐。一样高。Bootstrap 4 - 表单
- flutter - 对作为 Stream Provider 的列表进行排序,但不会更改实际 llist 的顺序
- postgresql-9.5 - 可以在两个“选择”语句之间进行选择
- mysql - 如何只有在改变之后才能获得价值