我用各種OpenCV過濾器創建了黑色和白色面具。有四個圈是清晰可見Python OpenCV從黑色和白色面具檢測圈
我試圖勾勒使用HoughCircles這些圈子,但它給許多誤報和一般壞的結果:
circles = cv2.HoughCircles(combined, cv.CV_HOUGH_GRADIENT, 1, 300, np.array([]), 10, 30, 60, 300)
哪有我正確地檢測到黑白圖像中的圓形?
這裏是一個可以與黑白圖像被用於運行的代碼:
import numpy as np
import cv2
import cv
image = cv2.imread("image.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray, cv.CV_HOUGH_GRADIENT, 1, 300, np.array([]), 10, 30, 60, 300)
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(image, (i[0], i[1]), i[2], (0, 255, 0), 1)
cv2.circle(image, (i[0], i[1]), 2, (0, 0, 255), 3)
cv2.imshow("thing", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
如果您提供一段可運行的代碼來加載圖像並繪製圓圈,有人可能會傾向於查看它。 – Bull 2014-09-06 01:47:09
謝謝@B ...添加了可運行代碼 – fruitcup 2014-09-06 01:52:50