使用边框从图像裁剪脸部

时间:2020-09-07 20:18:10

标签: python opencv machine-learning deep-learning

这是输入框: input image

我用RetinaFace来检测所有面孔和普通的csv文件。这是我的csv文件:

,bbox,score,landmarks
0,"[1811, 850, 1948, 1013]",0.999666452407836,"[[1828, 911], [1887, 913], [1841, 942], [1832, 974], [1876, 976]]"
1,"[346, 1285, 503, 1468]",0.9996420145034791,"[[365, 1361], [424, 1348], [385, 1395], [390, 1426], [439, 1416]]"
2,"[1543, 1418, 1702, 1618]",0.9995224475860591,"[[1578, 1514], [1647, 1498], [1619, 1554], [1610, 1585], [1658, 1572]]"

(上面只有一些行)。

仅显示我的输出图像,其中RetinaFace检测到所有脸部: Output image 但是我无法分开获得面孔:

frame = cv2.imread('input.jpg')
x,y,w,h = [1811, 850, 1948, 1013] # one of the bounding boxes
plt.imshow(frame[y:y+h, x:x+w])

它没有提供正确的面部位置。我得到的输出是:

output

2 个答案:

答案 0 :(得分:3)

我引用了getActiveRange()代码,发现边界框是通过这种方式提取的:link

retinaface

使用与上述索引相似的索引对我来说非常合适。

x_min, y_min, x_max, y_max = annotation["bbox"]

enter image description here

答案 1 :(得分:0)

您是否尝试过重新实现其 tensorflow?它的提取人脸功能直接返回检测到的人脸。此外,它还可以根据地标坐标对齐检测到的人脸。

#!pip install retina-face
from retinaface import RetinaFace
import matplotlib.pyplot as plt
faces = RetinaFace.extract_faces("img.jpg", align = True)
for face in faces:
   plt.imshow(face)
   plt.show()