1 Star 0 Fork 0

sunchao/yoloface-landmark106

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
yolo_pfld106.py 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
import cv2
from detect_img import dect_box_handle, draw_point
INPUT_SIZE = 56
def forward_landmark(landmark_net, face_roi, bbox):
ih, iw, _ = face_roi.shape
sw = float(iw) / float(112)
sh = float(ih) / float(112)
blob = cv2.dnn.blobFromImage(face_roi, scalefactor=1 / 255.0, size=(112, 112))
landmark_net.setInput(blob)
out = landmark_net.forward()
points = out[0].flatten()
for i in range(int(len(points) / 2)):
points[i * 2] = ((points[i * 2] * 112) * sw) + bbox[0]
points[(i * 2) + 1] = ((points[(i * 2) + 1] * 112) * sh) + bbox[1]
return points
if __name__ == "__main__":
net = cv2.dnn.readNetFromCaffe('caffemodel/yoloface-50k.prototxt', 'caffemodel/yoloface-50k.caffemodel')
landmark_net = cv2.dnn.readNet('v3.onnx')
imgpath = 'test.jpeg'
srcimg = cv2.imread(imgpath)
blob = cv2.dnn.blobFromImage(srcimg, scalefactor=1 / 256.0, size=(INPUT_SIZE, INPUT_SIZE), swapRB=True)
net.setInput(blob)
outputs = net.forward()
outputs = outputs.transpose(0, 3, 2, 1)[0,:]
output_box = dect_box_handle(outputs, srcimg)
for i in output_box:
face_roi = srcimg[i[1]:i[3], i[0]:i[2]]
points = forward_landmark(landmark_net, face_roi, i)
draw_point(srcimg, points)
print('detect', int(points.size*0.5), 'points')
cv2.rectangle(srcimg, (i[0], i[1]), (i[2], i[3]), (255, 255, 0), 2)
cv2.namedWindow('detect', cv2.WINDOW_NORMAL)
cv2.imshow('detect', srcimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/moyan_sun/yoloface-landmark106.git
git@gitee.com:moyan_sun/yoloface-landmark106.git
moyan_sun
yoloface-landmark106
yoloface-landmark106
main

搜索帮助