Can't display anything using Opencv after stratup

I configured my jetson nano 2gb to run a script on startup, I also enabled auto-login.
I need to display the camera output on the screen after startup using cv2.imshow(), every thing works fine if I start the script manually, but when the script runs automatically it gives the following error :
“python3[6550]: cannot open display” and “GStreamer warning: Cannot query video position: status=0,value=-1,duration-1”
I found some threads that proposed changing the pipeline, but to avail…
I also tried only displaying a single image which also failed.
Any ideas ???

Hi,
Please check Jetson Nano FAQ

Q: How to autorun an app or commands at startup?

@DaneLLL
Hello,
Thanks for the reply,
I checked the FAQ and it proposed 2 solutions:
1-Enable rc.local with systemd and configure the pipelines
2- Put the commands to ~/.xsessionrc
I didn’t try the first one, since I don’t think it is a pipeline problem, I feel it’s more simple than that.
I tried the second solution and the camera stream did start, but I wasn’t able to stop it without entering console mode and killing the process.
Any ideas how should I proceed?

Hi,
You can set num-buffers to nvarguscamerasrc so that it stops after capturing required number of frames.

@DaneLLL
Doing what you said did not change anything, a window outputting the camera’s frames kept showing on the screen, and I couldn’t exit it without killing the process.
I used the camera.py script from the link, but my app wont start in this mode.
The issue that I receive is : “python: cannot open display” when checking the service status
What is the source of this problem?
.Any ideas how it can be solved ?
I have been stuck at this problem for a long time…

Thanks in advance.

Hi,
Generally we run the sample and exit by Ctrl+C. This is beyond our experience. We would suggest go to https://forum.opencv.org/ to get further help.

@DaneLLL
Hi,
I am very gratefull,
My app runs fine when I run it manually, however I only face this issue when it starts automatically through mything.service. Python is unable to “open” the display and output on the screen.
What I need is to output the stream of the camera on the screen after some processing directly after boot, how can this be achieved ?

Thanks again.

Hi,
So you follow this post to run camera.py and it fails?
Mediapipe error Open Gl error in myservice.service - #14 by DaneLLL

We have verified this and it shall work fine. A bit strange you cannot run it successfully.

@DaneLLL
Hello,
Actually this post works fine with the camera.py, however my application needs some “sudo” permissions and I think this is causing the app to fail, and placing sudo before starting the app did not work, what do you think ? how can I debug the errors in xsessionrc?
Side question, is there a problem to use the “.xsessionrc” file to launch scripts on boot, just like the other methods?

Hi,
For our experience, root user is not able to access X session. You would need to be a normal user for running a command in .xsessionrc.

@DaneLLL,
Ok…
So how can I run an application that needs root permissions on startup, while also requiring to display camera output on the screen ?

I found the following solution :

Thank you for your assistance.

1 Like