Note that CIDetectorEyeBlink appeared in iOS 7 !
If you try to use this key in older versions you'll get EXC_BAD_ACCESS because it is undefined.
Starting from iOS7 you won't have problems in this code fragment.
Question
NSDictionary *orientation = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], CIDetectorEyeBlink,
[NSNumber numberWithInt:imgOrientation], CIDetectorImageOrientation, nil];
My app keeps crashing at this line, giving the dreaded EXC_BAD_ACCESS
(code=1, address=0x0). I went through all the contents in the NSDictionary
named "orientation" and they're all objective c objects. Does anyone have any idea as to why this is happening? Anything helps because I'm completely lost. This is the entire method in which the line is located:
-(void)scanFace{
UIImageOrientation imgOrientation = imgView.image.imageOrientation;
orientation = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], CIDetectorEyeBlink,
[NSNumber numberWithInt:imgOrientation], CIDetectorImageOrientation, nil];
CIImage *newImage = [CIImage imageWithCGImage:imgView.image.CGImage
options:orientation];
CIContext *context = [CIContext contextWithOptions:nil];
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:context options:[NSDictionary
dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
NSArray *features = [detector featuresInImage:newImage options:orientation];
if (features.count == 0) {
NSLog(@"NO FACE %i", features.count);
} else {
NSLog(@"FACE FOUND %i", features.count);
}
for (CIFaceFeature *feature in features) {
if (feature.leftEyeClosed == YES) {
leftLab.text = [NSMutableString stringWithFormat:@"Left Eye Closed"];
} else {
leftLab.text = [NSMutableString stringWithFormat:@"Left Eye Open"];
}
if (feature.rightEyeClosed == YES) {
rightLab.text = [NSMutableString stringWithFormat:@"Right Eye Closed"];
} else {
rightLab.text = [NSMutableString stringWithFormat:@"Right Eye Open"];
}
}
}
Here is the stack trace:
0 FaceDetection 0x000551a7 -[ViewController scanFace] + 66
1 FaceDetection 0x000550cb __26-[ViewController takePic:]_block_invoke_2 + 282
2 libdispatch.dylib 0x3c6ac793 <redacted> + 10
3 libdispatch.dylib 0x3c6ac5db <redacted> + 22
4 libdispatch.dylib 0x3c6afe45 _dispatch_main_queue_callback_4CF + 228
5 CoreFoundation 0x3456b1b1 <redacted> + 1288
6 CoreFoundation 0x344de23d CFRunLoopRunSpecific + 356
7 CoreFoundation 0x344de0c9 CFRunLoopRunInMode + 104
8 GraphicsServices 0x380bd33b GSEventRunModal + 74
9 UIKit 0x363fa2b9 UIApplicationMain + 1120
10 FaceDetection 0x00055e41 main + 116
11 libdyld.dylib 0x3c6bfb20 <redacted> + 0
Solution
Note that CIDetectorEyeBlink appeared in iOS 7 !
If you try to use this key in older versions you'll get EXC_BAD_ACCESS because it is undefined.
Starting from iOS7 you won't have problems in this code fragment.