【问题标题】:Cropping face from image using bounding box使用边界框从图像中裁剪人脸
【发布时间】:2020-12-26 05:43:46
【问题描述】:

这是输入帧:

我使用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 检测到: 但是我无法分别获得面孔:

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])

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

【问题讨论】:

  • 您是否从正确分辨率的图像中裁剪?看起来您正在从缩小的图像中裁剪。带有框的图像是否与您尝试用于裁剪人脸的图像相同?

标签: python opencv machine-learning deep-learning


【解决方案1】:

你尝试过重新实现它的 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()

【讨论】:

    【解决方案2】:

    我参考了retinaface 代码,发现边界框是这样提取的:link

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

    使用类似于上述索引的索引对我来说效果很好。

    x,y,w,h = label
    plt.imshow(frame[y:h, x:w])
    

    【讨论】:

      猜你喜欢
      • 2018-03-07
      • 1970-01-01
      • 2020-12-31
      • 2018-10-24
      • 1970-01-01
      • 2020-09-27
      • 2021-08-12
      • 2018-07-08
      • 1970-01-01
      相关资源
      最近更新 更多