Esempio n. 1
0
def test():
    cap = cv2.VideoCapture(1)
    print("good_name:....")
    good_name = input()
    path_origin = "three_light/origin/{}/".format(good_name)
    path_after = "three_light/after/{}/".format(good_name)
    if not os.path.exists(path_origin):
        os.makedirs(path_origin)
    if not os.path.exists(path_after):
        os.makedirs(path_after)

    counts = 0
    while True:
        ret, img = cap.read()
        cv2.circle(img, (333, 240), 235, (0, 0, 255), 2)
        cv2.imshow('ori', img)
        img_name = time.time()
        #if counts % gap == 0:
        #     cv2.imwrite(path_origin+'{}.jpg'.format(img_name), img)

        _, img_process = black_process_three(img)
        #if counts % gap == 0:
        #    cv2.imwrite(path_after+'{}.jpg'.format(img_name), img_process)

        cv2.imshow('image', img_process)
        counts += 1
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()
Esempio n. 2
0
def mix_images(base, img2):
    # 将img2处理后的pre2上的物体抠出来放在img1处理后的base处理后的图上
    mask, pre2 = black_process_three(img2)
    # cv2.imshow('mask', mask)

    mask_inv = cv2.bitwise_not(mask)

    # mask 为掩码,与原图作用时,mask=0的地方原图变为黑色,其他地方不变
    img1_bg = cv2.bitwise_and(base, base, mask=mask_inv)
    # cv2.imshow('img1_bg', img1_bg)
    img2_bg = cv2.bitwise_and(pre2, pre2, mask=mask)

    dst = cv2.add(img1_bg, img2_bg)
    # base[55:335, 145:545] = dst

    return dst
Esempio n. 3
0
def mix_two_images(base, img2):
    # roi = base[28:328, 145:545]
    roi = base[:]
    # 将img2处理后的pre2上的物体抠出来放在img1处理后的base处理后的图上
    # img2 = cv2.resize(img2, (400, 300))
    mask, pre2 = black_process_three(img2)
    # cv2.imshow('mask', mask)

    mask_inv = cv2.bitwise_not(mask)

    # mask 为掩码,与原图作用时,mask=0的地方原图变为黑色,其他地方不变
    img1_bg = cv2.bitwise_and(roi, roi, mask=mask_inv)
    # cv2.imshow('img1_bg', img1_bg)
    img2_bg = cv2.bitwise_and(pre2, pre2, mask=mask)

    dst = cv2.add(img1_bg, img2_bg)
    #base[28:328, 145:545] = dst
    base = dst

    return base
Esempio n. 4
0
if not os.path.exists(dir2):
    os.makedirs(dir2)

cap = cv2.VideoCapture(1)

# 视频帧计数间隔频率
timeF = 6

while True:
    count = 1
    while cap.isOpened() and count <= 601:
        ret, img = cap.read()
        if count % timeF == 0:
            now = time.time()
            cv2.imwrite(dir1 + '/' + str(now) + '.jpg', img)
            # image = cv2.imread(dir1 + '/' + str(now) + '.jpg')
            # im = cv2.imread(dir1 + '/' + str(now) + '.jpg')
            # open_image_1st(img)
            _, img = black_process_three(img)
            cv2.imwrite(dir2 + '/' + str(now) + '.jpg', img)
        count += 1
        # cv2.imshow('image', img)
        cv2.waitKey(1)
    else:
        break

cap.release()
cv2.destroyAllWindows()

print("ending!!!!")