立即学习:https://edu.csdn.net/course/play/28807/427168?utm_source=blogtoedu
1.获取深度学习模型
2.选取所需要的硬件(CPU GPU 棒)
3.读取图像
4.调整图像大小 ,适应模型的输入维度
代码
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
#读入图像
frame=cv.imread('faces.jpg')
#改变图像的大小,格式改变为blob
blob=cv.dnn.blobFromImage(frame,size=(672,384)ddepth=cv.cv_8u)
#输入输出数据(input) foeward方法是将blob数据进行训练并保存在out中
net.setInput(blob)
out=net.forward()
#识别置信度画矩形(没听到,,,不太详细)
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)