Jetson Nano OpenCV 4.1.0

Hi,

I have installed python3.7
I also installed opencv 4.1.0 on my Nano using the script at https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.0.0_Nano.sh and modified the version.

Now, the opencv is present in python3.6 but not in python3.7
when I type
python3.6 and then import cv2 - it’s ok. I can see cv2.version being 4.1.0
python3.7 and then import cv2 - it’s nok. module cv2 not found

Is there a trick how to install the opencv to python3.7 as well?

help, help, please :)

Cheers,
Martin

I have same issue.
Anyone who can help for this :)

I ended up compiling OpenCV from source.

Here are some instructions to do that.

http://docs.donkeycar.com/guide/robot_sbc/setup_jetson_nano/#step-4-install-opencv

yes, we ended up doing the same. We already figured that one so sharing the install script

#!/bin/bash
export DEBIAN_FRONTEND=noninteractive

cd ~/
apt update -y
apt upgrade -y
apt install software-properties-common -y
add-apt-repository ppa:deadsnakes/ppa -y
apt remove python3-apt -y
apt install python3.7-dev -y
apt install python3.7 -y
apt install python3-pip -y
apt install curl -y
apt install unzip -y
apt install libhdf5-serial-dev hdf5-tools -y
apt install build-essential libatlas-base-dev -y
apt install cmake -y
apt install gfortran -y
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.7 get-pip.py
pip3.7 install -I numpy
pip3.7 install Cython
pip3.7 install boto3
pip3.7 install greengrasssdk
pip3.7 install scipy
pip3.7 install sklearn

apt install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
apt install python3-apt -y
apt install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
apt install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
apt install -y curl
apt update

update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2

#CUDA
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/cuda/bin"' >> /etc/environment
echo 'LD_LIBRARY_PATH="/usr/local/cuda/lib64"' >> /etc/environment

#OpenCV
fallocate -l 6G /mnt/6GB.swap
mkswap /mnt/6GB.swap
swapon /mnt/6GB.swap
swapon -s
curl -L https://github.com/opencv/opencv/archive/4.1.0.zip -o opencv-4.1.0.zip
curl -L https://github.com/opencv/opencv_contrib/archive/4.1.0.zip -o opencv_contrib-4.1.0.zip
unzip opencv-4.1.0.zip
unzip opencv_contrib-4.1.0.zip
cd opencv-4.1.0/
mkdir release
cd release/
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="5.3" -D CUDA_ARCH_PTX="" -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.0/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D PYTHON_EXECUTABLE=/usr/bin/python3.7 -D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3.7 ..
make -j3
make install
ldconfig
mkdir /usr/lib/python3.7/dist-packages
cp lib/python3/cv2.cpython-37m-aarch64-linux-gnu.so /usr/lib/python3.7/dist-packages

#Torch
cd ~/
git clone --recursive http://github.com/pytorch/pytorch
cd pytorch

export USE_NCCL=0
export USE_DISTRIBUTED=0
export TORCH_CUDA_ARCH_LIST="5.3;6.2;7.2"
export USE_NUMPY=ON
pip3.7 install https://michael-dietz-tests.s3.amazonaws.com/torch-1.2.0-cp37-cp37m-linux_aarch64.whl
pip3.7 install https://michael-dietz-tests.s3.amazonaws.com/torchvision-0.3.0-cp37-cp37m-linux_aarch64.whl

pip3.7 install -r requirements.txt
pip3.7 install scikit-build --user
pip3.7 install ninja --user

python3.7 setup.py install

cd ~/
apt install -y libjpeg-dev zlib1g-dev
git clone https://github.com/pytorch/vision torchvision
cd torchvision

python3.7 setup.py install

cd ~/

#YOLO3
cd ~/
git clone https://github.com/ZQPei/deep_sort_pytorch.git
cd deep_sort_pytorch/YOLO3/
wget https://pjreddie.com/media/files/yolov3.weights
cd ..
mkdir deep/checkpoint
cd deep/checkpoint
wget https://michael-dietz-tests.s3.amazonaws.com/ckpt.t7
cd ~/

#GreenGrass
adduser --system ggc_user
groupadd --system ggc_group

wget wget https://d1onfpft10uf5o.cloudfront.net/greengrass-core/downloads/1.9.1/greengrass-linux-aarch64-1.9.1.tar.gz
tar -xzvf greengrass-linux-aarch64-1.9.1.tar.gz -C /

#unmount and delete swap file
swapoff -v /mnt/6GB.swap
rm -f /mnt/6GB.swap

Thank you so much zdary and rahul.ravikumar!

How did you get that JEP script to run? All it returns is some (install folder) message

That is my complete script, it contains the parts from JEP script too.
Just flash jetpack, start jetson, open trrminal
sudo su -
And then run the install script

Sure but I dont want python 3.7 just opencv 4.1.0, when running the JEP script it just returns (install folder) message. How do you run the JEP script?

I haven’t installed JEP script myself so I don’t know the error you are refering to.
But I would imagine you need to execute it With a parameter where you want to install the opencv?