a03_augmentation.py 文件源码

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

项目:KAGGLE_CERVICAL_CANCER_2017 作者: ZFTurbo 项目源码 文件源码
def return_random_perspective(img, row):
    perc = 0.1
    cols = img.shape[1]
    rows = img.shape[0]
    start0_max, end0_max, start1_max, end1_max = get_bounding_boxes_positions(img, row)

    if start1_max <= 0:
        p1 = random.randint(0, int(img.shape[1] * perc))
    else:
        p1 = random.randint(0, start1_max)

    if start0_max <= 0:
        p2 = random.randint(0, int(img.shape[0] * perc))
    else:
        p2 = random.randint(0, start0_max)

    if end1_max >= img.shape[1]:
        p3 = img.shape[1] - random.randint(0, int(img.shape[1] * perc))
    else:
        p3 = random.randint(end1_max, img.shape[1])

    if start0_max <= 0:
        p4 = random.randint(0, int(img.shape[0] * perc))
    else:
        p4 = random.randint(0, start0_max)

    if start1_max <= 0:
        p5 = random.randint(0, int(img.shape[1] * perc))
    else:
        p5 = random.randint(0, start1_max)

    if end0_max >= img.shape[0]:
        p6 = img.shape[0] - random.randint(0, int(img.shape[0] * perc))
    else:
        p6 = random.randint(end0_max, img.shape[0])

    if end1_max >= img.shape[1]:
        p7 = img.shape[1] - random.randint(0, int(img.shape[1] * perc))
    else:
        p7 = random.randint(end1_max, img.shape[1])

    if end0_max >= img.shape[0]:
        p8 = img.shape[0] - random.randint(0, int(img.shape[0] * perc))
    else:
        p8 = random.randint(end0_max, img.shape[0])

    pts1 = np.float32([[p1, p2], [p3, p4], [p5, p6], [p7, p8]])
    pts2 = np.float32([[0, 0], [cols, 0], [0, rows], [cols, rows]])
    M = cv2.getPerspectiveTransform(pts1, pts2)
    # img = cv2.rectangle(img, (int(start1_max), int(start0_max)), (int(end1_max), int(end0_max)), (0, 0, 255), thickness=5)
    dst = cv2.warpPerspective(img, M, (cols, rows))
    # show_resized_image(dst)
    return dst
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号