How to set up Raspberry Pi Buster and Intel NCS2 and OpenVINO with OpenCV trackers - opencv

Is there a definitive set of instructions to implement OpenCV trackers with OpenVINO and the now-obsolete NCS2 on a RPi 4b - Buster?
My understanding that the last OpenVINO to support the NCS2 was v2020.3.
I attempted to cross-compile using:
https://github.com/opencv/opencv/wiki/Intel-OpenVINO-backend#raspbian-buster
After installing opencv/opencv-contrib 4.5.5 from source:
$ python3
Python 3.7.3 (default, Oct 31 2022, 14:04:00)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.5.5'
>>> tracker = cv2.TrackerCSRT_create()
>>>
However, in a test.py script I have:
...
import cv2
net = cv2.dnn.readNetFromCaffe(_weights, _model)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
...
detections = net.forward()
I get the error relating to DNN_TARGET_MYRIAD:
cv2.error: OpenCV(4.5.5) /home/pi/opencv/modules/dnn/src/dnn.cpp:1414: error: (-215:Assertion failed) preferableBackend != DNN_BACKEND_OPENCV || preferableTarget == DNN_TARGET_CPU || preferableTarget == DNN_TARGET_OPENCL || preferableTarget == DNN_TARGET_OPENCL_FP16 in function 'setUpNet'
I then used this to install OpenVINO:
https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_raspbian.html
but using this version of OpenVINO (as the last to support the NCS2):
https://storage.openvinotoolkit.org/repositories/openvino/packages/2020.3/l_openvino_toolkit_runtime...
I exported the paths to the new post cross-compiled opencv_install directory:
$ export PYTHONPATH=/home/pi/Desktop/opencv_install/lib/python2.7/dist-packages/:$PYTHONPATH
$ export PYTHONPATH=/home/pi/Desktop/opencv_install/lib/python3.7/site-packages/:$PYTHONPATH
$ export LD_LIBRARY_PATH=/home/pi/Desktop/opencv_install/lib/:$LD_LIBRARY_PATH
I set up the NCS2 with no errors :
$ sudo usermod -a -G users "$(whoami)"
$ sh /opt/intel/openvino_2020.3/install_dependencies/install_NCS_udev_rules.sh
then:
$ source /opt/intel/openvino_2020.3/bin/setupvars.sh
and then checked:
$ python3
Python 3.7.3 (default, Oct 31 2022, 14:04:00)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.3.0-openvino-2020.3.0'
>>> tracker = cv2.TrackerCSRT_create()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'cv2' has no attribute 'TrackerCSRT_create'
>>>
If I open a new terminal and $ source /opt/intel/openvino_2020.3/bin/setupvars.sh
then run a test.py script:
...
import cv2
net = cv2.dnn.readNetFromCaffe(_weights, _model)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
...
detections = net.forward()
...
I get a segmentation fault error.
So far I have not edited any of the setup scripts.
Thanks for any help! I'd like to put this NCS2 to work.

Generally, if you are able to run some OpenVINO demo with NCS2 after following this installation guide, then you should be able to use that OpenCV functionality (ensured that you had installed the correct OpenCV).
It's recommended to use the recent OpenVINO and OpenCV version.
As indicated in this OpenVINO System Requirements, the current recommended OpenCV version is 4.5.

Related

glob module is refereed from system package instead of python venv

While trying to import glob in a python venv environment, it is referring to the system package and not the virtual environment even though pandas module is referring to the virtual environment.
I am using python 3.8 and I created a virtual environment using python venv :
cd trial_3
python3 -m venv trial_3_env
On trying to use glob module (which i haven't yet installed in the environment), I can see that it is not throwing any error, but using the glob module from the system packages.
Please find the screenshot showing the same below:
(trial_3_env) anitta#vinjohn:~/Desktop/Study_Data_Engineering/virtualenv_trial/trial_3$ pip freeze
numpy==1.23.4
pyspark==3.3.0
python-dateutil==2.8.2
pytz==2022.6
six==1.16.0
(trial_3_env) anitta#vinjohn:~/Desktop/Study_Data_Engineering/virtualenv_trial/trial_3$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import glob
>>> glob.__file__
'/usr/lib/python3.8/glob.py'
>>>
I tried checking this behavior with pandas module, but they are working as expected and throw error while importing when I have not preinstalled them in my system.
(trial_3_env) anitta#vinjohn:~/Desktop/Study_Data_Engineering/virtualenv_trial/trial_3$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>>
Could someone let me know the cause of globs behavior ? and if such scenario can occur for other modules as well.
Thanks in advance!
#ChrisD and #sinoroc answers helped me. standard libraries of venv python interpreter are referenced from the system python interpreter path itself and venv folder doesn't have any python standard libraries stored inside.

conda python 3.7 opencv import error libgnutls.so.30: undefined symbol: mpn_add_1, version HOGWEED_4

I am facing problem while getting opencv to work with python 3.7 in Conda on Ubuntu 20.04.
I get the following error when I try to import cv2 in python:
$ python
Python 3.7.8 | packaged by conda-forge | (default, Jul 23 2020, 03:54:19)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/swagat/anaconda3/envs/tf2py37/lib/python3.7/site-packages/../../././libgnutls.so.30: undefined symbol: mpn_add_1, version HOGWEED_4
my Conda configuration looks something like this:
active environment : tf2py37
active env location : /home/swagat/anaconda3/envs/tf2py37
shell level : 2
user config file : /home/swagat/.condarc
populated config files :
conda version : 4.8.5
conda-build version : 3.18.9
python version : 3.7.4.final.0
virtual packages : __cuda=10.1
__glibc=2.31
I installed opencv from the conda-forge channel using the following command:
$ conda install -c conda-forge opencv
I can see that opencv is installed on my system:
$ conda list opencv
# packages in environment at /home/swagat/anaconda3/envs/tf2py37:
#
# Name Version Build Channel
libopencv 4.5.0 py37_2 conda-forge
opencv 4.5.0 py37_2 conda-forge
py-opencv 4.5.0 py37hc6149b9_2 conda-forge
I also checked if gnutls is installed:
$ conda list gnutls
# packages in environment at /home/swagat/anaconda3/envs/tf2py37:
#
# Name Version Build Channel
gnutls 3.6.13 h79a8f9a_0 conda-forge
What else I can try to solve this problem? I am kind of stuck here. Any help will be appreciated. Thanks.
It seems that conda version of the opencv is broken.
My solution is:
remove your conda opencv and install the native one:
conda remove opencv
python -m pip install opencv-python # Execute this with your conda env activated

Keras running in Docker very slow and crashes - ValueError: Feature my_feature is not in features dictionary

I can run Keras neural net locally on my W10 laptop fine
But same code running in Docker is extremely slow and always crashes with error:
ValueError: Feature my_feature is not in features dictionary.
The feature not found is always the target feature
There are version differences between laptop and container but I'm not convinced this has bearing
Laptop
Windows 10 Enterprise 64bit
Intel Core i7-7820HQ # 2.90GHz
16GB RAM
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
λ pip list | grep tensorflow
tensorflow 2.0.0
tensorflow-estimator 2.0.1
λ pip list | grep pandas
pandas 0.23.3
pandas-ml 0.6.1
λ pip list | grep numpy
numpy 1.17.4
Docker
# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Python 3.6.10 (default, Apr 23 2020, 15:40:23)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
root#modelbuilder:~# pip list | grep tensorflow
tensorflow 2.3.0
tensorflow-estimator 2.3.0
root#modelbuilder:~# pip list | grep pandas
pandas 0.24.0
pandas-ml 0.6.1
root#modelbuilder:~# pip list | grep numpy
numpy 1.19.2
Verified what was mentioned here: ValueError: Feature not in features dictionary
Target is not being fed into feature columns, features correspond etc, and this would also fail locally.
Any help will be much appreciated
Figured this out.
Crash issue:
In error created feature column for target, so removed the target from features for columns
Slow Docker:
Was running model.fit() over and over (many times)

Still loads previous version after upgrading latest version OpenCV 4.4.0

I upgraded OpenCV 4.4.0 from OpenCV 4.2.x with pip command :
pip install --upgrade opencv-python==4.4.0.40
and checked the upgrade completed :
Collecting opencv-python==4.4.0.40
|████████████████████████████████| 33.5 MB 283 kB/s
Requirement already satisfied, skipping upgrade: numpy>=1.17.3 in c:\users\kangs\anaconda3\lib\site-packages (from opencv-python==4.4.0.40) (1.18.5)
Found existing installation: opencv-python 4.3.0.36
Successfully uninstalled opencv-python-4.3.0.36
PS C:\Users\kangs\Documents\TELPA\Source\numberplateRecognition> python
Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.4.0'
>>> exit()
However, I still get this error message when I run this code :
cv2.dnn.readNet(WEIGHTS, CFG)
Error message :
Traceback (most recent call last):
File "c:\Users\kangs\Documents\TELPA\Source\numberplateRecognition\number_plate_v4c.py", line 54, in <module>
File "c:\Users\kangs\Documents\TELPA\Source\numberplateRecognition\algorithm\detection\yolodetector.py", line 39, in __init__
self.load_dir(dir_path)
File "c:\Users\kangs\Documents\TELPA\Source\numberplateRecognition\algorithm\detection\yolodetector.py", line 50, in load_dir
self.load_files(file_list)
File "c:\Users\kangs\Documents\TELPA\Source\numberplateRecognition\algorithm\detection\yolodetector.py", line 78, in load_files
self.net = cv2.dnn.readNet(WEIGHTS, CFG)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\dnn\src\darknet\darknet_io.cpp:686: error: (-212:Parsing error) Unsupported activation: mish in function 'cv::dnn::darknet::ReadDarknetFromCfgStream'
I found out that the code still linked to the previous library OpenCV 4.2.0.
Can someone please let me know why this happens and how to solve this problem?

Issue installing OpenCV 4.1.2 on Jetson Nano. import cv2, No module named 'cv2'

I installed OpenCV 4.1.2 from source with CUDA support. Had no issues. and created a symbolic link from OpenCV’s installation directory to my virtualenv
ln -s /usr/local/lib/python3.6/site-packages/cv2/python3.6/cv2.cpython-36m-aarch64-linux-gnu.so cv2.so
I am having an issue with import cv2
$ python
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>>
I checked site-packages directory and I can see cv2.so. I am obviously missing something.
The main issue here in my view I am not able to link to my virtualenv, in fact I am able to check my installation and its working
/usr/local/lib/python3.6/site-packages/cv2/python-3.6$ python
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
Issue solved a very very little mistake
I changed the name from
cv2.cpython-36m-aarch64-linux-gnu.so to cv2.so
I realized it was an issue with one of the folders, this will do the magic:
ln -s /usr/local/lib/python3.6/site-packages/cv2/python-3.6/cv2.so cv2.so
notice its python-3.6 not python3.6 after cv2

Resources