[英]Cropping face from image using bounding box
This is the input frame :这是输入框:
I used RetinaFace
to detect all the faces and general csv files from that.我使用
RetinaFace
从中检测所有人脸和一般 csv 文件。 This is my csv file :这是我的 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]]"
(only some of the rows are present above ). (只有部分行出现在上方)。
And just to show my output image where all the faces where detected by RetinaFace :只是为了显示我的输出图像,其中 RetinaFace 检测到的所有人脸:
However I'm not able to get the faces separately :
但是我无法分别获得面孔:
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])
It doesn't give the correct facial location.它没有给出正确的面部位置。 The output I get is :
我得到的输出是:
I referred the retinaface
code and found out that the bounding box is being extracted this way : link我参考了
retinaface
代码,发现边界框是以这种方式提取的: 链接
x_min, y_min, x_max, y_max = annotation["bbox"]
Using indexes similar to the above indexing worked perfectly fine for me.使用类似于上述索引的索引对我来说非常好。
x,y,w,h = label
plt.imshow(frame[y:h, x:w])
Did you try its tensorflow re-implementation?你试过它的 tensorflow 重新实现吗? Its extract faces function returns detected faces directly.
它的提取人脸功能直接返回检测到的人脸。 Besides, it can align detected faces based on the landmark coordinations.
此外,它可以根据地标坐标对齐检测到的人脸。
#!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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.