200DK有兩個攝像頭的接口,早在兩年前,張小白就在早期CANN版本中試過攝像頭:
https://link.zhihu.com/?target=https%3A//bbs.huaweicloud.com/blogs/194291
當然也要注意里面的坑,比如說接口中排線的方向等等。
我們下面看看,在CANN 5.0.4 alpha005的版本對攝像頭的支持如何:
cd samples/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera
mkdir -p build/intermediates/host
cd build/intermediates/host
cmake ../../../src -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_SKIP_RPATH=TRUE
make
cd $HOME/samples/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera/out
mkdir output
攝像頭1:
./main -i -c 1 -o ./output/filename.jpg --overwrite
攝像頭0:
./main -i -c 0 -o ./output/filename0.jpg --overwrite
從宿主機將結(jié)果文件拷貝回來:
mkdir camera
cd camera
scp HwHiAiUser@192.168.1.2:~/samples/cplusplus
/level1_single_api/5_200dk_peripheral/ascendcamera/out/output/*.jpg .
打開看看:
說明這兩個攝像頭拍照都沒(太大的)問題。(盡管這個帶夜視的廉價攝像頭是一如既往的發(fā)紅。。)
執(zhí)行以下腳本下載caffe模型,并轉(zhuǎn)換為om模型:
cd ${HOME}/samples/cplusplus/level2_simple_inference/2_object_detection/face_detection_camera/model
wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE
/ATC%20Model/facedection/face_detection_fp32.caffemodel
wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE
/ATC%20Model/facedection/face_detection.prototxt
wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models
/face_detection_camera/insert_op.cfg
atc --output_type=FP32 --input_shape="data:1,3,300,300" --weight=./face_detection_fp32.caffemodel --input_format=NCHW --output=./face_detection --soc_version=Ascend310 --insert_op_conf=./insert_op.cfg --framework=0 --save_original_model=false --model=./face_detection.prototxt
編譯:
cd ~/samples/cplusplus/level2_simple_inference/2_object_detection/face_detection_camera/scripts
bash ./sample_build.sh
運行:
bash sample_run.sh
具體報錯如下:
HwHiAiUser@davinci-mini:~/samples/cplusplus/level2_simple_inference/2_object_detection/face_detection_camera/scripts$ bash sample_run.sh
[INFO] The sample starts to run
Current environment valid ip list:
127.0.0.1
192.168.199.204
Please choose one to show the presenter in browser:192.168.199.204
[INFO] Acl init ok
[INFO] Open device 0 ok
[INFO] Use default context currently
content_type config string:1
[INFO] dvpp init resource ok
[INFO] Load model ../model/face_detection.om success
[INFO] Create model description success
[INFO] Create model(../model/face_detection.om) output success
[INFO] Init model ../model/face_detection.om success
[INFO] No specified carmera id, use camera0
[ERROR] Set camera fps failed
[ERROR] Set camera0 property failed
[ERROR] Open camera failed
[2022-04-23 18:24:44][LIBMEDIA_ERROR] CloseCamera failed!!! Camera[0] is not opened
[ERROR] Close camera 0 failed
[INFO] Unload model ../model/face_detection.om success
[INFO] destroy context ok
[INFO] Reset device 0 ok
[INFO] Finalize acl ok
[INFO] The program runs successfully, Please visit http://192.168.199.204:7007 for display server!
Enter any command to stop the application:
kill existing project process: kill -9 3147.
/home/HwHiAiUser/Ascend/thirdpart/aarch64/common/sample_common.sh: line 40: kill: (3147) - No such process
ERROR: kill project process failed.
經(jīng)過專家指點,是目前攝像頭相關(guān)底層代碼的fps設(shè)置有誤:
當然,專家的指點只是一個方向,代碼具體的實現(xiàn)張小白仔細看了一下,face_detection_camera 調(diào)用的是acllite。
首先,main.cpp調(diào)用了 ~/samples/cplusplus/common/acllite/src/AclLiteVideoProc.cpp:
然后,位于 /home/HwHiAiUser/samples/cplusplus/common/acllite/src 的 AclLiteVideoProc.cpp 調(diào)用了CameraCapture:
由于不知道它調(diào)了哪個,所以兩邊都加了個日志。
最后在 ./samples/cplusplus/common/acllite/src/CameraCapture.cpp 的 SetProperty設(shè)置屬性:
張小白對于代碼邏輯都沒改,只是加了幾行日志。
然后
cd ~/samples/cplusplus/common/acllite
make
make install
再回到工程目錄:
cd ~/samples/cplusplus/level2_simple_inference/2_object_detection/face_detection_camera/scripts
bash sample_build.sh
bash sample_run.sh
此時,代碼正在運行,瀏覽器打開 192.168.199.204:7007
出現(xiàn)了Presenter Server的頁面,點擊person可以打開:
可以看到,視頻中的人臉可以被成功識別。
(未完待續(xù))