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
从宿主机将结果文件拷贝回来:
mkdir camera
cd camera
scp HwHiAiUser@192.168.1.2:~/samples/cplusplus
/level1_single_api/5_200dk_peripheral/ascendcamera/out/output/*.jpg .
打开看看:
说明这两个摄像头拍照都没(太大的)问题。(尽管这个带夜视的廉价摄像头是一如既往的发红。。)
执行以下脚本下载caffe模型,并转换为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.
经过专家指点,是目前摄像头相关底层代码的fps设置有误:
当然,专家的指点只是一个方向,代码具体的实现张小白仔细看了一下,face_detection_camera 调用的是acllite。
首先,main.cpp调用了 ~/samples/cplusplus/common/acllite/src/AclLiteVideoProc.cpp:
然后,位于 /home/HwHiAiUser/samples/cplusplus/common/acllite/src 的 AclLiteVideoProc.cpp 调用了CameraCapture:
由于不知道它调了哪个,所以两边都加了个日志。
最后在 ./samples/cplusplus/common/acllite/src/CameraCapture.cpp 的 SetProperty设置属性:
张小白对于代码逻辑都没改,只是加了几行日志。
然后
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
出现了Presenter Server的页面,点击person可以打开:
可以看到,视频中的人脸可以被成功识别。
(未完待续)