zweigraf / face-landmarking-ios

👦 Basic face landmarking on iPhone with Dlib via Swift & ObjC++
481 stars 125 forks source link

Face detection from UIImage #3

Open skyfoxa opened 8 years ago

skyfoxa commented 8 years ago

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

zweigraf commented 8 years ago

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.

virut26 commented 8 years ago

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

zweigraf commented 8 years ago

@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.

vuvkar commented 6 years ago

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.

softdev999 commented 6 years ago

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