I am using a Raspberry Pi 3 Model B Rev 1.2 running Raspbian 10 (Buster). I want to run a python script on startup that uses OpenVINO and OpenCV to detect objects and display a stream from a webcam.
I created a shell script launcher.sh
that contains
#!/bin/sh
/opt/inte/openvino/bin/setupvars.sh
/usr/bin/python3 /home/pi/project/run.py
I ran $ chmod 775 launcher.sh
and confirmed that the script works with $ sh launcher.sh
.
To run the script on start up I used $ sudo crontab -e
and added @reboot sh /home/pi/project/launcher.sh >/home/pi/logs/cronlog 2>&1
to the bottom.
The script does run on reboot. The logs show that the OpenVINO environment is initialized, but the logs also indicate I get a ModuleNotFoundError: No module named 'openvino'. I'm guessing it only works when i run it from the terminal because I have my bash.rc setting up the OpenVINO env each time.
What am I doing wrong? Is there a better way to do this on Buster?
Thanks to Mauricio.R from Intel I was able to find a proper solution.
nano ~/openvino-app-script
with contents: #!/bin/bash
source /opt/intel/openvino/bin/setupvars.sh
/usr/bin/python3 /path/to/script/run.py
Change the bash script's permissions and ownership with chmod u+x ~/openvino-app-script
. You should make sure this script works by running it with bash ./openvino-app-script
Create a service file using sudo nano /etc/systemd/system/openvino-app.service
with contents
[Unit]
Description=OpenVINO Python Script
After=network.target
[Service]
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/pi/.Xauthority"
ExecStart=/home/pi/openvino-app-script
WorkingDirectory=/home/pi
StandardOutput=inherit
StandardError=inherit
Restart=on-failure
User=pi
[Install]
WantedBy=graphical.target
sudo systemctl enable openvino-app.service
You can check the status or disable the service by changing enable
to disable
or status
This solution works great for my project, which displays a video-stream with an overlay using OpenCV and performs inference using an NCS.