当前位置:   article > 正文

玩转Atlas200DK(十四)玩转摄像头_atlas200dk连接高端摄像头

atlas200dk连接高端摄像头

十四、在Atlas 200DK上玩转摄像头

200DK有两个摄像头的接口,早在两年前,张小白就在早期CANN版本中试过摄像头:

Atlas 200DK系统折腾纪实:(1)论图片及18.04.1的诞生​bbs.huaweicloud.com/blogs/194291

当然也要注意里面的坑,比如说接口中排线的方向等等。

我们下面看看,在CANN 5.0.4 alpha005的版本对摄像头的支持如何:

1、在200DK上执行ascend camera例程

根据:https://gitee.com/ascend/samples/tree/v0.6.0/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera

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 .

打开看看:

说明这两个摄像头拍照都没(太大的)问题。(尽管这个带夜视的廉价摄像头是一如既往的发红。。)

2、在200DK上执行face_detection_camera例程

根据 https://gitee.com/ascend/samples/tree/v0.6.0/cplusplus/level2_simple_inference/2_object_detection/face_detection_camera

执行以下脚本下载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

具体报错如下:

  1. HwHiAiUser@davinci-mini:~/samples/cplusplus/level2_simple_inference/2_object_detection/face_detection_camera/scripts$ bash sample_run.sh
  2. [INFO] The sample starts to run
  3. Current environment valid ip list:
  4. 127.0.0.1
  5. 192.168.199.204
  6. Please choose one to show the presenter in browser:192.168.199.204
  7. [INFO] Acl init ok
  8. [INFO] Open device 0 ok
  9. [INFO] Use default context currently
  10. content_type config string:1
  11. [INFO] dvpp init resource ok
  12. [INFO] Load model ../model/face_detection.om success
  13. [INFO] Create model description success
  14. [INFO] Create model(../model/face_detection.om) output success
  15. [INFO] Init model ../model/face_detection.om success
  16. [INFO] No specified carmera id, use camera0
  17. [ERROR] Set camera fps failed
  18. [ERROR] Set camera0 property failed
  19. [ERROR] Open camera failed
  20. [2022-04-23 18:24:44][LIBMEDIA_ERROR] CloseCamera failed!!! Camera[0] is not opened
  21. [ERROR] Close camera 0 failed
  22. [INFO] Unload model ../model/face_detection.om success
  23. [INFO] destroy context ok
  24. [INFO] Reset device 0 ok
  25. [INFO] Finalize acl ok
  26. [INFO] The program runs successfully, Please visit http://192.168.199.204:7007 for display server!
  27. Enter any command to stop the application:
  28. kill existing project process: kill -9 3147.
  29. /home/HwHiAiUser/Ascend/thirdpart/aarch64/common/sample_common.sh: line 40: kill: (3147) - No such process
  30. 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可以打开:

可以看到,视频中的人脸可以被成功识别。

(未完待续)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/339013
推荐阅读
相关标签
  

闽ICP备14008679号