1

我想从图像中检测颜色,我在 AVFoundation 的实时相机类的帮助下逐帧获取图像。现在我想从图像中检测红色并在得到红色后进行操作。我读了这篇文章,但找不到任何健康的解决方案。这可能不使用外部库吗?任何教程或帮助材料都会对我有所帮助。提前致谢。

4

1 回答 1

0

试试这个代码。当屏幕发生触摸移动和触摸开始时调用此方法:

-(void) getPixelColorAtLocation:(CGPoint)point {

unsigned char pixel[4] = {0};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGContextTranslateCTM(context, -point.x, -point.y);
[self.layer renderInContext:context];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
        if((pixel[0]=255) && (pixel[1] = 0) && (pixel[2] = 0)){
     //if pixel are red then this condition become true

}

使用此方法获取图像:

- (UIImage *)drawLineFromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint image:(UIImage *)image
{

}

你可以这样称呼它:

self.image = [self drawLineFromPoint:previousPoint  toPoint:point image:self.image];
于 2013-03-15T11:04:12.013 回答