简体   繁体   English

使用边界框从图像中裁剪人脸

[英]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.

相关问题 使用边界框坐标的语法错误裁剪图像 - syntax error- cropping image using bounding box coordinates 裁剪图像后,如何找到新的边界框坐标? - After cropping a image, how to find new bounding box coordinates? 裁剪和存储图像集合的边界框图像区域? - Cropping and storing bounding box image regions for a collection of images? Google App Engine 图片 API - 使用带百分比的边界框进行裁剪 - Google App Engine Images API - cropping using a bounding box with percentages 如何使用openCV或Python从图像中删除黑色边框 - How to remove black bounding box from the image using openCV or Python 从边界框注释自动裁剪图像 python - Automatic image cropping from bounding boxes annotation python 使用带有KNN算法的OpenCV Python检测面部丘疹的边界框 - Bounding Box on Detecting pimples on face using OpenCV Python with KNN algorithm 给定边界框的人脸验证 - Face verification of given bounding box 如何在不使用边界框的情况下标记图像? - How to label image without using bounding box? 通过边界框从图像中提取选定的文本 - Extracting selected text by bounding box from an image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM