CIDetector give wrong position on facial features

烈酒焚心 提交于 2019-12-05 16:46:04

Just use the code from Apple's SquareCam app. It aligns the square correctly in any orientation for both the front and rear cameras. Interpolate along the faceRect for the correct eye and mouth positions. Note: you do have to swap the x position with the y position from the face feature. Not sure why exactly you have to do the swap but that gives you the correct positions.

Your transform is missing a scale unless your image view has the exact same size as your image. Start with

   CGAffineTransformMakeScale( viewWidth / imageWidth, - viewHeight / imageHeight )

where viewWidth and viewHeight is the size of your view and imageWidth and imageHeight is the size of your image.

So after playing around and with the help of @Sven, i figured it out.

CGAffineTransform transform = CGAffineTransformMakeScale(self.imageView.bounds.size.width/mainImage.size.width, -self.imageView.bounds.size.height/mainImage.size.height);
    transform = CGAffineTransformRotate(transform, degreesToRadians(270));

I had to adjust the transform to be scaled b.w the image size and the size of the imageview then for some reason i had to rotate it, but it works perfectly now

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!