• DepthAI
  • Oak camera not detected using cv2 VideoCapture

Hi, I have managed to get Oak camera recognized as a webcam but I cannot use it inside another script when I try to access it by cv2. Initially what worked for me was following the Using UVC for webcam. Please help thank you!

    Hi SadiaC
    Looks to me like you aren't accessing the right camera address? Can you confirm the "webcam" is actually there?

    Thanks,
    Jaka

      6 days later
      6 days later

      jakaskerl Hi thank you for your reply. The webcam is running separately when I follow the instructions as given. However, it's not recognized when I try to access it using opencv in another code.

      jakaskerl I am trying to use the OAK cameras as only a webcam device with other codes. I don't want to use the models inside the cameras for now and just make it usable as an input device. It would be great if you could give some insights on that!

        Hi SadiaC
        Could you paste your code?
        I can confirm that it works for me with this code:

        import cv2
        
        # Initialize the VideoCapture object to use the default camera (camera index 1 since 0 is my webcam)
        cap = cv2.VideoCapture(1)
        
        # Check if the camera opened successfully
        if not cap.isOpened():
            print("Error: Could not open camera.")
            exit()
        
        # Loop to continuously get frames from the camera
        while True:
            # Capture frame-by-frame
            ret, frame = cap.read()
        
            # Check if the frame was captured successfully
            if not ret:
                print("Error: Could not read frame.")
                break
        
            # Display the resulting frame
            cv2.imshow('Video Feed', frame)
        
            # Break the loop if 'q' is pressed
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        
        # Release the VideoCapture object and close display window
        cap.release()
        cv2.destroyAllWindows()

        Thanks,
        Jaka

          5 months later

          jakaskerl Hi this doesnt work! The camera doesnt get recognised as a usb camera at all. I have tried this on my windows laptop as well it only recognises the webcam but not the oak camera.

          Hi @SadiaC
          Make sure the UVC script is running in the background and there are no errors.
          You can try changing the index in VideoCapture(), maybe the UVC device is at a different index.

          Thanks,
          Jaka