iOS Tesseract OCR Image Preperation [英] iOS Tesseract OCR Image Preperation

查看:149
本文介绍了iOS Tesseract OCR Image Preperation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个OCR应用程序来识别来自Photos的文本。

I would like to implement an OCR application that would recognize text from Photos.

我成功编译和集成了iOS中的Tesseract Engine,我成功地理解了在拍摄清晰文件时(或从屏幕上拍摄此文字的照片)检测,但对于其他文字,如路标,商店标志,颜色背景,检测失败。

I succeeded in Compiling and Integration the Tesseract Engine in iOS, I succeeded in getting reasonable detection when photographing clear documents (or a photoshot of this text from the screen) but for other text such as signposts, shop signs, colour background, the detection failed.

问题是什么样的图像处理准备是必要的,以获得更好的识别。例如,我希望我们需要将图像转换为灰度/ B& W以及修复对比度等。

The Question is What kind of image processing preparations are necessary to get better recognition. For example, I expect that we need to transform the images into grayscale /B&W as well as fixing contrast etc.

如何在iOS中完成,是否有这个包?

How can this be done in iOS, Is there a package for this?

推荐答案

我目前正在做同样的事情。
我发现保存在photoshop中的PNG工作正常,但最初从相机中导入然后导入应用程序的图像从未起作用。
不要让我解释它 - 但应用这个功能使这些图像有效。也许它对你也有用。

I'm currently working on the same thing. I found that a PNG saved in photoshop worked fine, but an image which was originally sourced from the camera then imported into the app never worked. Don't ask me to explain it - but applying this function made these images work. Maybe it'll work for you too.

// this does the trick to have tesseract accept the UIImage.
UIImage * gs_convert_image (UIImage * src_img) {
    CGColorSpaceRef d_colorSpace = CGColorSpaceCreateDeviceRGB();
    /*
     * Note we specify 4 bytes per pixel here even though we ignore the
     * alpha value; you can't specify 3 bytes per-pixel.
     */
    size_t d_bytesPerRow = src_img.size.width * 4;
    unsigned char * imgData = (unsigned char*)malloc(src_img.size.height*d_bytesPerRow);
    CGContextRef context =  CGBitmapContextCreate(imgData, src_img.size.width,
                                                  src_img.size.height,
                                                  8, d_bytesPerRow,
                                                  d_colorSpace,
                                                  kCGImageAlphaNoneSkipFirst);

    UIGraphicsPushContext(context);
    // These next two lines 'flip' the drawing so it doesn't appear upside-down.
    CGContextTranslateCTM(context, 0.0, src_img.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    // Use UIImage's drawInRect: instead of the CGContextDrawImage function, otherwise you'll have issues when the source image is in portrait orientation.
    [src_img drawInRect:CGRectMake(0.0, 0.0, src_img.size.width, src_img.size.height)];
    UIGraphicsPopContext();

    /*
     * At this point, we have the raw ARGB pixel data in the imgData buffer, so
     * we can perform whatever image processing here.
     */


    // After we've processed the raw data, turn it back into a UIImage instance.
    CGImageRef new_img = CGBitmapContextCreateImage(context);
    UIImage * convertedImage = [[UIImage alloc] initWithCGImage:
                                 new_img];

    CGImageRelease(new_img);
    CGContextRelease(context);
    CGColorSpaceRelease(d_colorSpace);
    free(imgData);
    return convertedImage;
}

我也做了很多实验,为tesseract准备图像。调整大小,转换为灰度,然后调整亮度和对比度似乎效果最好。

I've also gone a lot of experimentation preparing the image for tesseract. Resizing, converting to grayscale, then adjusting brightness and contrast seems to work best.

我也尝试过这个GPUImage库。 https://github.com/BradLarson/GPUImage
GPUImageAverageLuminanceThresholdFilter似乎给了我一个很好的调整后的图像,但tesseract似乎不能很好地使用它。

I've also tried this GPUImage library. https://github.com/BradLarson/GPUImage And the GPUImageAverageLuminanceThresholdFilter seems to give me a great adjusted image, but tesseract doesn't seem to work well with it.

我还将opencv放入我的项目并计划尝试它的图像例程。可能甚至一些盒子检测找到文本区域(我希望这会加快tesseract)。

I've also put in opencv into my project and plan to try out it's image routines. Possibly even some box detection to find the text area (i'm hoping this will speed up tesseract).

这篇关于iOS Tesseract OCR Image Preperation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆