Face Detection Problem Using CIDetector

I am working on an application in which I have to detect the left eye, right eye and mouth. I have an ImageView on my self.view and the imageView contains an image of a face, now I want to get the coordinates of both eyes and mouth. I saw 2-3 code examples for this, but they are all about the same in all codes that we have to invert in my view to match the coordinates that I don't want, because my view has some other controls. And one more thing they all use

UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image.png"]]; 

but my ImageView has a frame, and I cannot initialize it with the image. When I do this, I find that the faces and eyes do not match the eyes.

I started my code from this code sample , but in this view, its Y coordinate is also inverted.

Can someone help me how can I detect the face and mouth in the UIImageView image without inverting my self.view.

let me know if my question is not clear enough.

Any help would be appreciated, thanks in advance!

+6
source share
2 answers

Designed it! - edited the class to have a faceContainer that contains all the objects of the face (mouth and eyes), then this container rotates and all that. Obviously, this is very rude, but it really works. Here is the link, http://www.jonathanlking.com/download/AppDelegate.m . Then replace the application delegate from the sample code with it.

- OLD POST -

Look at the Apple Documentation and move 42 out of this apple talk . In addition, you should probably follow up on conversations, since it has a demo of what you are trying to achieve, it is called โ€œUsing the main image on iOS and Mac OS Xโ€ here .

0
source

The trick here is to convert the returned points and borders from the CIDetector to your coordinates, rather than flipping through your own view. CIImage has a start in the bottom left, which you will need to convert to the top left

 int height = CVPixelBufferGetHeight(pixelBuffer); CGAffineTransform transform = CGAffineTransformMakeScale(1, -1); transform = CGAffineTransformTranslate(transform, 0, -1 * height); /* Do your face detection */ CGRect faceRect = CGRectApplyAffineTransform(feature.bounds, transform); CGPoint mouthPoint = CGPointApplyAffineTransform(feature.mouthPosition, transform); // Same for eyes, etc 

For your second question about UIImageView you just need to do

 imageview.image = yourImage 

After initializing your image

+1
source

Source: https://habr.com/ru/post/918744/


All Articles