1
我正在使用人臉檢測API,並想知道如何將座標從大型高分辨率圖像轉換爲顯示在UIImageView上的較小圖像。到目前爲止,我已經顛倒了我的圖像和容器視圖的座標系統,以便它與核心圖像座標系統相匹配,並且我還計算了高分辨率圖像和圖像視圖尺寸之間的高度比率,但是我得到的座標不準確。我假設我無法像我想的那樣輕鬆地將大圖像中的點轉換爲小圖像。任何人都可以請指出我的錯誤(S)?人臉檢測ios7座標縮放問題
[self.shownImageViewer setTransform:CGAffineTransformMakeScale(1,-1)];
[self.view setTransform:CGAffineTransformMakeScale(1,-1)];
//240 x 320
self.shownImageViewer.image = self.imageToShow;
yscale = 320/self.imageToShow.size.height;
xscale = 240/self.imageToShow.size.width;
height = 320;
CIImage *image = [[CIImage alloc] initWithCGImage:[self.imageToShow CGImage]];
CIContext *faceDetectionContext = [CIContext contextWithOptions:nil];
CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:faceDetectionContext options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}];
NSArray * features = [faceDetector featuresInImage:image options:@{CIDetectorImageOrientation:[NSNumber numberWithInt:6]}];
for(CIFaceFeature *feature in features)
{
if(feature.hasLeftEyePosition)
self.leftEye = feature.leftEyePosition;
if(feature.hasRightEyePosition)
self.rightEye = feature.rightEyePosition;
if(feature.hasMouthPosition)
self.mouth = feature.mouthPosition;
}
NSLog(@"%g and %g",xscale*self.rightEye.x, yscale*self.rightEye.y);
NSLog(@"%g and %g",yscale*self.leftEye.x, yscale*self.leftEye.y);
NSLog(@"%g",height);
self.rightEyeMarker.center = CGPointMake(xscale*self.rightEye.x,yscale*self.rightEye.y);
self.leftEyeMarker.center = CGPointMake(xscale*self.leftEye.x,yscale*self.leftEye.y);