1.前言
? V853 芯片內(nèi)置一顆 NPU核,其處理性能為最大 1 TOPS 并有 128KB 內(nèi)部高速緩存用于高速數(shù)據(jù)交換,支持 OpenCL、OpenVX、android NN 與 ONNX 的 API 調(diào)用,同時(shí)也支持導(dǎo)入大量常用的深度學(xué)習(xí)模型。本章提供一個(gè)例程,展示如何使用V853芯片中的NPU部分進(jìn)行人形檢測(cè)和人臉識(shí)別。
資源包(含有應(yīng)用程序和yuvplayer軟件包):source.zip
100ASK_V853-PRO開(kāi)發(fā)板資料匯總:
鏈接:100ASK_100ASK-PRO 資料匯總 - Allwinner / V853-Pro - 嵌入式開(kāi)發(fā)問(wèn)答社區(qū)
100ASK_V853-PRO開(kāi)發(fā)板購(gòu)買(mǎi)鏈接:100ASK_V853-PRO開(kāi)發(fā)板
2.示例程序目錄
將上述資源包下載完成解壓后,把示例程序100ASK_viplite-driver
放在Ubuntu中的任意目錄中。假設(shè)我放在/home/book/workspaces目錄下,下面為人形識(shí)別和人臉識(shí)別應(yīng)用程序的目錄結(jié)構(gòu)。
book@100ask:~/workspaces/100ASK_viplite-driver$ tree
.
├── 100ASK_Algo
│ ├── det_demo
│ │ ├── 100ASK_det_demo
│ │ ├── aw_errors.c
│ │ ├── aw_errors.h
│ │ ├── body_384x216.yuv
│ │ ├── body_640x360.yuv
│ │ ├── demo.cc
│ │ ├── face_480x270.nv12
│ │ ├── list.c
│ │ ├── list.h
│ │ ├── Makefile
│ │ ├── Readme.txt
│ │ └── testcase.txt
│ ├── fdet
│ │ └── 100ASK_Facedet_480_288_nv12.nb
│ ├── include
│ │ ├── awnn_det.h
│ │ ├── awnn.h
│ │ ├── awnn_info.h
│ │ ├── awnn_lib.h
│ │ └── cross_utils.h
│ ├── libawnn.a
│ ├── libawnn.so
│ ├── pdet
│ │ ├── 100ASK_humandet_384_224_V0.nb
│ │ ├── 100ASK_humandet_384_224_V1.nb
│ │ ├── 100ASK_humandet_640_384_V0.nb
│ │ └── 100ASK_humandet_640_384_V1.nb
│ └── Readme.txt
└── sdk_release
├── libVIPlite.a
├── libVIPlite.so
├── libVIPuser.a
├── libVIPuser.so
└── sdk
├── vip_lite_common.h
└── vip_lite.h
7 directories, 31 files
其中100ASK_Algo文件包含了:
? 1.det_demo目錄包含應(yīng)用程序和測(cè)試圖片
? 2.fdet目錄包含人臉模型
? 3.include目錄包含應(yīng)用程序頭文件和
? 4.pdet目錄包含人形模型
sdk_release中包含了NPU相關(guān)的模型處理文件
3.主函數(shù)demo.cc
下面僅對(duì)應(yīng)用程序中的demo.cc程序中的main.cc進(jìn)行講解,對(duì)于其他代碼,您可以直接查看應(yīng)用程序壓縮包的其他文件。
int main(int argc, char* argv[]) {
if (argc != 2) {
printf("%s testcase.txtn", argv[0]);
return 0;
}
int count = 0;
/*創(chuàng)建一個(gè)結(jié)構(gòu)體獲取參數(shù)1的中的數(shù)據(jù),該結(jié)構(gòu)體是輸入nbg路徑,返回awnn_info_t結(jié)構(gòu)體。包含庫(kù)名稱,網(wǎng)絡(luò)輸入圖像寬高,內(nèi)存占用大小,閾值信息等,其中count為處理的圖像和網(wǎng)絡(luò)模型個(gè)數(shù)*/
network_info_t **infos = create_infos_from_testcase(argv[1], count);
printf("count=%dn", count);
if (count && infos) {
awnn_info_t * nbinfo;
unsigned int mem_size = 0;
pthread_t thread[count] = {0};
//獲取參數(shù)1獲取對(duì)應(yīng)模型個(gè)數(shù)
for (int i = 0; i < count; i++) {
nbinfo = awnn_get_info(infos[i]->nbg);
printf("info %s %s %u %u %u %fn", nbinfo->name, nbinfo->md5,
nbinfo->width, nbinfo->height, nbinfo->mem_size, nbinfo->thresh);
infos[i]->nbinfo = nbinfo;
mem_size += nbinfo->mem_size;
}
//根據(jù)內(nèi)存初始化申請(qǐng)NPU模型所需的內(nèi)存大小
printf("mem_size: %un", mem_size);
awnn_init(mem_size);
//創(chuàng)建線程處理模型和圖片
for (int i = 0; i < count; i++) {
pthread_create(&thread[i], NULL, detect_thread, infos[i]);
}
for (int i = 0; i < count; i++) {
if (thread[i] != 0)
pthread_join(thread[i], NULL);
}
awnn_uninit();
}
//銷毀結(jié)構(gòu)體內(nèi)存
destroy_infos(infos, count);
return 0;
}
可以看到上述過(guò)程并沒(méi)有涉及到模型的處理過(guò)程,可以查看100ASK_viplite-driver/100ASK_Algo/include/目錄中對(duì)應(yīng)函數(shù)的函數(shù)說(shuō)明。
4.編譯應(yīng)用程序
假設(shè)我將應(yīng)用程序文件夾100ASK_viplite-driver放在~/workspaces/100ASK_viplite-driver,進(jìn)入應(yīng)用程序目錄下
book@100ask:~$ cd ~/workspaces/100ASK_viplite-driver/
book@100ask:~/workspaces/100ASK_viplite-driver$ cd 100ASK_Algo/det_demo/
假設(shè)我的Tina SDK放在/home/book/workspaces/tina-v853-open
,為應(yīng)用程序增加環(huán)境變量。
book@100ask:~/workspaces/100ASK_viplite-driver/100ASK_Algo/det_demo$ export TINA_TOP=/home/book/workspaces/tina-v853-open
book@100ask:~/workspaces/100ASK_viplite-driver/100ASK_Algo/det_demo$ export STAGING_DIR=~/workspaces/tina-v853-open/openwrt/openwrt/staging_dir/
添加完成后即可編譯應(yīng)用程序
book@100ask:~/workspaces/100ASK_viplite-driver/100ASK_Algo/det_demo$ make
/home/book/workspaces/tina-v853-open/prebuilt/rootfsbuilt/arm/toolchain-sunxi-musl-gcc-830/toolchain/bin/arm-openwrt-linux-muslgnueabi-g++ demo.cc list.c aw_errors.c -I./ -I./../../100ASK_Algo/include -L./../../100ASK_Algo -L./../../sdk_release -l:libawnn.a -l:libVIPlite.a -l:libVIPuser.a -o 100ASK_det_demo
book@100ask:~/workspaces/100ASK_viplite-driver/100ASK_Algo/det_demo$ ls
100ASK_det_demo aw_errors.h body_640x360.yuv face_480x270.nv12 list.h Readme.txt
aw_errors.c body_384x216.yuv demo.cc list.c Makefile testcase.txt
編譯完成后,可以在當(dāng)前目錄下生成一個(gè)名為100ASK_det_demo的應(yīng)用程序。
5.修改testcase.txt
? testcase.txt文件里面包含有模型路徑、待檢測(cè)的圖像、圖像尺寸。下面對(duì)該文件進(jìn)行詳細(xì)的解讀,testcase.txt原文件為:
# example:
# [network]
# network type thresh loop
# input1 width height
# input2 width height
# input3 width height
#
# network: nbg path
# type: 1(humanoidv1.0),3(humanoidv3.0),4(face)
# thresh: postprocess thresh
# loop: loop count
# input: multi test case each in oneline
[network]
models/100ASK_humandet_640_384_V1.nb 1 0.25 1
body_640x360.yuv 640 360
[network]
models/100ASK_humandet_384_224_V1.nb 3 0.25 1
body_384x216.yuv 384 216
[network]
models/100ASK_Facedet_480_288_nv12.nb 4 0.6 1
face_480x270.nv12 480 270
可以看到文件已經(jīng)對(duì)該文件如何使用和網(wǎng)絡(luò)節(jié)點(diǎn)的各參數(shù)定義有了解釋。testcase.txt文件中可以包含有多個(gè)處理的模型,每個(gè)需要處理的模型需要有特定的格式要求,假設(shè)我現(xiàn)在使用的是100ASK_humandet_640_384_V1.nb模型文件處理test1_640x360.yuv的圖像文件,則可以修改testcase.txt文件為
[network]
models/100ASK_humandet_640_384_V1.nb 1 0.25 1
test1_640x360.yuv 640 360
models/100ASK_humandet_640_384_V1.nb
為模型的存放路徑;1
為模型的類別;0.25
為后處理閾值;1
為循環(huán)次數(shù);test1_640x360.yuv
為測(cè)試圖像的名稱;640 360
為測(cè)試圖像的尺寸。
**注意:**100ASK_humandet_640_384_V1.nb為類別1,100ASK_humandet_384_224_V1.nb為類別3。
如果你還想使用同一個(gè)模型,增加一個(gè)test2_640x360.yuv
測(cè)試圖像,可以直接在該模型下增加
test2_640x360.yuv
測(cè)試圖像和圖像尺寸,例如:
[network]
models/100ASK_humandet_640_384_V1.nb 1 0.25 1
test1_640x360.yuv 640 360
test2_640x360.yuv 640 360
6.運(yùn)行測(cè)試程序
? 我們?cè)谑纠绦蛑幸呀?jīng)放入供您進(jìn)行測(cè)試使用的圖像,您也可以使用TF卡將虛擬機(jī)中的應(yīng)用程序、模型和測(cè)試圖像等文件拷貝到TF卡中 ,TF卡中的文件結(jié)構(gòu)應(yīng)如下所示
book@100ask:/media/book/B89C-7C55$ tree
.
├── 100ASK_det_demo
├── body_384x216.yuv
├── body_640x360.yuv
├── face_480x270.nv12
├── models
│ ├── 100ASK_Facedet_480_288_nv12.nb
│ ├── 100ASK_humandet_384_224_V1.nb
│ └── 100ASK_humandet_640_384_V1.nb
└── testcase.txt
可以看到應(yīng)用程序、測(cè)試圖片和testcase.txt文件放在TF卡根目錄的文件夾下,單獨(dú)創(chuàng)建一個(gè)models文件夾將模型文件放在該文件夾下。
? 將開(kāi)發(fā)板板上電,插入12V電源線和2條Type-C數(shù)據(jù)線后,再將TF卡插入開(kāi)發(fā)板中
? 啟動(dòng)完成開(kāi)發(fā)板后,掛載TF卡到/mnt目錄下,輸入mount /dev/mmcblk1p1 /mnt/
root@TinaLinux:/# [ 9866.263682] sunxi-mmc sdc0: sdc set ios:clk 0Hz bm PP pm UP vdd 22 width 1 timing LEGACY(SDR12) dt B
[ 9866.523742] sunxi-mmc sdc0: no vqmmc,Check if there is regulator
[ 9866.553676] sunxi-mmc sdc0: sdc set ios:clk 400000Hz bm PP pm ON vdd 22 width 1 timing LEGACY(SDR12) dt B
[ 9866.593686] sunxi-mmc sdc0: sdc set ios:clk 400000Hz bm PP pm ON vdd 22 width 1 timing LEGACY(SDR12) dt B
[ 9866.606971] sunxi-mmc sdc0: sdc set ios:clk 400000Hz bm PP pm ON vdd 22 width 1 timing LEGACY(SDR12) dt B
[ 9866.619855] sunxi-mmc sdc0: sdc set ios:clk 400000Hz bm PP pm ON vdd 22 width 1 timing LEGACY(SDR12) dt B
[ 9866.633161] sunxi-mmc sdc0: sdc set ios:clk 400000Hz bm PP pm ON vdd 22 width 1 timing LEGACY(SDR12) dt B
[ 9866.855649] sunxi-mmc sdc0: sdc set ios:clk 0Hz bm PP pm ON vdd 22 width 1 timing LEGACY(SDR12) dt B
[ 9866.866027] sunxi-mmc sdc0: no vqmmc,Check if there is regulator
[ 9866.893675] sunxi-mmc sdc0: sdc set ios:clk 400000Hz bm PP pm ON vdd 22 width 1 timing LEGACY(SDR12) dt B
[ 9866.914333] mmc1: host does not support reading read-only switch, assuming write-enable
[ 9866.924044] sunxi-mmc sdc0: sdc set ios:clk 400000Hz bm PP pm ON vdd 22 width 4 timing LEGACY(SDR12) dt B
[ 9866.938320] sunxi-mmc sdc0: sdc set ios:clk 400000Hz bm PP pm ON vdd 22 width 4 timing UHS-DDR50 dt B
[ 9866.948838] sunxi-mmc sdc0: sdc set ios:clk 50000000Hz bm PP pm ON vdd 22 width 4 timing UHS-DDR50 dt B
[ 9866.959640] mmc1: new ultra high speed DDR50 SDHC card at address aaaa
[ 9866.967694] mmcblk1: mmc1:aaaa SU08G 7.40 GiB
[ 9866.990824] mmcblk1: p1
root@TinaLinux:/# mount /dev/mmcblk1p1 /mnt/
[ 3573.953864] FAT-fs (mmcblk1p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
進(jìn)入mnt目錄下即可看到TF卡內(nèi)的文件
root@TinaLinux:/# cd /mnt/
root@TinaLinux:/mnt# ls
100ASK_det_demo face_480x270.nv12
System Volume Information models
body_384x216.yuv testcase.txt
body_640x360.yuv
root@TinaLinux:/mnt# ls models/
100ASK_Facedet_480_288_nv12.nb 100ASK_humandet_640_384_V1.nb
100ASK_humandet_384_224_V1.nb
確保應(yīng)用程序、模型文件夾中的模型文件、測(cè)試圖片、testcase.txt都存在后,即可開(kāi)始運(yùn)行測(cè)試程序,輸入
./100ASK_det_demo testcase.txt
root@TinaLinux:/mnt# ./100ASK_det_demo testcase.txt
count=3
info 05dc32ee903c08a3abd53ddd829a8dd5 640 384 10061394 0.000000
info 827b3a725d0fd7173338a56fd06c8db0 384 224 2829624 0.000000
info 3d42fcd47490a62d52ea021760[ 7944.592701] npu[665][665] vipcore, device init..
[ 7944.600170] set_vip_power_clk ON
mem_size: 16530637
Version: AW[ 7944.608597] enter aw vip mem alloc size 16530637
NN_LIB_1.0.3
[0xb6f8f560]vip_in[ 7944.615697] aw_vip_mem_alloc vir 0xe1328000, phy 0x48800000
it[121],
The version of Viplit[ 7944.623477] npu[665][665] gckvip_drv_init kernel logical phy address=0x48800000 virtual =0xe1328000
e is: 1.8.0-0-AW-2023-02-24
VIPLite driver version=0x00010800...
malloc 384x224 nv12 buffer
malloc 480x288 nv12 buffer
malloc 640x384 nv12 buffer
save file: post_body_384x216.yuv
save file: post_face_480x270.nv12
save file: post_body_640x360.yuv
[ 7946.373546] npu[665][665] gckvip_drv_exit, aw_vip_mem_free
[ 7946.379816] aw_vip_mem_free vir 0xe1328000, phy 0x48800000
[ 7946.386027] aw_vip_mem_free dma_unmap_sg_atrs
[ 7946.391003] aw_vip_mem_free ion_unmap_kernel
[ 7946.396101] aw_vip_mem_free ion_free
[ 7946.400118] aw_vip_mem_free ion_client_destroy
[ 7946.410983] npu[665][665] vipcore, device un-init..
執(zhí)行測(cè)試程序完成后可以查看當(dāng)前目錄下的文件,輸入ls
root@TinaLinux:/mnt# ls
100ASK_det_demo post_body_640x360.yuv.input_0.txt
System Volume Information post_body_640x360.yuv.input_1.txt
body_384x216.yuv post_body_640x360.yuv.output_0.txt
body_640x360.yuv post_data
face_480x270.nv12 post_face_480x270.nv12
models post_face_480x270.nv12.input_0.txt
post_body_384x216.yuv post_face_480x270.nv12.input_1.txt
post_body_384x216.yuv.input_0.txt post_face_480x270.nv12.output_0.txt
post_body_384x216.yuv.input_1.txt post_face_480x270.nv12.output_1.txt
post_body_384x216.yuv.output_0.txt post_face_480x270.nv12.output_2.txt
post_body_384x216.yuv.output_1.txt testcase.txt
post_body_640x360.yuv
上述文件中,帶有post前綴的文件為執(zhí)行應(yīng)用程序后生成的文件。其中post_data文件夾含有模型的執(zhí)行結(jié)果和執(zhí)行性能
post_data/result_TID.txt :輸出每個(gè)模型檢測(cè)結(jié)果,其中 TID 為檢測(cè)線程ID號(hào)。
post_data/performance_TID.txt :輸出每個(gè)模型檢測(cè)性能結(jié)果,其中 TID 為檢測(cè)線程ID號(hào);性能評(píng)測(cè)時(shí)建議運(yùn)行單個(gè)模型且將 stdout 重定向?yàn)?/dev/null 。
post_inputN :每個(gè)輸入的畫(huà)框結(jié)果,其中 inputN 為輸入圖像路徑,直接在路徑前添加 post_前綴進(jìn)行保存,因此輸入圖像路徑請(qǐng)勿添加 ./ 或使用絕對(duì)路徑。
post_body_384x216.yuv
、post_body_640x360.yuv
、post_face_480x270.nv12
為輸出畫(huà)框結(jié)果的圖像。
卸載TF卡所用的文件系統(tǒng),輸入
root@TinaLinux:/mnt# cd ../
root@TinaLinux:/# umount /mnt/
7.使用yuvplayer軟件查看圖像
將TF卡放入讀卡器后,插入電腦端,使用yuvplayer軟件打開(kāi)圖像,該文件放在source目錄下的yuvplayer-2.5.zip,解壓后即可使用。設(shè)置圖像尺寸和顏色空間即可查看圖像。
在電腦端,打開(kāi)U盤(pán)文件夾。注意:您之前沒(méi)使用過(guò)yuvplayer.exe,可能不會(huì)出現(xiàn)我的.nv12文件一樣的圖標(biāo),但不影響后續(xù)的操作。
選擇我們需要查看的圖像,例如我想查看body_640x360.yuv
文件,單擊body_640x360.yuv
文件后,右鍵后選擇打開(kāi)方式。
點(diǎn)擊更多應(yīng)用
使用滾輪往下滑,點(diǎn)擊在這臺(tái)電腦上查找其他應(yīng)用
找到y(tǒng)uvplayer-2.5.zip解壓出來(lái)的yuvplayer-2.5文件夾中的yuvplayer.exe文件,選中該文件后點(diǎn)擊打開(kāi)
打開(kāi)后,會(huì)出現(xiàn)如下畫(huà)面,該畫(huà)面是由于沒(méi)有設(shè)置尺寸和顏色空間導(dǎo)致的
在選項(xiàng)欄中點(diǎn)擊Size后,選擇Custom。這樣的選擇意思是選擇自定義尺寸
在自定義尺寸界面輸入圖像尺寸,該圖像尺寸寬為640,高為360,設(shè)置完成后點(diǎn)擊確定
確定完成之后可以,看到大致的圖像,但此時(shí)還需要修改顯示的圖像空間。
在選項(xiàng)欄中點(diǎn)擊選擇Color后,點(diǎn)擊選擇NV12顏色空間
選擇完成后,即可看到正常的圖像
其他圖像的查看方式也同理,值得注意的是每張圖像的尺寸可能不一樣,需要根據(jù)源圖像的尺寸設(shè)置。
使用yuvplayer查看post_face_480x270.nv12
圖像文件為:
7.使用自定義圖片測(cè)試
? 由于我們平常使用的圖片格式多為JPG或者PNG格式,其圖像數(shù)據(jù)格式都為RGB等常見(jiàn)顏色空間,但在視頻編解碼和視頻傳輸應(yīng)用中通常使用NV12的視頻存儲(chǔ)格式,它將圖片中 Y 軸色度信息和 UV 軸亞像素信息存儲(chǔ)在同一個(gè)平面中。這就導(dǎo)致在 NV12 格式中,圖像的每一行都存儲(chǔ)一個(gè) Y 值(代表色度信息),然后每隔兩行存儲(chǔ)一個(gè) U 和 V 值(代表亞像素信息)。所以NV12 格式中的圖像數(shù)據(jù)通常會(huì)比其他格式(如 RGB)少一半。
? 如果您獲取的應(yīng)用的圖像為NV12就不需要進(jìn)行格式轉(zhuǎn)換,如果您想測(cè)試的圖像為并不是NV12格式,而是我們常見(jiàn)的RGB格式的JPG或PNG圖像,則需要使用工具進(jìn)行轉(zhuǎn)換。
? 下面我們使用的工具是ffmpeg
,下面演示如何使用ffmpeg
進(jìn)行圖像存儲(chǔ)格式的轉(zhuǎn)換。
? 安裝ffmpeg
,在虛擬機(jī)終端界面輸入sudo apt-get install ffmpeg
book@100ask:~$ sudo apt-get install ffmpeg
[sudo] password for book:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libdumbnet1
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
i965-va-driver libaacs0 libass9 libavcodec57 libavdevice57 libavfilter6
libavformat57 libavresample3 libavutil55 libbdplus0 libbluray2 libbs2b0
libchromaprint1 libcrystalhd3 libdc1394-22 libflite1 libgme0 libgsm1
libllvm10 libmysofa0 libnorm1 libopenal-data libopenal1 libopenjp2-7
libopenmpt0 libpgm-5.2-0 libpostproc54 librubberband2 libsdl2-2.0-0
libshine3 libsnappy1v5 libsndio6.1 libsoxr0 libssh-gcrypt-4 libswresample2
libswscale4 libva-drm2 libva-x11-2 libva2 libvdpau1 libx264-152 libx265-146
libxvidcore4 libzmq5 libzvbi-common libzvbi0 mesa-va-drivers
mesa-vdpau-drivers va-driver-all vdpau-driver-all
Suggested packages:
ffmpeg-doc i965-va-driver-shaders libbluray-bdj firmware-crystalhd
libportaudio2 sndiod libvdpau-va-gl1 nvidia-vdpau-driver
nvidia-legacy-340xx-vdpau-driver
The following NEW packages will be installed:
ffmpeg i965-va-driver libaacs0 libass9 libavcodec57 libavdevice57
libavfilter6 libavformat57 libavresample3 libavutil55 libbdplus0 libbluray2
libbs2b0 libchromaprint1 libcrystalhd3 libdc1394-22 libflite1 libgme0
libgsm1 libllvm10 libmysofa0 libnorm1 libopenal-data libopenal1 libopenjp2-7
libopenmpt0 libpgm-5.2-0 libpostproc54 librubberband2 libsdl2-2.0-0
libshine3 libsnappy1v5 libsndio6.1 libsoxr0 libssh-gcrypt-4 libswresample2
libswscale4 libva-drm2 libva-x11-2 libva2 libvdpau1 libx264-152 libx265-146
libxvidcore4 libzmq5 libzvbi-common libzvbi0 mesa-va-drivers
mesa-vdpau-drivers va-driver-all vdpau-driver-all
0 upgraded, 51 newly installed, 0 to remove and 242 not upgraded.
Need to get 32.5 MB/47.9 MB of archives.
After this operation, 222 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
此時(shí)會(huì)提示您將有222M空間需要被使用,此時(shí)輸入y
,即可進(jìn)行下載安裝
等待安裝完成后,輸入ffmpeg -h
book@100ask:~$ ffmpeg -h
ffmpeg version 3.4.11-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
...
可以看到ffmpeg
的版本號(hào)和適用的Ubuntu,后續(xù)的使用指南可自行觀看,這里就不展示全部輸出信息。
下面我們使用《RISC-V嵌入式開(kāi)發(fā)線下交流會(huì)》中的照片,尺寸為480×270
,圖像格式為JPG
book@100ask:~/workspaces/testImg$ ls
test_480-270.jpg
使用ffmpeg
進(jìn)行格式轉(zhuǎn)換,在終端輸入ffmpeg -i test_480-270.jpg -s 480x288 -pix_fmt nv12 100ask_face-480-270.yuv
book@100ask:~/workspaces/testImg$ ffmpeg -i test_480-270.jpg -s 480x270 -pix_fmt nv12 100ask_face-480-270.yuv
ffmpeg version 3.4.11-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, image2, from 'test_480-270.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 5699 kb/s
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 480x270 [SAR 96:96 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native))
Press [q] to stop, [?] for help
[swscaler @ 0x55787ff64b20] deprecated pixel format used, make sure you did set range correctly
Output #0, rawvideo, to '100ask_face-480-270.yuv':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Video: rawvideo (NV12 / 0x3231564E), nv12, 480x270 [SAR 1:1 DAR 16:9], q=2-31, 38880 kb/s, 25 fps, 25 tbn, 25 tbc
Metadata:
encoder : Lavc57.107.100 rawvideo
frame= 1 fps=0.0 q=-0.0 Lsize= 190kB time=00:00:00.04 bitrate=38880.0kbits/s speed=0.664x
video:190kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
執(zhí)行完成沒(méi)有出現(xiàn)報(bào)錯(cuò),并可以輸入ls
查看轉(zhuǎn)換后的圖像文件
book@100ask:~/workspaces/testImg$ ls
test_480-270.jpg 100ask_face-480-270.yuv
可以發(fā)現(xiàn)生成了一個(gè)名為100ask_face-480-270.yuv
文件,該文件的圖像尺寸為480×270
,圖像存儲(chǔ)格式為NV12。
將其拷貝到開(kāi)發(fā)板上,與應(yīng)用程序100ASK_det_demo放在同一目錄中,例如:
root@TinaLinux:/mnt# ls
100ASK_det_demo
100ask_face-480-270.yuv
System Volume Information
body_384x216.yuv
body_640x360.yuv
face_480x270.nv12
models
post_100ask_face-480_288.yuv.input_0.txt
post_100ask_face-480_288.yuv.input_1.txt
post_100ask_face-480_288.yuv.output_0.txt
post_100ask_face-480_288.yuv.output_1.txt
post_100ask_face-480_288.yuv.output_2.txt
post_body_384x216.yuv
post_body_384x216.yuv.input_0.txt
post_body_384x216.yuv.input_1.txt
post_body_384x216.yuv.output_0.txt
post_body_384x216.yuv.output_1.txt
post_body_640x360.yuv
post_body_640x360.yuv.input_0.txt
post_body_640x360.yuv.input_1.txt
post_body_640x360.yuv.output_0.txt
post_data
post_face_480x270.nv12
post_face_480x270.nv12.input_0.txt
post_face_480x270.nv12.input_1.txt
post_face_480x270.nv12.output_0.txt
post_face_480x270.nv12.output_1.txt
post_face_480x270.nv12.output_2.txt
testcase.txt
修改testcase.txt,增加人臉模型的輸入圖像,在串口終端輸入
root@TinaLinux:/mnt# vi testcase.txt
修改文件內(nèi)容為:
# example:
# [network]
# network type thresh loop
# input1 width height
# input2 width height
# input3 width height
#
# network: nbg path
# type: 1(humanoidv1.0),3(humanoidv3.0),4(face)
# thresh: postprocess thresh
# loop: loop count
# input: multi test case each in oneline
[network]
models/100ASK_humandet_640_384_V1.nb 1 0.25 1
body_640x360.yuv 640 360
[network]
models/100ASK_humandet_384_224_V1.nb 3 0.25 1
body_384x216.yuv 384 216
[network]
models/100ASK_Facedet_480_288_nv12.nb 4 0.6 1
face_480x270.nv12 480 270
100ask_face-480-270.yuv 480 270
運(yùn)行100ASK_det_demo
應(yīng)用程序
root@TinaLinux:/mnt# ./100ASK_det_demo testcase.txt
count=3
info 05dc32ee903c08a3abd53ddd829a8dd5 640 384 10061394 0.000000
info 827b3a725d0fd7173338a56fd06c8db0 384 224 2829624 0.000000
info 3d42fcd47490a62d52ea021760[ 212.538113] npu[465][465] vipcore, device init..
[ 212.545449] set_vip_power_clk ON
mem_size: 16530637
Version: AW[ 212.553935] enter aw vip mem alloc size 16530637
NN_LIB_1.0.3
[0xb6fe0560]vip_init[121],
The version of Viplite is: 1.8.0-0-AW-2023-02-24
[ 212.569158] aw_vip_mem_alloc vir 0xe1353000, phy 0x48800000
[ 212.575548] npu[465][465] gckvip_drv_init kernel logical phy address=0x48800000 virtual =0xe1353000
VIPLite driver version=0x00010800...
malloc 480x288 nv12 buffer
malloc 384x224 nv12 buffer
malloc 640x384 nv12 buffer
save file: post_body_384x216.yuv
save file: post_face_480x270.nv12
save file: post_body_640x360.yuv
save file: post_100ask_face-480-270.yuv
[ 215.019076] npu[465][465] gckvip_drv_exit, aw_vip_mem_free
[ 215.025231] aw_vip_mem_free vir 0xe1353000, phy 0x48800000
[ 215.031525] aw_vip_mem_free dma_unmap_sg_atrs
[ 215.036451] aw_vip_mem_free ion_unmap_kernel
[ 215.041627] aw_vip_mem_free ion_free
[ 215.045646] aw_vip_mem_free ion_client_destroy
[ 215.051785] npu[465][465] vipcore, device un-init..
使用yuvplayer軟件查看圖像,配置圖像的尺寸:寬480、高270;配置圖像顏色空間為NV12
可以看到該模型已經(jīng)檢測(cè)到大部分人臉模型,可能由于圖像過(guò)于模糊導(dǎo)致有個(gè)別未能識(shí)別到,但該模型的精度還是比較高的。這里僅演示人臉識(shí)別,對(duì)于人形識(shí)別大家也可以參考這個(gè)示例自行去修改增加。參考這個(gè)示例大家可以去自己嘗試獲取自定義的圖像進(jìn)行人臉識(shí)別或人形檢測(cè)。
-
芯片
+關(guān)注
關(guān)注
453文章
50248瀏覽量
421104 -
Linux
+關(guān)注
關(guān)注
87文章
11213瀏覽量
208736 -
AI
+關(guān)注
關(guān)注
87文章
29849瀏覽量
268150 -
開(kāi)發(fā)板
+關(guān)注
關(guān)注
25文章
4909瀏覽量
97080 -
人臉識(shí)別
+關(guān)注
關(guān)注
76文章
4003瀏覽量
81688
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論