I read the post of Adrian Rosebrock (pyimagesearch)
I launched a file bash from cron the python code openvino_real_time_object_detection.sh.
Its contents is:
python3 openvino_real_time_object_detection.py --prototxt MobileNetSSD_deploy.prototxt --model MobileNetSSD_deploy.caffemodel
But it doesn't work. Below the log file :
Traceback (most recent call last):
File "openvino_real_time_object_detection.py", line 2, in <module>
from imutils.video import VideoStream
File "/home/pi/.virtualenvs/openvino/lib/python3.5/site-packages/imutils/__init__.py", line 8, in <module>
from .convenience import translate
File "/home/pi/.virtualenvs/openvino/lib/python3.5/site-packages/imutils/convenience.py", line 6, in <module>
ImportError: libopencv_ml.so.4.0: cannot open shared object file: No such file or directory
I tried to solve this issue, but to no avail.
when I launch this code.sh directly via terminal command like this :
pi@raspberrypi:~ $ bash -x openvino_real_time_object_detection.sh ; the software launches and works perfectly
Could you help me to solve this issue in order to launch the bash file from cron ?
Thanks in advance.
Not 100% sure but when starting programs from cron job no environment is inherited, i.e. scfripts run from cron jobs need to use things like /bin/date instead of just date as no path is set.
I suspect the setupvars.sh that is usually sourced in your .bashrc is not being run via the cron job.
You'll likely need to either create the $PYTHONPATH from within your python code, or launch it from a "wrapper" script that sources it before launching the python3 command when started by cron.
Why are you trying to start it from a cron job?
You will need to add
before the line that starts the actual python3 command.
A lot of stuff goes on behind the scenes when you log in that doesn't happen when a script is run from a cron job. Your cronjob script needs to do all the required setup on its own to make your program. run. For example you may also need the absolute path to the python3 executable.
Adrian sees virtual environments as a necessity. I see it as a needless complication for a Raspberry Pi that is likely going to be doing a single IOT type of task.
I needed to use a Virtual Environment to get his openvino code running on an Odroid XU-4 because the Ubuntu-Mate18 it uses has Python3.6 so I had to "sideload" python 3.5 and use a Virtual environment to get Raspbian OpenVINO to run there. Extra work, but necessary in this case. But I don't create a virtual environment until I encounter a conflict that forces it.