In our test folder Kuvia, we have many images taken daily by Erkki Kurenniemi. In order to detect which ones contain a human presence, we have run a program written with Opencv using its python API. The algorithm that detects the faces tries to establish eyes alignement, the presence of the nose, the mouth and the hairline. The algorithm is our intermediary. Through it, we gain access to the faces but we also must accept its understanding somewhat extended of what a face is.
#!/usr/bin/python import os,cv facesdir="/home/nicolas/Public/kurenniemi-erkki/faces" i=0 j=0 for root, dirs, files in os.walk("."): print root, "dirs", dirs if i>0: for f in files: print os.getcwd() #path = os.path.join(root, d) if f.endswith('JPG') or f.endswith('jpg'): imname=os.path.join(root,f) image=cv.LoadImage(imname, cv.CV_LOAD_IMAGE_COLOR) #Load the image hc = cv.Load("../faces/haarcascade_frontalface_alt2.xml") faces = cv.HaarDetectObjects(image, hc, cv.CreateMemStorage(), 1.2,2, cv.CV_HAAR_DO_CANNY_PRUNING, (220,220) ) if faces: for (x,y,w,h),n in faces: cv.Rectangle(image, (x,y), (x+w,y+h), 255) print imname,' x: ',x,' y: ',y,' width: ',w,' height: ',h cv.SetImageROI(image, (x, y, w, h)) imtmp = cv.CreateImage(cv.GetSize(image),image.depth,image.nChannels) imtmpname=facesdir+'/'+f+'-'+str(x)+'-'+str(y)+'-'+str(w)+'-'+str(h)+'.jpg' cv.Copy(image,imtmp) cv.SaveImage(imtmpname,imtmp) cv.SetImageCOI(image, 0) j+=1 # else: # break i+=1