讀取攝像頭

2022-06-07 11:30:11 字數 598 閱讀 1823

#

從攝像頭獲取影象資料

cap =cv2.videocapture(0)

while

(true):

#ret 讀取成功true或失敗false

#frame讀取到的影象的內容

#讀取一幀資料

ret,frame =cap.read()

#變為灰度圖

gray =cv2.cvtcolor(frame,cv2.color_bgr2gray)

cv2.imshow(

'frame

',gray)

#waitkey功能是不斷重新整理影象,單位ms,返回值是當前鍵盤按鍵值

#ord返回對應的ascii數值

if cv2.waitkey(1) & 0xff == ord('q'

):

break

cap.release()

#攝像頭釋放

cv2.destroyallwindows()

#視窗釋放

OPENCV讀取攝像頭

opencv highgui cvcreatecameracapture 或cvcapturefromcam windows 中都是由較為低效的 vfw機制實現的,不適合在最終產品中使用。在 windows 中使用directshow opencv 中文網的 yushiqi 提供了乙個基於 dire...

OpenCV攝像頭讀取

在mac下面使用預設的opencv讀取攝像頭程式會報錯 int main int,char videocapture cap 0 open the default camera if cap.isopened check if we succeeded return 1 mat edges name...

matlab讀取攝像頭

matlab採集攝像頭程式的 source.vid videoinput winvideo 1,yuy2 640x480 set source.vid,returnedcolorspace grayscale vidres get source.vid,videoresolution nbands ...