我是靠谱客的博主 怕黑汉堡,这篇文章主要介绍人脸检测(SSD模型),现在分享给大家,希望可以做个参考。

使用opencv 加载训练好的SSD模型

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 文件下载地址 # deploy.prototxt.txt: # https://github.com/opencv/opencv/tree/master/samples/dnn/face_detector # res10_300x300_ssd_iter_140000.caffemodel: # https://github.com/Shiva486/facial_recognition/blob/master/res10_300x300_ssd_iter_140000.caffemodel import cv2 import numpy as np def cv_show(neme, img): cv2.namedWindow(neme, cv2.WINDOW_NORMAL) cv2.imshow(neme, img) cv2.waitKey(0) cv2.destroyAllWindows() # 读取照片 img = cv2.imread('./images/faces2.jpg') # 加载模型 face_detector = cv2.dnn.readNetFromCaffe('./weights/deploy.prototxt.txt', './weights/res10_300x300_ssd_iter_140000.caffemodel') # 原图尺寸 img_height = img.shape[0] img_width = img.shape[1] # 缩放至模型输入尺寸 img_resize = cv2.resize(img, (500, 300)) # 图像转为blob img_blob = cv2.dnn.blobFromImage(img_resize, 1.0, (500, 300), (104.0, 177.0, 123.0)) # 输入 face_detector.setInput(img_blob) # 推理 detections = face_detector.forward() # 查看检测人脸数量 num_of_detections = detections.shape[2] # 原图复制,一会绘制用 img_copy = img.copy() for index in range(num_of_detections): # 置信度 detection_confidence = detections[0, 0, index, 2] # 挑选置信度 if detection_confidence > 0.15: # 位置 locations = detections[0, 0, index, 3:7] * np.array([img_width, img_height, img_width, img_height]) # 打印 print(detection_confidence * 100) lx, ly, rx, ry = locations.astype('int') # 绘制 cv2.rectangle(img_copy, (lx, ly), (rx, ry), (0, 255, 0), 5) cv_show('neme', img_copy)

最后

以上就是怕黑汉堡最近收集整理的关于人脸检测(SSD模型)的全部内容,更多相关人脸检测(SSD模型)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部