Я пытаюсь получить цвет пикселей на изображении, отображаемом веб-камерой. Я хочу увидеть, как цвет пикселя меняется со временем.
Мое текущее решение высасывает ОЧЕНЬ ЦП, оно работает и дает мне правильный ответ, но я не уверен на 100%, правильно ли я это делаю, или я мог бы сократить некоторые шаги.
- (IBAction)addFrame:(id)sender
{
// Get the most recent frame
// This must be done in a @synchronized block because the delegate method that sets the most recent frame is not called on the main thread
CVImageBufferRef imageBuffer;
@synchronized (self) {
imageBuffer = CVBufferRetain(mCurrentImageBuffer);
}
if (imageBuffer) {
// Create an NSImage and add it to the movie
// I think I can remove some steps here, but not sure where.
NSCIImageRep *imageRep = [NSCIImageRep imageRepWithCIImage:[CIImage imageWithCVImageBuffer:imageBuffer]];
NSSize n = {320,160 };
//NSImage *image = [[[NSImage alloc] initWithSize:[imageRep size]] autorelease];
NSImage *image = [[[NSImage alloc] initWithSize:n] autorelease];
[image addRepresentation:imageRep];
CVBufferRelease(imageBuffer);
NSBitmapImageRep* raw_img = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
NSLog(@"image width is %f", [image size].width);
NSColor* color = [raw_img colorAtX:1279 y:120];
float colourValue = [color greenComponent]+ [color redComponent]+ [color blueComponent];
[graphView setXY:10 andY:200*colourValue/3];
NSLog(@"%0.3f", colourValue);
Любая помощь приветствуется, и я с удовольствием попробую другие идеи.
Спасибо, ребята.