find_circles.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:eclipse2017 作者: google 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号