发布网友 发布时间:2022-04-21 22:21
共1个回答
热心网友 时间:2023-07-10 01:06
# coding=utf-8
# Camera
# Author: Res_TP
# 2018.11.29
# 使用以下命令安装 Pillow 和 openCV
# python -m pip install numpy
# python -m pip install matplotlib
# python -m pip install Pillow
# python -m pip install opencv-python
import cv2
from PIL import Image, ImageDraw
if __name__ == "__main__":
camera = cv2.VideoCapture(0)
cv2.namedWindow("Camera")
if not camera.isOpened():
print("Camera coudn't be found.")
exit(0)
while True:
status, img = camera.read()
if status == False:
print("Camera closed.")
break
key = cv2.waitKey(1)
if cv2.getWindowImageRect("Camera")[0] == -1:
break
cv2.imshow("Camera", img)
camera.release()
cv2.destroyAllWindows()