0
如何检测光学圆(空心以及填充)?有没有什么办法可以一般化的方式解决segementation问题?圆形物体检测
我是不是能够检测到光圈时,我运用以下方法:
import numpy as np
import cv2
image= cv2.imread("cropped.jpg")
lower_bound = np.array([0,0,0])
upper_bound = np.array([255,255,195])
blur_factor = (3,3)
image= cv2.blur(image, blur_factor)
mask = cv2.inRange(image, lower_bound, upper_bound)
kernel = np.ones((3,3),np.uint8)
closing = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
contours = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)[0]
contours.sort(key=lambda x:cv2.boundingRect(x)[0])
array = []
ii = 1
for c in contours:
(x,y),r = cv2.minEnclosingCircle(c)
center = (int(x),int(y))
r = int(r)
if r >= 12 and r<=15:
cv2.circle(image,center,r,(0,255,0),2)
array.append(center)
for i in array:
text_color = (0, 0, 255)
cv2.putText(image, str(ii), i, cv2.FONT_HERSHEY_SIMPLEX, 0.5, text_color, 2)
ii = ii + 1
cv2.imshow("masked",mask)
cv2.imshow("circled",image)
cv2.waitKey(0)
你报价是创建与掩盖原来的限图像的图像线考虑的最小圈闭。意思是一个黑色的图像,除了最小的封闭圆内的区域,这将是你的阈值图像。试试代码和imshow()的东西:) 对于你的号码识别问题,这是一个完全不同的问题:检查OCR https://en.wikipedia.org/wiki/Optical_character_recognition,我认为有OpenCV中的实现。 – Soltius
这是你的代码,我只是改变了数字。这个想法是寻找所有最小的封闭圆,并且只选择那些具有特定半径(在12和18之间)的圆,因为你知道那是你正在寻找的半径。 – Soltius
你可以看看霍夫圆变换 – Soltius