utils.py 文件源码

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

项目:answer-sheet-scan 作者: inuyasha2012 项目源码 文件源码
def detect_cnt_again(poly, base_img):
    """
    ???????????????????
    :param poly: ndarray
    :param base_img: ndarray
    :return: ndarray
    """
    # ?????????????????flag
    flag = False

    # ?????????????????????????
    top_left, bottom_left, top_right, bottom_right = get_corner_node_list(poly)
    roi_img = get_roi_img(base_img, bottom_left, bottom_right, top_left, top_right)
    img = get_init_process_img(roi_img)

    # ?????????
    cnt = get_max_area_cnt(img)

    # ?????????????????????
    if cv2.contourArea(cnt) > roi_img.shape[0] * roi_img.shape[1] * SHEET_AREA_MIN_RATIO:
        flag = True
        poly = cv2.approxPolyDP(cnt, cv2.arcLength((cnt,), True) * 0.1, True)
        top_left, bottom_left, top_right, bottom_right = get_corner_node_list(poly)
        if not poly.shape[0] == 4:
            raise PolyNodeCountError

    # ?????????????????
    base_poly_nodes = np.float32([top_left[0], bottom_left[0], top_right[0], bottom_right[0]])
    base_nodes = np.float32([[0, 0],
                            [base_img.shape[1], 0],
                            [0, base_img.shape[0]],
                            [base_img.shape[1], base_img.shape[0]]])
    transmtx = cv2.getPerspectiveTransform(base_poly_nodes, base_nodes)

    if flag:
        img_warp = cv2.warpPerspective(roi_img, transmtx, (base_img.shape[1], base_img.shape[0]))
    else:
        img_warp = cv2.warpPerspective(base_img, transmtx, (base_img.shape[1], base_img.shape[0]))
    return img_warp
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号