Mehmet Akif Aydemir
Mehmet Akif Aydemir

Reputation: 1

Failed to capture frame from picamera with V4L2 (Raspberry Pi 4B - Pi Camera v3)

I want to do live object detection with Raspberry pi 4B 8GB and Pi Camera v3 without using USB Accelerator. I want to do it with “Custom model” but first of all I wanted to test the example from tensorflow's github official page to test it (https://github.com/tensorflow/examples/tree/master/lite/examples/object_detection/raspberry_pi).

I am using Raspbian 64-bit Bookworm. I did all the installation steps properly, I did not get any error. However, when running the code, I get the following error:

(.venv) bitirme@raspberrypi:~/project/examples/lite/examples/object_detection/raspberry_pi $ python3 test.py
[ WARN:[email protected]] global cap_v4l.cpp:1134 tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
Failed to capture frame from camera

Can you help me with this? I can't figure out what the problem is. I think OpenCV can't get the image, although I can get the image from the camera with the “rpicam” commands.

test.py:

import cv2
cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read()
    if not ret:
        print("Failed to capture frame from camera")
        break
    cv2.imshow("Camera", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

Here some info:

(.venv) bitirme@raspberrypi:~/project/examples/lite/examples/object_detection/raspberry_pi $ ls -l /dev/video0
crw-rw----+ 1 root video 81, 14 Jun  7 15:58 /dev/video0

Update: Thanks for your feedback and please excuse my mistakes as this is the first post I have sent to the forum. First of all, let me say that since I have seen such codes in various videos and on the official site of tensorflow, I try to use them. Here is the most recent video I watched: https://youtu.be/fVmAeK-GLXA What I don't understand is, what is different in the 64-bit Bookworm version of Raspbiban that so many people can do these steps without getting an error, but when I try to do it, I get such an error? Is it related to the camera I'm using? I also tried PiCamera2 in a different code but this time numpy gave me an error. I was getting a long error even though I had numpy installed. I'm really sorry I'm having a hard time understanding but what exactly do I need to use with Raspbian 64-bit Bookworm, Pi Camera v3 and Raspberry pi 4B to perform this object detection?

Upvotes: 0

Views: 291

Answers (0)

Related Questions