Jetson nano bare metal introduction and Opencv environment configuration

0. Preface

I am obsessed with the direction of hardware. I recently received support from my teacher and borrowed an Nvidia Jetson nano board from the teacher (ecstasy). I will briefly describe nano below. I just got the board and finished lighting the lights. The teacher instructed me to configure the opencv environment after lighting the lights and go to the image processing instruction ocean. The process of configuring opencv is tortuous and painful. Here we mainly summarize and share the configuration process and the ups and downs of stepping into and filling pits.

0.1 Introduction to Jetson Nano

Jetson Nano is a compact and powerful artificial intelligence embedded development board launched by NVIDIA in March 2019. It is pre-installed with Ubuntu 18.04LTS system and equipped with the 128-core Maxwell GPU developed by NVIDIA, which can quickly implement AI technology and apply it to various smart devices. Compared with several previous Jetson products (Jetson TK1, Jetson TX1, Jetson TX2, Jetson Xavier), Jetson Nano is priced at only US$99, significantly reducing the research and development costs of artificial intelligence terminals. Therefore, it has received widespread attention once it was launched.
Here are some advantages of nano:
(1) It is small in size, powerful in performance, affordable, adopts a hardware design similar to Raspberry Pi, supports a series of popular AI frameworks, and NVIDIA has invested a lot of research and development efforts to create a matching Jetpack SDK development kit, which can make learning and developing AI products easier and more convenient.

(2) Designed specifically for AI, its performance is more powerful than that of Raspberry Pi. It is equipped with a quad-core Cortex-A57 processor, 128-core Maxwell GPU and 4GB LPDDR memory, which can bring enough AI computing power to robot terminals and industrial vision terminals. force.

(3) Provides 472 GFLOPs, supports high-resolution sensors, can process multiple sensors in parallel, and can run multiple modern neural networks on each sensor stream.

(4) Support NVIDIA’s NVIDIA JetPack component package, which includes board-level support packages for deep learning, computer vision, GPU computing, multimedia processing, etc., CUDA, cuDNN and TensorRT software libraries.

(5) Supports a series of popular AI frameworks and algorithms, such as TensorFlow, PyTorch, Caffe/Caffe2, Keras, MXNet, etc., allowing developers to easily and quickly integrate AI models and frameworks into products to easily achieve image recognition and target goals Detection, pose estimation, semantic segmentation, video enhancement and intelligent analysis and other powerful functions.

After talking about it, in fact, we can’t afford PC graphics cards such as 1080Ti that are too expensive to run edge computing. However, single-board computers like nano are small in size and come with a built-in GUP, which is simply good news for the public.
————————————————

1.0 Jetson bare metal hardware introduction

First picture
Insert image description here

As you can see, the nano is only slightly larger than a Romoss power bank, but it actually comes with its own GPU.
Let’s take a look at what’s inside the little black box.
First remove the shell.
Insert image description here
Insert image description here

dissipate heat

The above is a brief introduction to the bare metal hardware of Jetson nano.

Initial configuration of 2.0 Jetson nano

Installing the system
I use a tf card to start. Other installations are very detailed on the Weixue official website or others, so I won’t go into details.

2.0.1 Download image

NVIDIA official address
https://developer.nvidia.com/embedded/dlc/jetson-nano-dev-kit-sd-card-image

2.0.2 Format tf card

I am too lazy to install the online tutorials and use other applications to format it. I just select the tf card on my computer, right-click and format it.

2.0.3 Use balenatcher to write the image

Insert image description here

2.0.4 Happy booting~

2.1 Development environment configuration

Change the source after installing the image, otherwise subsequent updates and upgrades will be very slow. However, because Jetson Nano uses an Ubuntu 18.04.2 LTS system with aarch64 architecture, which is different from the Ubuntu system with AMD architecture, it needs to be replaced with the aarch64 source.
Then, back up the original source and enter in the terminal:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak    

Change the source. A window will open here with a bunch of URLs. If it does not pop up, check whether the command is correct
sudo gedit /etc/apt/sources.list
and then delete them all. Copy and paste the following:

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe

The source change is completed and the source is updated:

sudo apt-get update``
sudo apt-get full-upgrade

If you fail, try a few more times

3. Opencv configuration and implementation of face recognition case

This section uses Python to complete the case of face recognition

3.1 Install pip

pip is a Python package management tool that provides the functions of finding, downloading, installing, and uninstalling Python packages.
You can install it directly using the Python 3.6 pre-installed on the system.
Terminal input: sudo apt-get install python3-pip python3-dev
and then upgrade: python3 -m pip install --upgrade pip.
Note that the pip upgrade here is extremely slow and often fails. It tests your patience and your mentality.

3.2 Install Python common learning packages

sudo apt-get install python3-scipy
sudo apt-get install python3-pandas
sudo apt-get install python3-sklearn

Likewise, some packages may fail to download, so be patient.

3.3 Configure opencv for python

Here you can directly use the opencv4.1.1 pre-installed in the original image
and use the following command to view the version number.

opencv_version

3.4 Face detection based on opencv

Code OSS is used in the original tutorial (which can be understood as vscode for nano). But downloading OSS is very tiring, so I edit it directly with vim editor.
Note: The Vim editor is the standard editor under all Unix and Linux systems. It is as powerful as any latest text editor.

Terminal input command

sudo vi face_detect.py

Generate a python script and enter
then press a to enter edit mode and copy and paste the example

import cv2 
filepath = "test.jpg" 
img = cv2.imread(filepath) # 读取图片 
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 转换灰色 
#OpenCV人脸识别分类器 
classifier = cv2.CascadeClassifier( "haarcascade_frontalface_default.xml" ) 
color = (0, 255, 0) # 定义绘制颜色 
#调用识别人脸 
faceRects = classifier.detectMultiScale( gray, scaleFactor=1.2, minNeighbors=3, minSize=(32, 32)) 
if len(faceRects): # 大于0则检测到人脸 
    for faceRect in faceRects: # 单独框出每一张人脸 
        x, y, w, h = faceRect 
        # 框出人脸 
        cv2.rectangle(img, (x, y), (x + h, y + w), color, 2) 
cv2.imshow("image", img) # 显示图像 
c = cv2.waitKey(10) 
cv2.waitKey(0) 
cv2.destroyAllWindows()

If you haven’t started learning about opencv face recognition, you should pay special attention here. The example requires a test.jpg picture in the path where the py script is located (see the second line of code.) and the face recognition configuration file (in xml file with the suffix) (see line 6 of the code). I just don’t understand what the face recognition configuration file in the original tutorial is, and then an error is reported. Then
enter
$ python3 face_detect.py in the terminal
to run the example normally and identify the test .jpg face~
Insert image description here

4. Summary

The configuration of Opencv under Jetson nano is tortuous and mysterious. Here are a few points to summarize:

  1. Be patient when installing software and libraries. If it fails, try a few more times.
  2. The tutorial is not customized for us individually. If you don’t understand something, you need to Baidu it yourself.
  3. Make good use of tools, such as search engines. If you can't find something, use another search engine. You might be surprised. Use Bing, Baidu, etc. flexibly. If possible, you can directly chat GPT, which is very powerful. It is a powerful tool for beginners to debug and improve learning efficiency.
  4. If you ask a question to a senior or teacher, be sure to pay attention to how you ask. Do not send instant messages to the teacher, because the teacher may need to use QQ or WX to receive important notifications. Sending instant messages will disturb the teacher, especially when the teacher is busy. You can use email to write down the background of the problem, error log, and your own ideas and send it to the teacher.
  5. The last and most important point is to be good at debugging. Program errors are very common, and finding errors is very critical. It is most efficient to use the keywords in the error log to use tools to find errors. Note that it is a keyword. Try to shorten the error content as much as possible and include more keywords to go to Baidu.

Zhihuijun said that too advanced technology is like magic to ordinary people. To me, it's amazing to be able to use these small components to achieve various operations. I also love being immersed in the electronic world, it's all magical. I hope everyone can find what they love and pursue the dreams they want to pursue.

Refer to the original link:
https://blog.csdn.net/qianbin3200896/article/details/103760640
JETSON NANO - Waveshare Wiki
(39 messages) Jetson Nano (1): System Burning_Luan Baobao's blog who loves learning-CSDN blog

Guess you like

Origin blog.csdn.net/qq_46558184/article/details/129471097