0

I can do face recognition using the apple's app squareCam. Every thing is working fine, but now I want to recognize face with tilted position, means when the face is tilted for say 30 to 35 degree, I want to recognize them and according to the degree the want to tilt my overlay image to set on the face properly.

Please help me, any suggestion or idea is accepted or invited.

Thanks in advance

Happy Coding :)

Charles
  • 50,943
  • 13
  • 104
  • 142
The iOSDev
  • 5,237
  • 7
  • 41
  • 78

2 Answers2

6

I'm not sure it is what you looked for, but you can use the eyes' positions to determine the angle of tilt like this: (if you are using the iOS face regonition service)

CIFaceFeature *_selectedFace = // the face feature
float _rotationAngle = 0.f;
if (_selectedFace.leftEyePosition.x != _selectedFace.rightEyePosition.x) {
        _rotationAngle = atan((_selectedFace.leftEyePosition.y - _selectedFace.rightEyePosition.y) / (_selectedFace.leftEyePosition.x - _selectedFace.rightEyePosition.x));
}

UPDATE

since iOS7.0, CIFaceFeature has a readonly property, called faceAngle, which can also help to define the face angle.

CIFaceFeature *_selectedFace = // the face feature
float _rotationAngle = _selectedFace.faceAngle;

you can read more about the property in the official CIFaceFeature Class Reference documentation.

holex
  • 23,961
  • 7
  • 62
  • 76
  • sorry but it doesn't provide the required effects. It provide some angle but not the perfect to rotate my overlay image – The iOSDev Jul 20 '12 at 05:53
  • it is not just _some_ angle. I made a project which makes the people's faces older and to position the ageing effects on the face I'm using this angle, it is working perfectly fine. however, I don't know how your overlay image looks and what it is exactly. – holex Jul 20 '12 at 08:27
  • yes it is fine. And i use apples squrecam example to take image the same code with some modification is used to display overlay images – The iOSDev Jul 20 '12 at 08:34
  • as far as I know the `SquareCam` sample project is also using the `CoreImage.framework` for the face recognition, so you are working the `CIFaceFeature`. this is same what I used. however if the `CoreImage` service is not good enough for you, you could create an own face recognition algorithm and then you could get more details of the image in that case. – holex Jul 20 '12 at 08:55
  • 1
    But I don't have enough knowledge about how to create face recognition algorithm. – The iOSDev Jul 20 '12 at 09:05
  • what is your goal with the face recognition? what do you want to do with the recognised faces on the image? – holex Jul 20 '12 at 09:06
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/14167/discussion-between-aalok-parikh-and-holex) – The iOSDev Jul 20 '12 at 09:14
  • @holex I'm looking for exactly the same. Even I use faceangle its not providing the exact coordinates. Please check the question here http://stackoverflow.com/questions/41829807/transform-an-image-using-cifacefeature-in-ios – Maniganda saravanan Jan 29 '17 at 05:27
  • ARFaceAnchor would be ideal. Unfortunately though, ARFaceAnchor is only compatible to iPhone X+ (needs a TrueDepth camera) But AVMetadataFaceObject has roll and yaw angles. – Chewie The Chorkie Jan 29 '20 at 17:01
1

CIFaceFeature now has a faceAngle property

https://developer.apple.com/library/prerelease/ios/documentation/CoreImage/Reference/CIFaceFeature/index.html#//apple_ref/occ/instp/CIFaceFeature/faceAngle

  • My answer was unchecked and downvoted and the comments were cleared. Thanks for stealing my answer. –  Mar 31 '16 at 18:09