예제 #1
0
def show_landmarks(path):
    import cv
    from utils.DFLJPG import DFLJPG
    jpg = DFLJPG.load(path)
    img = cv.cv_load(path)
    lm = jpg.get_landmarks()
    for (x, y) in lm:
        cv.cv_point(img, (x, y), (255, 0, 0))
    cv.cv_show(img)
예제 #2
0
    def repaint():
        nonlocal trans_pitch_to_x
        nonlocal trans_yaw_to_y
        nonlocal trans_x_to_pitch
        nonlocal trans_y_to_yaw
        nonlocal trans_r
        nonlocal src_cur_list
        nonlocal cur_list
        nonlocal cur_pitch_yaw
        nonlocal img
        nonlocal src_path
        mid = cur_mid
        w = cur_w
        sx = mid[0] - w / 2
        sy = mid[1] - w / 2
        ex = mid[0] + w / 2
        ey = mid[1] + w / 2
        idxs = (img_list[:, 1] >= sx) & \
               (img_list[:, 2] >= sy) & \
               (img_list[:, 1] <= ex) & \
               (img_list[:, 2] <= ey)
        cur_list = img_list[idxs]
        cur_pitch_yaw = cur_list[:, 1:3]
        if len(src_img_list) == 0:
            src_cur_list = []
        elif src_path:
            idxs = (src_img_list[:, 1] >= sx) & \
                   (src_img_list[:, 2] >= sy) & \
                   (src_img_list[:, 1] <= ex) & \
                   (src_img_list[:, 2] <= ey)
            src_cur_list = src_img_list[idxs]

        trans_pitch_to_x = cv.trans_fn(sx, ex, 0, width)
        trans_yaw_to_y = cv.trans_fn(sy, ey, 0, width)
        trans_x_to_pitch = cv.trans_fn(0, width, sx, ex)
        trans_y_to_yaw = cv.trans_fn(0, width, sy, ey)
        trans_r = cv.trans_fn(0, width, 0, w)
        img = cv.cv_new((width, width))

        min_fno = int(cur_list[0][0])
        max_fno = int(cur_list[-1][0])
        trans_color = cv.trans_fn(min_fno, max_fno, 0, 1)
        for _, p, y in src_cur_list:
            cv.cv_point(img, (trans_pitch_to_x(p), trans_yaw_to_y(y)),
                        (192, 192, 192), src_r * 2 / cur_w)
        for f, p, y in cur_list:
            fno = int(f)
            h = trans_color(fno)
            s = 1
            v = 1
            r, g, b = colorsys.hsv_to_rgb(h, s, v)
            cv.cv_point(img, (trans_pitch_to_x(p), trans_yaw_to_y(y)),
                        (b * 255, g * 255, r * 255), 2)
        cv2.imshow("select", img)
예제 #3
0
def skip_by_pitch(src_path, dst_path):
    import os
    import shutil
    import cv
    size = 800
    r = 20
    src_img_list = get_pitch_yaw_roll(src_path)
    dst_img_list = get_pitch_yaw_roll(dst_path)
    trash_path = dst_path + "_trash"
    if not os.path.exists(trash_path):
        os.makedirs(trash_path)

    img = cv.cv_new((size + 1, size + 1))
    trans: Callable[[Any], int] = lambda v: int((v + 1) * size / 2)
    count = 0
    for [_, pitch, yaw, _] in src_img_list:
        x = trans(pitch)
        y = trans(yaw)
        cv.cv_point(img, (x, y), (128, 128, 128), r)
    # cv.cv_show(img)
    xys = []
    for [path, pitch, yaw, _] in dst_img_list:
        x = trans(pitch)
        y = trans(yaw)
        c = img[y, x]
        c_ = img[-y, x]
        if sum(c) == 255 * 3 and sum(c_) == 255 * 3:
            xys.append((x, y, (0, 0, 0xff)))
            if not os.path.exists(path) or not os.path.exists(trash_path):
                continue
            count += 1
            shutil.move(path, trash_path)
        else:
            xys.append((x, y, (0xcc, 0x66, 0x33)))
    for (x, y, color) in xys:
        cv.cv_point(img, (x, y), color, 2)
    # cv.cv_show(img)
    io.log_info("Out Of Pitch, %d / %d" % (count, len(dst_img_list)))
    save_path = os.path.join(dst_path, "_skip_by_pitch.bmp")
    cv.cv_save(img, save_path)