Webcam work in opencv python



  • Here's the code:

    import cv2
    

    cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_FPS, 24) # Частота кадров
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 600) # Ширина кадров в видеопотоке.
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) # Высота кадров в видеопотоке.

    while True:
    ret, img = cap.read()
    cv2.imshow("camera", img)
    if cv2.waitKey(10) == 27: # Клавиша Esc
    break

    cap.release()
    cv2.destroyAllWindows()

    I've got the simplest web, connected through usb, other applications show the image, everything. When I start the code, the program doesn't turn anything out in the terminal, there's no window called "camera." Can you tell me why the image of the web isn't out?



  • Try changing the numbers in the line. cap = cv2.VideoCapture(0)♪ Maybe your web weighs on. cap = cv2.VideoCapture(1) And so on.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2