iphone - Coordinate system for CIFaceFeature -


i'm using cifeature class reference face detection , i'm more little confused core graphics coordinates , regular uikit coordinates. code:

    uiimage *mainimage = [uiimage imagenamed:@"facedetectionpic.jpg"];  ciimage *image = [[ciimage alloc] initwithimage:mainimage]; nsdictionary *options = [nsdictionary dictionarywithobject:cidetectoraccuracyhigh forkey:cidetectoraccuracy]; cidetector *detector = [cidetector detectoroftype:cidetectortypeface context:nil options:options]; nsarray *features = [detector featuresinimage:image];  cgrect facerect;  (cifacefeature *feature in features) {     facerect= [feature bounds];  } 

it's pretty standard. according official documentation says:

bounds rectangle holds discovered feature. (read-only)

discussion rectangle in coordinate system of image.

when directly output facerect, get: rect {{136, 427}, {46, 46}}. when apply cgaffinetransfer flip right way, negative coordinates doesn't seem right. image working in imageview.

so in coordinate system these coordinates in? image? imageview? core graphic coordinates? regular coordinates?

i figured out. documentation points out, rectangle drawn cifacefeature in coordinate system of image. means rectangle has coordinates of original image. if have autoresize option checked, means image gets scaled down fit in uiimageview. need convert old image coordinates new image coordinates.

this nifty piece of code adapted here you:

- (cgpoint)convertpointfromimage:(cgpoint)imagepoint {   cgpoint viewpoint = imagepoint;   cgsize imagesize = self.setbody.image.size;  cgsize viewsize  = self.setbody.bounds.size;   cgfloat ratiox = viewsize.width / imagesize.width;  cgfloat ratioy = viewsize.height / imagesize.height;   uiviewcontentmode contentmode = self.setbody.contentmode;    if (contentmode == uiviewcontentmodescaleaspectfit)   {      if (contentmode == uiviewcontentmodescaleaspectfill)      {          cgfloat scale;           if (contentmode == uiviewcontentmodescaleaspectfit) {             scale = min(ratiox, ratioy);          }          else /*if (contentmode == uiviewcontentmodescaleaspectfill)*/ {             scale = max(ratiox, ratioy);         }          viewpoint.x *= scale;         viewpoint.y *= scale;          viewpoint.x += (viewsize.width  - imagesize.width  * scale) / 2.0f;         viewpoint.y += (viewsize.height - imagesize.height * scale) / 2.0f;      }  } return viewpoint; } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -