make -j选项的意义
make -j 1 && make install 一个CPU编译
make -j 2 && make install 二个CPU编译
温馨提示:openvino版本需要和模型版本对应,否则会出错!
法一
cd ~/Downloads/
最新版的openvino有三种sample,分别是c、cpp、python
此处要使用cpp的示例,例如:
cd inference_engine_vpu_arm/deployment_tools/inference_engine/samples/cpp
创建build并转到该目录下
mkdir build && cd build
编译
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a"
make -j2 object_detection_sample_ssd
编译完成后下载网络和权重文件:
wget --no-check-certificate https://download.01.org/openvinotoolkit/2018_R4/open_model_zoo/face-detection-adas-0001/FP16/face-detection-adas-0001.bin
温馨提示:openvino版本需要和模型版本对应,否则会出错!
wget --no-check-certificate https://download.01.org/openvinotoolkit/2018_R4/open_model_zoo/face-detection-adas-0001/FP16/face-detection-adas-0001.xml
然后自己在网上找一张人脸的图片,执行
./armv7l/Release/object_detection_sample_ssd -m face-detection-adas-0001.xml -d MYRIAD -i <path_to_image>
#<path_to_image>是人脸图片的绝对路径
例如
./armv7l/Release/object_detection_sample_ssd -m face-detection-adas-0001.xml -d MYRIAD -i /home/pi/1.jpg
如果运行成功,会在build文件夹下输出一副out_0.bmp图片:
原图
到这里表示计算棒运行成功!
法二:Opencv + python api调用方法
建一个文件夹,把之前下载的xml和bin文件、准备的图片、py文件都放进去
下面是官方示例代码,注意这个cv2,Openvino自带Opencv,不需要再自己去下
import cv2 as cv
# Load the model.可以在这里修改要使用的模型文件
net = cv.dnn.readNet('face-detection-adas-0001.xml', 'face-detection-adas-0001.bin')
# Specify target device.
net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)
# Read an image.替换成你的图片相对路径
frame = cv.imread('/home/pi/1.jpg')
if frame is None:
raise Exception('Image not found!')
# Prepare input blob and perform an inference.
blob = cv.dnn.blobFromImage(frame, size=(672, 384), ddepth=cv.CV_8U)
net.setInput(blob)
out = net.forward()
# Draw detected faces on the frame.
for detection in out.reshape(-1, 7):
confidence = float(detection[2])
xmin = int(detection[3] * frame.shape[1])
ymin = int(detection[4] * frame.shape[0])
xmax = int(detection[5] * frame.shape[1])
ymax = int(detection[6] * frame.shape[0])
if confidence > 0.5:
cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))
# Save the frame to an image file.
cv.imwrite('out.png', frame)
先切换到py所在的文件夹
/home/pi/Downloads/inference_engine_vpu_arm/inference_engine/samples/build/
然后运行,一定要用python3,2没有OpenCV
还有一个细节要注意
如果你这样运行就会报错,说找不到xml文件
python3 NCS2.py
树莓派断点关机的,有空再来截图
参考
https://blog.csdn.net/qqqzmy/article/details/85213414
https://blog.csdn.net/qq_47110957/article/details/105597468
https://blog.csdn.net/PianGe_zyl/article/details/108241395