python - 是否有用于像素邻居探测的 Python (np/cv2/etc.) 函数?
问题描述
我有一些二进制图像,想要从中提取有关线条、它们的坐标和宽度的数据,以便进一步分类。
我已经尝试过 cv2.Canny,但它的质量很差,无法满足我的需求,因此我需要为每个像素提供更多手动、逐步的解决方案。
import cv2
import numpy as np
path = '../img/1.jpg'
img = cv2.imread(path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (3, 3), 0)
dilate = cv2.dilate(blur, np.ones((3, 3), np.uint8), iterations=3)
threshold = cv2.threshold(dilate, 128, 255, cv2.THRESH_BINARY)
_, threshold = threshold
canny = cv2.Canny(threshold, 128, 255)
contours, hierarchy = cv2.findContours(
canny, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
dc = cv2.drawContours(img, contours, -1, (0, 255, 0), 1)
cv2.imshow("canny", canny)
cv2.imshow("dc", dc)
while True:
key = cv2.waitKey()
q = 113
esc = 27
if key == q or key == esc:
break
我想找出更精确的方法来找到轮廓坐标并对其进行分类。
线路探测器
主意
精明是坏的
资源
解决方案
推荐阅读
- geth - geth 进程已停止,因为 debug_traceBlockByNumber
- r - R Shiny - 在后台运行应用程序并使用代码发出 UI 控件
- coldfusion - Lucee-自定义标签的无效组件定义
- javascript - 如何在新选项卡中打开 JS 文件并在 2 秒后关闭
- node.js - "errorMessage": "index.handler 未定义或未导出",
- python - xpath `//a[@href]` 与标签 `a`
- javascript - 阻止所有其他功能的未捕获的 TypeError
- javascript - 使用带有 JS 的 Riot 游戏 API 并且无法加载响应数据
- ruby-on-rails - 机架攻击节流
- android - 从锁定屏幕启动 Activity 时,Activity 的 onStart() 和 onResume() 方法调用了两次