简体   繁体   中英

Cannot Video Capture With opencv on macOS

On python when I try to video capture with open cv2 I get that:

2021-11-18 11:07:36.572 Python[5863:20765] =>> Checked Property: [cfen] 1667655022
2021-11-18 11:07:36.572 Python[5863:20765] =>> Checked Property: [cfen] 1667655022
2021-11-18 11:07:36.572 Python[5863:20765] =>> Checked Property: [cfen] 1667655022
2021-11-18 11:07:36.572 Python[5863:20765] =>> Checked Property: [cfac] 1667653987
2021-11-18 11:07:36.621 Python[5863:20765] =>> Checked Property: [cfen] 1667655022
2021-11-18 11:07:36.622 Python[5863:20765] =>> Checked Property: [cfen] 1667655022
2021-11-18 11:07:36.722 Python[5863:20765] =>> Checked Property: [cfen] 1667655022
2021-11-18 11:07:36.722 Python[5863:20765] =>> Checked Property: [cfen] 1667655022

i also this windows opening:

window

this is my code:


    
    import cv2


    trained_face_data = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
 
  
    webcam = cv2.VideoCapture(0)
    
    
    ret, frame = webcam.read()
   
   
    grayscaled_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
    cv2.imshow('image face detector', grayscaled_img)
    
    cv2.waitKey(1)

Solved just have to change the parameters cv2.VideoCapture(0) to cv2.VideoCapture(2)

hope that can helps other Mac users

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM