I follow the example of the face recognition application from the Pro iOS 5 Augmented Reality book. I even downloaded the source code ... I ran it from there, and the problem remained with its code. Here's the problem: it crashes when assigning an array that takes an InImage CGImage function to a CIDetector that detects a face. From the registration ... it seems that this method is called many many times ... I use cocos2d_chipmunk, so I use CSScene. Please note that this glitch - EXC_BAD_ACCESS (code=1, address=0x4499923c)
Help please?
- (void)facialRecognitionRequest:(UIImage *)image {
if (!isProcessingRequest) {
isProcessingRequest = YES;
NSArray* arr = [detector featuresInImage:[CIImage imageWithCGImage:[image CGImage]]];
if ([arr count] > 0) {
for (int i = 0; i < 1; i++) {
CIFaceFeature *feature = [arr objectAtIndex:i];
double xPosition = (feature.leftEyePosition.x + feature.rightEyePosition.x+feature.mouthPosition.x)/(3*image.size.width) ;
double yPosition = (feature.leftEyePosition.y + feature.rightEyePosition.y+feature.mouthPosition.y)/(3*image.size.height);
double dist = sqrt(pow((feature.leftEyePosition.x - feature.rightEyePosition.x),2)+pow((feature.leftEyePosition.y - feature.rightEyePosition.y),2))/image.size.width;
yPosition += dist;
CGSize size = [[CCDirector sharedDirector] winSize];
pumpkin.opacity = 255;
pumpkin.scale = 5*(size.width*dist)/256.0;
[pumpkin setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"pumpkin%d.png", pumpkin_count + 4]]];
CCMoveTo *moveAction = [CCMoveTo actionWithDuration:0 position:ccp((size.width * (xPosition)), (size.height * ((yPosition))))];
[pumpkin runAction:moveAction];
}
} else {
pumpkin.opacity = 0;
}
}
isProcessingRequest = NO;
}
Purpose of CIDetector:
- (id)init {
if (self = [super init]) {
NSDictionary *detectorOptions = [NSDictionary dictionaryWithObjectsAndKeys:CIDetectorAccuracyLow, CIDetectorAccuracy, nil];
self.detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:detectorOptions];
}
return self;
}
I tried: CGImage * theCGImage = [CGImage image]; NSLog (@ "theCGImage:% @", theCGImage);
CIImage *theCIImage = [CIImage imageWithCGImage:theCGImage];
NSLog(@"theCIImage: %@", theCIImage);
NSArray* arr = [detector featuresInImage:theCIImage];
NSLog(@"arr: %@", arr);
Here are the results:
2012-04-15 19:08:25.136 Ch8[981:609f] tmpCGImage: <CGImage 0x1f689c00>
2012-04-15 19:08:25.143 Ch8[981:609f] tmpCIImage: <CIImage: 0x1f687970 extent [0 0 480 360]>
2012-04-15 19:08:25.282 Ch8[981:609f] arr: (
"<CIFaceFeatureInternal: 0x1f58e080>"
)
NSZombies, ... - ?