import cv2
import numpy as np


# 镜像输出视频
def video_mirror_output(video):
    new_img = np.zeros_like(video)
    h, w = video.shape[0], video.shape[1]
    for row in range(h):
        for i in range(w):
            new_img[row, i] = video[row, w - i - 1]
    return new_img


# 调用usb摄像头
camera_id = 0
cap = cv2.VideoCapture(camera_id)

# 显示
while True:
    ret, frame = cap.read()
    new_img = video_mirror_output(frame)

    cv2.imshow("window", new_img)
    # 如果输入 esc 退出程序
    boardkey = cv2.waitKey(1) & 0xFF
    if boardkey == 27:
        break
# 关闭
cap.release()
cv2.destroyAllWindows()