def findCircles(fname, image, circles_directory):
f = os.path.join(circles_directory, os.path.basename(fname) + ".pkl")
if os.path.exists(f):
circles = pickle.load(open(f, "rb"))
return circles
image_cols, image_rows, _ = image.shape
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.bilateralFilter(gray, 9, 75, 75)
gray = cv2.addWeighted(gray, 1.5, blurred, -0.5, 0)
gray = cv2.bilateralFilter(gray, 9, 75, 75)
# # detect circles in the image
dp = 1
c1 = 100
c2 = 15
print "start hough", fname
circles = cv2.HoughCircles(gray, cv2.cv.CV_HOUGH_GRADIENT, dp, image_cols / 8, param1=c1, param2=c2)
print "finish hough", fname
pickle.dump(circles, open(f, "wb"))
if circles is None or not len(circles):
return None
return circles
评论列表
文章目录