首页 > 解决方案 > 是否有用于像素邻居探测的 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

我想找出更精确的方法来找到轮廓坐标并对其进行分类。

线路探测器

线路探测器

主意

主意

精明是坏的

精明是坏的

资源

资源

标签: pythonalgorithmnumpyopencvcomputer-vision

解决方案


推荐阅读