【发布时间】:2018-07-20 21:44:25
【问题描述】:
我正在尝试检测 OMR 表上的气泡,看起来像这样:
我的边缘检测和轮廓显示代码引用自here。但是,在找到实际轮廓之前,我试图检测边缘但不知何故无法设置正确的参数值。 这是我得到的:
代码:
from imutils.perspective import four_point_transform
from imutils import contours
import numpy as np
import argparse
import imutils
import cv2
def auto_canny(image, sigma=0.50):
# compute the median of the single channel pixel intensities
v = np.median(image)
# apply automatic Canny edge detection using the computed median
lower = int(max(0, (1.0 - sigma) * v))
upper = int(min(255, (1.0 + sigma) * v))
edged = cv2.Canny(image, lower, upper)
# return the edged image
return edged
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to the input image")
args = vars(ap.parse_args())
image = cv2.imread(args["image"])
r = 500.0 / image.shape[1]
dim = (500, int(image.shape[0] * r))
# perform the actual resizing of the image and show it
image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
equalized_img = cv2.equalizeHist(gray)
cv2.imshow('Equalized', equalized_img)
# cv2.waitKey(0)
blurred = cv2.GaussianBlur(equalized_img, (7, 7), 0)
# edged =cv2.Canny(equalized_img, 30, 160)
edged = auto_canny(blurred)
cv2.imshow('edged', edged)
cv2.waitKey(0)
如何获得所有 90*4 的圆圈?
【问题讨论】:
-
你可以从检测到的圆圈中推断出圆圈之间的方向和距离,这样你就可以得到缺失圆圈的坐标。
-
你试过大津二值化吗?
-
嗨 Akhilesh,以下任何答案都有帮助吗?抱歉恢复晚了。