OpenCV wont' capture from MacBook Pro iSight

后端 未结 2 1694
执笔经年
执笔经年 2020-12-18 05:08

Since a couple of days I can\'t open my iSight camera from inside an opencv application any more. cap = cv2.VideoCapture(0) returns, and cap.isOpened()

2条回答
  •  失恋的感觉
    2020-12-18 05:18

    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.

提交回复
热议问题