首先感谢horizon.AI社区给与的这样一次机会。
一、初步印象
收到板子后一直在外出差,上上周才回来见到本尊,板子很漂亮,于是斥巨资购买USB camera一只。

之后Rufus下载Ubuntu server版img烧写进一张32G TF卡,之前用8G的一直死活不能启动,换32G马上正常。
使用自带的串口工具,一个很高的波特率(921600),第一次遇见,之前都是9600/115200。部分启动信息:
U-Boot 2018.09 (May 13 2022 - 04:13:58 +0000), Build: jenkins-aiot-x3solution-aiot_bsp_x3-198
Model: Hobot XJ3 Soc Board
DRAM: system DDR size: 0x7fe00000
2 GiB
MMC: dwmmc@A5010000: 0, dwmmc@A5011000: 1, dwmmc@A5012000: 2 (SD)
Loading Environment from UBI... GigaDevice SPI NAND was found.
128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
*** Warning - bad CRC, using default environment
In: serial@a5000000
Out: serial@a5000000
Err: serial@a5000000
Net: x3 sdb reset eth phy done
Warning: ethernet@A5014000 (eth0) using random MAC address - b2:af:2c:95:41:bb
eth0: ethernet@A5014000
Disable cnn cores ..
dtb_name:hobot-x3-pi.dtb
base board type: X3 SDB
bootmode: NAND
board_id = 31520324
hb_boot_args_cmd_set custom_bootargs 0 ubuntu_boot 1
Hit any key to stop autoboot: 0
enable watchdog success !
switch to partitions #0, OK
mmc2 is current device
Scanning mmc 2:1...
Found U-Boot script /boot/boot.scr
674 bytes read in 2 ms (329.1 KiB/s)
## Executing script at 03c10000
Boot script loaded from devtype:mmc devnum:2 devplist:1
Loading fdt file: /boot/hobot/hobot-x3-pi.dtb
67288 bytes read in 6 ms (10.7 MiB/s)
Loading kernel: /boot/vmlinuz-4.14.87
13897736 bytes read in 613 ms (21.6 MiB/s)
## Flattened Device Tree blob at 03c00000
Booting using the fdt blob at 0x3c00000
Loading Device Tree to 0000000003c00000, end 0000000003c1ffff ... OK
chip_id: ab36300
The address of the fdt is 0x3c00000
Changed status Done
Can't get fdt_addr !!!Orign(MAX) bpu model Reserve Mem Size to 64M!!
Starting kernel ...
root/root进去后,一些系统信息,包括四核ARM CPU,2G ram,Ubuntu版本:
root@ubuntu:/# cat /proc/cpuinfo
processor : 0
BogoMIPS : 48.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 1
BogoMIPS : 48.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 2
BogoMIPS : 48.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 3
BogoMIPS : 48.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
root@ubuntu:/# cat /proc/meminfo
MemTotal: 2034836 kB
MemFree: 1390424 kB
MemAvailable: 1601456 kB
Buffers: 12956 kB
Cached: 197056 kB
SwapCached: 0 kB
Active: 146292 kB
Inactive: 95948 kB
Active(anon): 34232 kB
Inactive(anon): 568 kB
Active(file): 112060 kB
Inactive(file): 95380 kB
Unevictable: 1940 kB
Mlocked: 1940 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 960 kB
Writeback: 0 kB
AnonPages: 34160 kB
Mapped: 54596 kB
Shmem: 968 kB
Slab: 63184 kB
SReclaimable: 22708 kB
SUnreclaim: 40476 kB
KernelStack: 1984 kB
PageTables: 1176 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1017416 kB
Committed_AS: 195836 kB
VmallocTotal: 263061440 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
CmaTotal: 704512 kB
CmaFree: 389040 kB
root@ubuntu:/# uname -a
Linux ubuntu 4.14.87 #3 SMP PREEMPT Thu Aug 11 17:43:44 CST 2022 aarch64 aarch64 aarch64 GNU/Linux
wifi配置好网络后,eth0是RJ45口,wlan0是无线。
root@ubuntu:# ifconfig
eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
ether 00:11:22:e3:75:58 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 43 base 0xa000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 2 bytes 176 (176.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 176 (176.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.43.188 netmask 255.255.255.0 broadcast 192.168.43.255
inet6 240e:472:2530:125:a3bd:f5ff:1329:8c6 prefixlen 64 scopeid 0x0<global>
inet6 fe80::d6e:5fae:2948:2a4a prefixlen 64 scopeid 0x20<link>
inet6 240e:472:2530:125:e8b1:c9ec:82ca:2dcb prefixlen 64 scopeid 0x0<global>
ether 08:e9:f6:ae:7b:ac txqueuelen 1000 (Ethernet)
RX packets 54 bytes 4958 (4.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 53 bytes 6362 (6.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
发热量还可以,因为在空调房:
root@ubuntu:/# hrut_somstatus
=====================1=====================
temperature-->
CPU : 48.9 (C)
cpu frequency-->
-e min cur max
-e cpu0: 240000 1000000 1200000
-e cpu1: 240000 1000000 1200000
-e cpu2: 240000 500000 1200000
-e cpu3: 240000 500000 1200000
bpu status information---->
-e min cur max ratio
-e bpu0: 400000000 1000000000 1000000000 0
-e bpu1: 400000000 1000000000 1000000000 0
二、工具介绍
5TOPS的算力,相应的的案例都放在/app/ai_inference目录中,models文件夹下面有5个模型,分别是:fcos_512x512_nv12.bin、mobilenet_unet_1024x2048_nv12.bin、mobilenetv1_224x224_nv12.bin、yolov3_darknet53_416x416_nv12.bin和yolov5s_672x672_nv12.bin,由文件名可以看得出,fcos是目标检测,mobilenetv1图像分类,mobilenet_unet图像分割……
因为用的是USB摄像头,所以选择了02_usb_camera_sample的案例,先来一个跑起来:
python3 usb_camera_fcos.py
要求接上HDMI显示器,具体就是检测摄像头中的物体,代码太长不介绍,识别率还可以,就是一个Google Android机器人被识别成瓶子了,估计圆滚滚的缘故吧。

这个案例的代码有点长,还有个简单点的,usb_camera_snap.py,顾名思义,就是抓拍摄像头照片,源码如下,很简单:
#!/usr/bin/env python3
import numpy as np
import cv2
if __name__ == '__main__':
# 打开 usb camera: /dev/video8
cap = cv2.VideoCapture(8)
if(not cap.isOpened()):
exit(-1)
print("Open usb camera successfully")
# 设置usb camera的输出图像格式为 MJPEG, 分辨率 1920 x 1080
codec = cv2.VideoWriter_fourcc( 'M', 'J', 'P', 'G' )
cap.set(cv2.CAP_PROP_FOURCC, codec)
cap.set(cv2.CAP_PROP_FPS, 30)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
_ ,frame = cap.read()
# print(frame.shape)
if frame is None:
print("Failed to get image from usb camera")
cv2.imwrite("imf.jpg", frame)
执行后生成一张imf.jpg文件,可是我想看看怎么办,弄到HDMI显示器上显示起来,反正hobot_vio提供,于是加了几行。
#!/usr/bin/env python3
import sys, os, time
import numpy as np
from hobot_vio import libsrcampy
import cv2
if __name__ == '__main__':
# 打开 usb camera: /dev/video8
cap = cv2.VideoCapture(8)
if(not cap.isOpened()):
exit(-1)
print("Open usb camera successfully")
# 设置usb camera的输出图像格式为 MJPEG, 分辨率 1920 x 1080
codec = cv2.VideoWriter_fourcc( 'M', 'J', 'P', 'G' )
cap.set(cv2.CAP_PROP_FOURCC, codec)
cap.set(cv2.CAP_PROP_FPS, 30)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
_ ,frame = cap.read()
# print(frame.shape)
if frame is None:
print("Failed to get image from usb camera")
cv2.imwrite("imf.jpg", frame)
time.sleep(1)
disp = libsrcampy.Display()
disp.display(0, 1920, 1080, 0, 1)
fo = open("imf.jpg", "rb")
img = fo.read()
fo.close()
disp.set_img(img)
time.sleep(10)
disp.close()
感谢专业的库,代码执行后显示器能显示抓拍的图片。??
*调试的过程中,有点不稳定,刚开始完全不能显示,后来重启几次才好。
三、下一步工作
1、安装天工开物open Explorer工具链,练习使用BPU;
2、部署深度学习模型,跑一个图像识别场景。
感谢阅读