在人臉檢測算法中,FDDB人臉數據集的人臉標註是橢圓形的框。
FDDB: Face Detection Data Set and Benchmark
數據格式如下:
major_axis_radius minor_axis_radius angle center_x center_y 1
長軸,短軸,角度,橢圓中心X,橢圓中心Y,類別1
2002/08/15/big/img_346
2
57.900200 36.595000 -1.522423 167.614400 65.427201 1
58.832400 43.598899 1.552231 304.969700 89.517800 1
圖像
使用OpenCV將橢圓框的人臉標記到圖像中,注意:橢圓函數是ellipse()的軸參數,是先短軸後長軸,與FDDB數據集正好相反。
import cv2
img = cv2.imread('./data/img_346.jpg') # 讀取圖像
cv2.ellipse(img, center=(167, 65), axes=(36, 58),
angle=-1.522423, startAngle=0, endAngle=360,
color=255)
cv2.ellipse(img, center=(304, 89), axes=(43, 58),
angle=1.552231, startAngle=0, endAngle=360,
color=255)
cv2.imshow('Image', img)
cv2.imwrite('./data/img_346.bbox.jpg', img)
cv2.waitKey(0)
將橢圓框轉換爲矩形框,中心加減長短軸,就是矩形框的兩個對角點:
import cv2
img = cv2.imread('./data/img_346.jpg')
cv2.ellipse(img, center=(167, 65), axes=(36, 58),
angle=-1.522423, startAngle=0, endAngle=360,
color=255)
cv2.ellipse(img, center=(304, 89), axes=(43, 58),
angle=1.552231, startAngle=0, endAngle=360,
color=255)
i1_pt1 = (167 - 36, 65 - 58)
i1_pt2 = (167 + 36, 65 + 58)
cv2.rectangle(img, pt1=i1_pt1, pt2=i1_pt2, color=(255, 0, 255))
i2_pt1 = (304 - 43, 89 - 58)
i2_pt2 = (304 + 43, 89 + 58)
cv2.rectangle(img, pt1=i2_pt1, pt2=i2_pt2, color=(255, 0, 255))
cv2.imshow('Image', img)
cv2.imwrite('./data/img_346.bbox.jpg', img)
cv2.waitKey(0)
OK, that’s all! Enjoy it!