OpenCV wont' capture from MacBook Pro iSight

这一生的挚爱 提交于 2019-11-29 07:59:27
qidaas

This is how I got the camera working for your code (on OSX 10.6):

import cv2

cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)

rval, frame = vc.read()

while True:

  if frame is not None:   
     cv2.imshow("preview", frame)
  rval, frame = vc.read()

  if cv2.waitKey(1) & 0xFF == ord('q'):
     break

I had a segmentation fault after I grab an image. It turned out that I used cv2.destroyAllWindows() before cap.release(). Below I show working code.

cap = cv2.VideoCapture(0)

while(True):
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

#do some ops

cap.release()
cv2.imshow("output", output)
cv2.waitKey(0)
cv2.destroyAllWindows()

This code works on El Captain.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!