face-landmarking-ios icon indicating copy to clipboard operation
face-landmarking-ios copied to clipboard

Face detection from UIImage

Open skyfoxa opened this issue 7 years ago • 5 comments

HI, great job, very helpfull project. I'm working on face detection for now, but I need detect face landmarks from an UIImage. Could you give me a hand how to switch the detection from video output? I don't have matedata and faceObject rects as you in AVCaptureVideoDataOutputSampleBufferDelegate, sou I use custom CIDetectorFaceType. But rects from my detector are very diferent from yours, so detected points arent correct. Do you have any hint what to do? Thanks

skyfoxa avatar Jul 19 '16 11:07 skyfoxa

Please check in which format the rects are that you get from CIDetectorFaceType.

AVCaptureVideoDataOutputSampleBufferDelegate delivers rectangles with valid values from 0 to 1 (0 being the leftmost point of the image, 1 being the rightmost; see https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVMetadataObject_Class/index.html#//apple_ref/occ/instp/AVMetadataObject/bounds for more details).

Dlib expects the face rectangles to be in pixel coordinates, that means from 0px to e.g. 640px. That means we have to convert the rectangles (convert relative values from AVMetadataObject to absolute values by multiplying with the size of the complete image).

As far as I can see from https://developer.apple.com/library/ios/documentation/CoreImage/Reference/CIFeature_Ref/index.html#//apple_ref/occ/instp/CIFeature/bounds, the bounds are already in image pixel coordinates. That means you do not need to multiply by the image size, so you can skip the convertScaleCGRect:toDlibRectacleWithImageSize: step that is done in DlibWrapper.mm.

zweigraf avatar Jul 27 '16 12:07 zweigraf

Could you please show some example code in Objective-c.

virut26 avatar Jul 30 '16 14:07 virut26

@virut26 Please stop this. I am sure most professional iOS developer will be glad to port the Swift code to Objective-C. GitHub is not a marketplace for free work.

zweigraf avatar Aug 01 '16 08:08 zweigraf

Hi, This project is a great one, it helped me in the beginning of using dlib in iOS. I also want to get dlib::rectangle from iOS CIFaceFeature, as it is much faster. The thing is that, using face detection with faceFeature.bound rect the points are calculated wrong. I compared 2 dlib::rectangles, one gotten from faceFeature.rect, and the other from dlib::get_frontal_face_detector(). the second one's rect is much smaller compared to the first one. Are there any ideas how to solve this problem.

vuvkar avatar Apr 12 '18 13:04 vuvkar

This project is really great!!!, but I got the same issue when we try to do face detect from UIImage, we have same issue above. @Luis, could you please help us on this? Thank you

softdev999 avatar Oct 27 '18 14:10 softdev999