无法检测到圈子

时间:2018-10-18 22:46:15

标签: python opencv3.0 object-detection

我尝试使用功能cv2.HoughCircles,但是它无法检测到纸上的手绘圆圈。有人可以帮我吗?

import numpy as np
import imutils
import cv2

image = cv2.imread("images/136_5cm.png")[enter[enter image description here][1] image description here][1]
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#gray = cv2.GaussianBlur(gray, (5, 5), 0)
# detect circles in the image
print('hello')
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.4 ,100,)
# ensure at least some circles were found
if circles is not None:
    # convert the (x, y) coordinates and radius of the circles to integers
    circles = np.round(circles[0, :]).astype("int")
    print(circles)

    # loop over the (x, y) coordinates and radius of the circles
    for (x, y, r) in circles:
        # draw the circle in the output image, then draw a rectangle
        # corresponding to the center of the circle
        cv2.circle(output, (x, y), r, (0, 255, 0), thickness=4, lineType=8, shift=0)
        cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)

    # show the output image
    cv2.imshow("output", np.hstack([image, output]))
    cv2.waitKey(0) 

0 个答案:

没有答案