在Xcode中,我試圖在將圖像發送到OCR之前預處理圖像。 OCR引擎Tesseract處理基於Leptonica庫的圖像。在Xcode項目中使用Leptonica處理圖像
作爲一個例子: Leptonica功能pixConvertTo8(「image.tif」)...有沒有一種方法可以將圖像原始數據從UIImage - > PIX轉換(參見leptonica庫中的pix.h) - >執行pixConvertTo8()並從PIX返回 - > UImage - 並且最好不將它保存到文件進行轉換 - 全部在內存中。
- (void) processImage:(UIImage *) uiImage
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// preprocess UIImage here with fx: pixConvertTo8();
CGSize imageSize = [uiImage size];
int bytes_per_line = (int)CGImageGetBytesPerRow([uiImage CGImage]);
int bytes_per_pixel = (int)CGImageGetBitsPerPixel([uiImage CGImage])/8.0;
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider([uiImage CGImage]));
const UInt8 *imageData = CFDataGetBytePtr(data);
// this could take a while.
char* text = tess->TesseractRect(imageData,
bytes_per_pixel,
bytes_per_line,
0, 0,
imageSize.width, imageSize.height);