提交 bd6e2786 编写于 作者: AI浩's avatar AI浩

Update detect_faces.py

上级 13ed05ca
import numpy as np import numpy as np
import cv2 import cv2
low_confidence=0.5 if __name__ == '__main__':
image_path='2.jpg' low_confidence = 0.5
proto_txt='deploy.proto.txt' image_path = '2.jpg'
model_path='res10_300x300_ssd_iter_140000_fp16.caffemodel' proto_txt = 'deploy.proto.txt'
# 加载模型 model_path = 'res10_300x300_ssd_iter_140000_fp16.caffemodel'
print("[INFO] loading model...") # 加载模型
net = cv2.dnn.readNetFromCaffe(proto_txt, model_path) print("[INFO] loading model...")
# 加载输入图像并为图像构建一个输入 blob net = cv2.dnn.readNetFromCaffe(proto_txt, model_path)
# 将大小调整为固定的 300x300 像素,然后对其进行标准化 # 加载输入图像并为图像构建一个输入 blob
image = cv2.imread(image_path) # 将大小调整为固定的 300x300 像素,然后对其进行标准化
(h, w) = image.shape[:2] image = cv2.imread(image_path)
blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)), 1.0, (h, w) = image.shape[:2]
blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)), 1.0,
(300, 300), (104.0, 177.0, 123.0)) (300, 300), (104.0, 177.0, 123.0))
# 通过网络传递blob并获得检测和预测 # 通过网络传递blob并获得检测和预测
print("[INFO] computing object detections...") print("[INFO] computing object detections...")
net.setInput(blob) net.setInput(blob)
detections = net.forward() detections = net.forward()
# 循环检测 # 循环检测
for i in range(0, detections.shape[2]): for i in range(0, detections.shape[2]):
# 提取与相关的置信度(即概率) # 提取与相关的置信度(即概率)
# 预测 # 预测
confidence = detections[0, 0, i, 2] confidence = detections[0, 0, i, 2]
...@@ -36,7 +37,7 @@ for i in range(0, detections.shape[2]): ...@@ -36,7 +37,7 @@ for i in range(0, detections.shape[2]):
(0, 0, 255), 2) (0, 0, 255), 2)
cv2.putText(image, text, (startX, y), cv2.putText(image, text, (startX, y),
cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2) cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
# 展示图片并保存 # 展示图片并保存
cv2.imshow("Output", image) cv2.imshow("Output", image)
cv2.imwrite("01.jpg",image) cv2.imwrite("01.jpg", image)
cv2.waitKey(0) cv2.waitKey(0)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册