With the new single board computer „Jetson Nano“ from nvidia it is possible to make this little thing really „see“ and detect things.
This 99.00 $ sbc is able to recognise the real world and process the things it sees in nearly realtime. For such a little thing it is astonishing what you can do nowadays: only with a dirty cheap usb webcam and a more dirty cheap computer running on 5V.
What you can see here are some examples from the open source Computer Vision software OpenCV version 4.1.1 written in python exectuted directly on the Jetson Nano. The usb camera is watching TV (soccer, of course :-))
On the monitor connected to the Jetson Nano via HDMI you can see the images being processed by OpenCV 4.1.1. The samples can be found in the (… surprise, surprise) opencv’s samples/python folder.
If you are interested in how to get OpenCV 4.1.1 installed on the Nano: Here we go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
#prepare jetson nano sudo apt update sudo apt upgrade sudo apt full-upgrade --autoremove # get rid of old installation sudo apt-get purge *libopencv* # install everything we need for compile sudo apt install -y \ build-essential \ curl \ git \ gfortran \ liblapacke-dev \ libavcodec-dev \ libavformat-dev \ libavresample-dev \ libcaffe-cpu-dev \ libdc1394-22-dev \ libgflags-dev \ libgoogle-glog-dev \ libgstreamer1.0-dev \ libgstreamer-plugins-base1.0-dev \ libgtk2.0-dev \ libgphoto2-dev \ libjpeg-dev \ libpng-dev \ libtheora-dev \ libmp3lame-dev \ libswscale-dev \ libtbb-dev \ libtbb2 \ libtiff-dev \ libv4l-dev \ libavcodec-dev \ libavformat-dev \ libhdf5-dev \ libxvidcore-dev \ libx264-dev \ libatlas-base-dev \ libblas-dev \ libcurl4-gnutls-dev \ liblapack-dev \ libeigen3-dev \ libswscale-dev \ libprotobuf-c-dev \ libprotobuf-dev \ libprotoc-dev \ protobuf-compiler \ pkg-config \ python-dev \ python-numpy \ python-pip \ python3-pip \ python-tk \ python3-tk \ python3-numpy \ python2.7-dev \ python3-dev \ qt5-qmake \ qttools5-dev-tools \ qt5-default \ libcurl4-openssl-dev \ libssl-dev \ libeigen-stl-containers-dev \ python-qt4-dev \ libtesseract-dev #prepare for installing a recent version of cmake #install cmake from source cd ~ sudo apt remove --purge cmake sudo apt install libcurl4-openssl-dev curl -L https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz -o cmake-3.15.2.tar.gz tar xf cmake-3.15.2.tar.gz cd cmake-3.15.2 ./bootstrap --prefix=/usr --parallel=j$(nproc) make -j$(nproc) sudo make install # test (optional) cmake --version # cmake version 3.15.2 # CMake suite maintained and supported by Kitware (kitware.com/cmake). curl -L https://bootstrap.pypa.io/get-pip.py -o get-pip.py sudo -H pip install virtualenv virtualenvwrapper remove old cache sudo rm -rf ~/.cache/pip # virtualenv and virtualenvwrapper export WORKON_HOME=$HOME/.virtualenvs # we use python3 as a standard in virtual environment export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python source /usr/local/bin/virtualenvwrapper.sh export VIRTUALENVWRAPPER_PYTHON3=/usr/bin/python3 source /usr/local/bin/virtualenvwrapper.sh # setting this permanently echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.bashrc echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python" >> ~/.bashrc echo "export VIRTUALENVWRAPPER_PYTHON3=/usr/bin/python3" >> ~/.bashrc echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc # create a virtual environment cd ~ mkvirtualenv cv_python3 -p python3 mkvirtualenv cv_python2 -p python # this should give you # Already using interpreter /usr/bin/python3 # Using base prefix '/usr' # New python executable in /home//.virtualenvs/cv/bin/python3 # Also creating executable in /home//.virtualenvs/cv/bin/python # Installing setuptools, pip, wheel… # done. # virtualenvwrapper.user_scripts creating /home//.virtualenvs/cv/bin /predeactivate # virtualenvwrapper.user_scripts creating /home//.virtualenvs/cv/bin/postdeactivate # virtualenvwrapper.user_scripts creating /home//.virtualenvs/cv/bin/preactivate # virtualenvwrapper.user_scripts creating /home/.virtualenvs/cv/bin/postactivate # virtualenvwrapper.user_scripts creating /home//.virtualenvs/cv/bin/get_env_details # (cv) @jetson:~/opencvComplete/opencv-4.1.1/release # the "(cv) in fromt of @jetson is the important one. If you do not see #this yet, try it with workon cv # if you want to leave the virtual environment, simple do it with # "deactivate" + ctrl (cv) … pip install numpy # we need MORE MEMORY for the build # check memory: sudo swapon --show # on a jetson nano it gives you # bNAME TYPE SIZE USED PRIO # /dev/zram0 partition 494,6M 0B 5 # /dev/zram1 partition 494,6M 0B 5 # /dev/zram2 partition 494,6M 0B 5 # /dev/zram3 partition 494,6M 0B 5 # create a swap file - for building opencv4.1.1 3G additional swap were tested o.k. # allocate the file: sudo fallocate -l 3G /swapfile # only root should have access to this file: sudo chmod 600 /swapfile # create the file-> sudo mkswap /swapfile # activate the swap file -> sudo swapon /swapfile # test if everything is o.k.-> # sudo swapon --show # another test -> sudo free -h # adjust swapiness - first lets see what we have now -> cat /proc/sys/vm/swappiness # set swapiness to a value of e.g. 10 -> (for me the default was o.k.) sudo sysctl vm.swappiness=10 # do not forget to remove the swap file after compiling when you are # working on an SD-card! # deactivate it with -> sudo swapoff -v /swapfile # remove it -> sudo rm /swapfile # protobuf -fix # If you have protobuf installed, then configure your build with # -BUILD_PROTOBUF=OFF and -WITH_PROTOBUF=ON # If you do NOT have protobuf installed, just ensure you have #-BUILD_PROTOBUF=ON # It worked for me with OpenCV 4.1.1 on Ubuntu 18.4.3 with CUDA 10.0 # get the sources cd ~ curl -L https://github.com/opencv/opencv/archive/4.1.1.zip -o opencv-4.1.1.zip curl -L https://github.com/opencv/opencv_contrib/archive/4.1.1.zip -o opencv_contrib-4.1.1.zip unzip opencv-4.1.1.zip unzip opencv_contrib-4.1.1.zip cd opencv-4.1.1/ # prepare build folder mkdir release && cd release # fix eigen bug (important to get eigen running) sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen cmake --system-curl -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D CMAKE_BUILD_TYPE=RELEASE \ -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.1/modules \ -D OPENCV_ENABLE_NONFREE=ON \ D ENABLE_PRECOMPILED_HEADERS=OFF \ -D WITH_CUDA=ON \ -D CUDA_ARCH_BIN="5.3" \ -D CUDA_ARCH_PTX="" \ -D CUDA_FAST_MATH=1 \ -D BUILD_PERF_TESTS=OFF \ -D BUILD_TESTS=OFF \ -D BUILD_DOCS=OFF \ -D WITH_JASPER=OFF \ -D BUILD_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=OFF \ -D WITH_TBB=ON \ -D WITH_HDF=ON \ -D WITH_OPENMP=ON \ -D WITH_JAVA=OFF \ -D WITH_GSTREAMER=ON \ -D WITH_LIBV4L=ON \ -D WITH_EIGEN3=ON \ -D PYTHON2_INCLUDE_PATH=/usr/include/python2.7 \ -D PYTHON2_LIBRARIES=/usr/lib/python2.7/config-aarch64-linux-gnu/libpython2.7.so \ -D PYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/python2.7/dist-packages/numpy/core/include \ -D PYTHON3_INCLUDE_PATH=/usr/include/python3.6 \ -D PYTHON3_LIBRARIES=/usr/lib/python3.6/config-3.6m-aarch64-linux-gnu/libpython3.6.so \ -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include \ -D WITH_QT=ON \ -D BUILD_OPENCV_PYTHON2=ON \ -D BUILD_OPENCV_PYTHON3=ON \ -D PYTHON2_EXECUTABLE=/usr/bin/python2.7 \ -D PYTHON_EXECUTABLE=/usr/bin/python \ -D BUILD_WITH_DEBUG_INFO=OFF \ -Wno-dev \ -Wno-undef \ -Wno-strict-aliasing \ .. make -j$(nproc) sudo make -j$(nproc) install cd /usr/local/lib/python3.6/dist-packages/cv2/python-3.6/ ln -s cv2.so cv2.cpython-36m-aarch64-linux-gnu.so sudo ldconfig sudo swapon --show sudo swapoff -v /swapfile sudo swapon --show sudo rm /swapfile workon cv_python3 (cv) pip install numpy -vv |
Have fun.