【mac】python使用cv2打开本机摄像头

1、代码

# -*- coding:utf8 -*-

import cv2 as cv


cap = cv.VideoCapture(0) 

while (True):
    hx, frame = cap.read() 
    
    if hx is False: 
        print('read video error')
        exit(0)
     
    cv.imshow('video', frame)
    if cv.waitKey(1) & 0xFF == ord('q'):
        break

cap.release() cv.destroyAllWindows()

 

参考链接:

https://blog.csdn.net/guijianchouxyz/article/details/120719515

posted @ 2022-08-24 11:55  代码诠释的世界  阅读(319)  评论(0编辑  收藏  举报