3

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?

nullcline
  • 342
  • 1
  • 15

2 Answers2

1

I wasn't able to resolve my specific issue, but I did manage to find a way to run my script on boot.

I added the following lines the end of my .bashrc,

source /opt/intel/openvino/bin/setupvars.sh
cd /home/pi/project
python3 run.py 
cd 

to initialize the OpenVINO environment and run my script every time a new terminal is opened, and then I made the LXTerminal run on boot by adding @lxterminal to the end of /etc/xdg/lxsession/LXDE-pi/autostart.

It's a pretty hacky way to do it and impractical if you're planning to use your Pi for anything else. Any advice would still be appreciated

nullcline
  • 342
  • 1
  • 15
1

Thanks to Mauricio.R from Intel I was able to find a proper solution.

  1. Create a script that initializes OpenVINO and launches my python script using nano ~/openvino-app-script with contents:
   #!/bin/bash
   source /opt/intel/openvino/bin/setupvars.sh     
   /usr/bin/python3 /path/to/script/run.py
  1. 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

  2. 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
  1. Activate the service with 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.

nullcline
  • 342
  • 1
  • 15