Freeman449s / Computer-Vision-Course

课程“计算机视觉”的代码仓库,利用OpenCV完成了直线与圆弧检测、Harris角点检测、EigenFace等工程。
GNU Lesser General Public License v2.1
4 stars 4 forks source link

圆弧检测 #3

Closed yingma111 closed 2 years ago

yingma111 commented 2 years ago
def grossCenterDetection(img: np.ndarray, gray: np.ndarray, edges: np.ndarray, tanMat: np.ndarray) -> list:
    accumMat = np.zeros(gray.shape, int)  # 圆心与边缘的距离大于图像本身尺度时舍弃
    # 计算累加器矩阵
    for y in range(0, edges.shape[0]):
        for x in range(0, edges.shape[1]):
            if edges[y][x] == 0:
                continue
            tan = tanMat[y][x]
            if tan == 0:
                continue
            for a in range(0, accumMat.shape[1]):
                b = round(a * tan - x * tan + y)   
                if b < 0 or b >= accumMat.shape[0]:
                    continue
                accumMat[b][a] += 1  # 在边缘图像中不为0,且梯度方向不为0,且圆心与
    # 筛选圆心
    pairList = pickPairs_center(accumMat, (img.shape[0], img.shape[1]), SuppressionMode.EIGHT_CONN)
    # 标出圆心
    img_copy = np.array(img)
    for i in range(0, len(pairList)):
        cv2.circle(img_copy, pairList[i], 2, CENTER_COLOR, thickness=-1)  # thickness为负值时,填充圆形
    cv2.imwrite("Img_with_Gross_Centers.jpg", img_copy)
    return pairList

其中b = round(a tan - x tan + y) ,能否解释一下这行的意义?

Freeman449s commented 2 years ago

tan是点P处梯度的方位角的正切。若P这一点确实在圆弧上,不妨设圆心(a,b),那么x=a+rcos, y=b+rsin,消去r即得到y-b=tan*(x-a).