We did it with GPUimage framework like this (calculate brightness and sharpness): (here are some snippets that might help you)
-(BOOL) calculateBrightness:(UIImage *) image {
float result = 0;
int i = 0;
for (int y = 0; y < image.size.height; y++) {
for (int x = 0; x < image.size.width; x++) {
UIColor *color = [self colorAt:image
atX:x
andY:y];
const CGFloat * colors = CGColorGetComponents(color.CGColor);
float r = colors[0];
float g = colors[1];
float b = colors[2];
result += .299 * r + 0.587 * g + 0.114 * b;
i++;
}
}
float brightness = result / (float)i;
NSLog(@"Image Brightness : %f",brightness);
if (brightness > 0.8 || brightness < 0.3) {
return NO;
}
return YES;
}
-(BOOL) calculateSharpness:(UIImage *) image {
GPUImageCannyEdgeDetectionFilter *filter = [[GPUImageCannyEdgeDetectionFilter alloc] init];
BinaryImageDistanceTransform *binImagTrans = [[BinaryImageDistanceTransform alloc] init ];
NSArray *resultArray = [binImagTrans twoDimDistanceTransform:[self getBinaryImageAsArray:[filter imageByFilteringImage:image]]];
if (resultArray == nil) {
return NO;
}
int sum = 0;
for (int x = 0; x < resultArray.count; x++) {
NSMutableArray *col = resultArray[x];
sum += (int)[col valueForKeyPath:@"@max.intValue"];
}
// Values under analysis
NSLog(@"Image Sharp : %i",sum);
if (sum < 26250000) { // tested - bad sharpness is under ca. 26250000
return NO;
}
return YES;
}
But it is very slow. It takes ca. 40 seconds for one image from iPad camera.