Picar-X: Camera closes after capturing one frame

I have been going through the project for the picar-x on the website and everything works well until #7. Computer Vision. When I run it, it captures 1 frame and then the camera automatically closes. The program doesn’t end there, so I have to Ctrl-C to exit if that gives any clues. I can look at the Flask app on the url provided to see the picture it takes. Also when I run ‘rpi-hello’ it takes video fine so I’m confident that the camera and connections are good. I think it could be related to the flask app but i’m not sure. I will show what the terminal prints out when I force exit the program but I can’t make sense of it.

There may be a conflict between the system desktop and the video source. When you run the example code, the video display shows for a moment before automatically closing, and then the screen freezes when you access the video source through the browser.

Please modify the code in the 7.display.py file and then re-run the 7.display.py example to check the working status.

Change Vilib.display(local=True, web=True) to:

Vilib.display(local=False, web=True)

Save the changes, exit the code file, and then run it again.

1 Like

Awesome, that worked! Thank you for the help. I figured it was something simple since I could take videos using the rpicam command.

I have been experiencing the same problem with the camera opening for a single shot and then stopping. I followed the advice above setting the local=False attribute, and this works fine for the camera streaming to a web browser (I have been running the 7.computer_vision.py script in ~picar/example folder). BUT… the “take photo” function is not working.

When I don’t set the local=False attribute and leave it as the default local=True, an error appears in the terminal stating:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

I notice that the /tmp/runtime-root folder is owned by the root user rather than me and wonder if the local=True attribute is making the script try to use that folder for storing temp images/data but is being refused because of the permissions. (I should add, I am not at all an expert in how Raspbian / linux works).

Can you advise how I can overcome this problem, as I want to be able to “Take photo”?

When both local=True (local display) and web=True (web stream) are enabled simultaneously, resource conflicts may occur. It is recommended to choose one based on your needs (prioritizing web=True mode for better compatibility).

After setting Vilib.display(local=False, web=True), please rerun the 7.computer_vision.py script. Then, access the camera stream via the web page and take a photo.

The photo file will be saved to the /home/{username}/Pictures directory. Please open the Pictures directory to check if the captured photo is there.