默认你的jetson nano已经安装镜像并启动。打开控制终端,输入如下命令安装依赖库
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get install build-essential python3 python3-dev python3-pip python3-pandas python3-opencv python3-h5py libhdf5-serial-dev hdf5-tools nano ntp
- pip3 install virtualenv
- python3 -m virtualenv -p python3 env
- echo "source env/bin/activate" >> ~/.bashrc
- source ~/.bashrc
- # Turn off swap
- sudo swapoff /var/swapfile
- # Allocates 4G of additional swap space at /var/swapfile
- sudo fallocate -l 4G /var/swapfile
- # Permissions
- sudo chmod 600 /var/swapfile
- # Make swap space
- sudo mkswap /var/swapfile
- # Turn on swap
- sudo swapon /var/swapfile
- # Automount swap space on reboot
- sudo bash -c 'echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab'
- # Reboot
- sudo reboot
- # Update
- sudo apt-get update
- sudo apt-get upgrade
- # Pre-requisites
- sudo apt-get install build-essential cmake unzip pkg-config
- sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
- sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
- sudo apt-get install libxvidcore-dev libx264-dev
- sudo apt-get install libgtk-3-dev
- sudo apt-get install libatlas-base-dev gfortran
- sudo apt-get install python3-dev
- # Create a directory for opencv
- mkdir -p projects/cv2
- cd projects/cv2
- # Download sources
- wget -O opencv.zip https://github.com/opencv/opencv/archive/4.1.0.zip
- wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.1.0.zip
- # Unzip
- unzip opencv.zip
- unzip opencv_contrib.zip
- # Rename
- mv opencv-4.1.0 opencv
- mv opencv_contrib-4.1.0 opencv_contrib
- source ~/env/bin/activate
- # Install Numpy
- pip install numpy
- # Create a build directory
- cd projects/cv2/opencv
- mkdir build
- cd build
- # Setup CMake
- cmake -D CMAKE_BUILD_TYPE=RELEASE \
- -D CMAKE_INSTALL_PREFIX=/usr/local \
- -D INSTALL_PYTHON_EXAMPLES=ON \
- -D INSTALL_C_EXAMPLES=OFF \
- -D OPENCV_ENABLE_NONFREE=ON \
- # Contrib path
- -D OPENCV_EXTRA_MODULES_PATH=~/projects/cv2/opencv_contrib/modules \
- # Your virtual environment's Python executable
- # You need to specify the result of echo $(which python)
- -D PYTHON_EXECUTABLE=~/env/bin/python \
- -D BUILD_EXAMPLES=ON ../opencv
- make -j2
- # Install OpenCV
- sudo make install
- sudo ldconfig
- # Go to the folder where OpenCV's native library is built
- cd /usr/local/lib/python3.6/site-packages/cv2/python-3.6
- # Rename
- mv cv2.cpython-36m-xxx-linux-gnu.so cv2.so
- # Go to your virtual environments site-packages folder
- cd ~/env/lib/python3.6/site-packages/
- # Symlink the native library
- ln -s /usr/local/lib/python3.6/site-packages/cv2/python-3.6/cv2.so cv2.so
- ls -la
- total 48
- drwxr-xr-x 10 user user 4096 Jun 16 13:03 .
- drwxr-xr-x 5 user user 4096 Jun 16 07:46 ..
- lrwxrwxrwx 1 user user 60 Jun 16 13:03 cv2.so -> /usr/local/lib/python3.6/site-packages/cv2/python-3.6/cv2.so
- -rw-r--r-- 1 user user 126 Jun 16 07:46 easy_install.py
- drwxr-xr-x 5 user user 4096 Jun 16 07:47 pip
- drwxr-xr-x 2 user user 4096 Jun 16 07:47 pip-19.1.1.dist-info
- drwxr-xr-x 5 user user 4096 Jun 16 07:46 pkg_resources
- drwxr-xr-x 2 user user 4096 Jun 16 07:46 __pycache__
- drwxr-xr-x 6 user user 4096 Jun 16 07:46 setuptools
- drwxr-xr-x 2 user user 4096 Jun 16 07:46 setuptools-41.0.1.dist-info
- drwxr-xr-x 4 user user 4096 Jun 16 07:47 wheel
- drwxr-xr-x 2 user user 4096 Jun 16 07:47 wheel-0.33.4.dist-info
- import cv2
- # Should print 4.1.0
- print(cv2.__version__)
- (env) jetson@jetson:~$ python
- Python 3.6.8 (default, Jan 14 2019, 11:02:34)
- [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import cv2
- >>> print(cv2.__version__)
- 4.1.0
- >>> quit()
- cd ~/projects
- git clone https://github.com/waveshare/donkeycar
- cd donkeycar
- git checkout master
- pip install -e .[nano]
- pip install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v42 tensorflow-gpu==1.13.1+nv19.3
- donkey createcar --path ~/mycar
程序运行后~/mycar目录下回自动生成一系列控制donkeycar的文件。
- nano myconfig.py
Jetson Nano使用基于Sony IMX219的相机,摄像头改为CSIC,分辨率设置为224*224.
- #CAMERA
- CAMERA_TYPE = "CSIC" # (PICAM|WEBCAM|CVCAM|CSIC|V4L|MOCK)
- IMAGE_W = 224
- IMAGE_H = 224