2011-02-16 96 views
22

是否有用于检测在图像平面中旋转的脸部的库?或者有什么方法可以使用opencv进行直立人脸检测级联?旋转脸部检测

+0

你有没有试过EXIF库?我相信它会有帮助。 – 2016-01-15 05:25:13

回答

2

朴素的方式:

  • 生成角的列表(例如,从-170至180在10度的步骤)
  • 对于列表中的每个角度n:由n
    • 旋转图像度
    • 旋转图像上的运行人脸检测器
    • 计算原始图像中检测到的人脸位置(撤消旋转)
  • 上从各个角度连接结果执行非最大抑制(你可能会得到多次检测从邻近的角度)基于颜色直方图的人脸检测
+1

这使得检测非常缓慢,并返回更多的误报,但可能是使哈尔检测类型旋转不变的唯一方法... – Ben 2011-11-18 11:41:15

0

方法是独立的面部朝向的。

0

你可以使用袋子里的单词/袋子的特征方法来约束AAM,ASM方法。 ,但它们也可以给出不是最优解收敛到全局最大值。

也haar-like-features只是功能的集合,你可以使用旋转不变的功能,然后把它放在adaboost classifer。

6

这里有一个简单的我与Python CV2

这不是最有效的事情写的,并且它使用etarion建议用简单的方式,但它的工作原理相当不错的只是正常的头倾斜(从检测什么 - 40至40头倾斜,这大概就像你可以倾斜你的头留直立。

import cv2 
from math import sin, cos, radians 

camera = cv2.VideoCapture(0) 
face = cv2.CascadeClassifier("haarcascade_frontalface_alt2.xml") 

settings = { 
    'scaleFactor': 1.3, 
    'minNeighbors': 3, 
    'minSize': (50, 50), 
    'flags': cv2.cv.CV_HAAR_FIND_BIGGEST_OBJECT|cv2.cv.CV_HAAR_DO_ROUGH_SEARCH 
} 

def rotate_image(image, angle): 
    if angle == 0: return image 
    height, width = image.shape[:2] 
    rot_mat = cv2.getRotationMatrix2D((width/2, height/2), angle, 0.9) 
    result = cv2.warpAffine(image, rot_mat, (width, height), flags=cv2.INTER_LINEAR) 
    return result 

def rotate_point(pos, img, angle): 
    if angle == 0: return pos 
    x = pos[0] - img.shape[1]*0.4 
    y = pos[1] - img.shape[0]*0.4 
    newx = x*cos(radians(angle)) + y*sin(radians(angle)) + img.shape[1]*0.4 
    newy = -x*sin(radians(angle)) + y*cos(radians(angle)) + img.shape[0]*0.4 
    return int(newx), int(newy), pos[2], pos[3] 

while True: 
    ret, img = camera.read() 

    for angle in [0, -25, 25]: 
     rimg = rotate_image(img, angle) 
     detected = face.detectMultiScale(rimg, **settings) 
     if len(detected): 
      detected = [rotate_point(detected[-1], img, -angle)] 
      break 

    # Make a copy as we don't want to draw on the original image: 
    for x, y, w, h in detected[-1:]: 
     cv2.rectangle(img, (x, y), (x+w, y+h), (255,0,0), 2) 

    cv2.imshow('facedetect', img) 

    if cv2.waitKey(5) != -1: 
     break 

cv2.destroyWindow("facedetect") 
2

就个人而言,我不知道一个图书馆。但是,我可以说的是,用眼睛检测然后,您可以使用atan函数并查找头部旋转的角度编辑。 (假设人对同一水平的双眼时,头不旋转)

deg = atan((leftEye.y - rightEye.y)/(leftEye.x - rightEye.x)) 

一旦你得到这个角度,转动你必须负deg度的图像,你应该有一个面可以是使用Haar Cascades进行检测。