我需要用圆圈处理图像以识别圆圈。 然后从内部圆到圆的外围需要4个像素点。
到目前为止,我已经在this blog的帮助下对此代码进行了编程:
import numpy as np
import cv2
import argparse
def imageProcessing():
ap=argparse.ArgumentParser()
ap.add_argument("-i","--image",required=True,help="path to image")
args=vars(ap.parse_args())
# load the image, clone it for output, and then convert it to grayscale
image = cv2.imread(args["image"])
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# detect circles in the image
circles = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT, 1.2, 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")
# 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), 4)
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)
if __name__=="__main__":
imageProcessing()
您能指出我犯的错误吗?为什么程序无法识别圆?
也指导我如何在内圈上获得4分。