我正在编写一个简单的程序,找到图像中最亮的像素,将来可以实现它找到视频帧中最亮的像素。使用小图像,它工作正常。在我的8x8测试图像上,所有黑色都带有一个白色像素,它看起来可以实时找到白色像素,但是当我升级到1000x1000图像时需要几秒钟才能找到它。我的目标是能够让它在高于1000x1000的情况下每秒定位15次以上。这甚至可能吗?这是我使用的代码。
//These are at the beginning of the class
static NSBitmapImageRep *imageRepStatic;
static float brightestBrightness;
static CGPoint brightest;
//This is in my function for getting the pixel
for (int y = 0; y < imageRepStatic.size.height; y++) {
for (int x = 0; x < imageRepStatic.size.width; x++) {
NSColor *color = [imageRepStatic colorAtX:x y:y];
NSArray *pixelData = [[NSString stringWithFormat:@"%@", color] componentsSeparatedByString:@" "];
float red = [[pixelData objectAtIndex:1] floatValue];
float green = [[pixelData objectAtIndex:2] floatValue];
float blue = [[pixelData objectAtIndex:3] floatValue];
float brightness = (red + green + blue) / 3;
if (brightness >= brightestBrightness) {brightestBrightness = brightness; brightest = CGPointMake(x, y);}
}
}
NSLog(@"The brightest pixel is at (%f, %f) and has a brightness of %f", brightest.x, brightest.y, brightestBrightness);
frame ++;
NSLog(@"%i", frame);