2011-02-16 151 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進行檢測。