Bar*_*K88 5 iphone tesseract image filter uiimage
我在我的iPhone应用程序中使用tesseract.
我在我的图像上尝试了几个滤镜,用于将其转换为灰度图像,但是我希望得到一个阈值设置的结果,以便图像内部的唯一像素为黑色或白色.
我成功地使用苹果灰度过滤器,它给出了适当的结果.然而,它仍然是一个16位图像(如果我错了,请纠正我).我目前使用的过滤如下:
- (UIImage *) grayishImage:(UIImage *)i {
// Create a graphic context.
UIGraphicsBeginImageContextWithOptions(i.size, YES, 1.0);
CGRect imageRect = CGRectMake(0, 0, i.size.width, i.size.height);
// Draw the image with the luminosity blend mode.
[i drawInRect:imageRect blendMode:kCGBlendModeLuminosity alpha:1.0];
// Get the resulting image.
UIImage *filteredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return filteredImage;
}
Run Code Online (Sandbox Code Playgroud)
谁能为我提供过滤器来获得纯黑白像素而不是灰度图像?
Bra*_*son 12
可能最快的方法是使用OpenGL ES 2.0着色器将阈值应用于图像.我的GPUImage框架封装了这个,这样你就不必担心幕后更多的技术方面了.
使用GPUImage,您可以使用GPUImageLuminanceThresholdFilter获取UIImage的阈值版本,代码如下:
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
GPUImageLuminanceThresholdFilter *stillImageFilter = [[GPUImageLuminanceThresholdFilter alloc] init];
stillImageFilter.threshold = 0.5;
[stillImageSource addTarget:stillImageFilter];
[stillImageFilter useNextFrameForImageCapture];
[stillImageSource processImage];
UIImage *imageWithAppliedThreshold = [stillImageFilter imageFromCurrentFramebuffer];
Run Code Online (Sandbox Code Playgroud)
您可以将彩色图像传递给此图像,因为这会自动从每个像素中提取亮度并将阈值应用于此.高于阈值的任何像素变为白色,并且下面的任何像素变为黑色.您可以调整阈值以满足您的特定条件.
但是,对于你要传递给Tesseract的东西,更好的选择是我的GPUImageAdaptiveThresholdFilter,它可以与GPUImageLuminanceThresholdFilter一样使用,只有没有阈值.自适应阈值处理基于当前像素周围的9像素区域进行阈值处理操作,调整局部照明条件.这是专门为帮助OCR应用程序而设计的,因此可能是这里的方法.
可以在此答案中找到来自两种类型过滤器的示例图像.
请注意,通过UIImage的往返速度比处理原始数据要慢,因此这些过滤器在直接视频或电影源上运行时要快得多,并且可以实时运行这些输入.我还有一个原始像素数据输出,与Tesseract一起使用可能更快.