问题描述:

im trying to do simple OCR application but i get errors like this:

Code:

import org.bytedeco.javacpp.*;

import static org.bytedeco.javacpp.lept.*;

import static org.bytedeco.javacpp.tesseract.*;

import static org.junit.Assert.assertTrue;

import java.io.File;

import java.io.UnsupportedEncodingException;

public class Main {

public void tesseract(String filename){

BytePointer outText;

tesseract.TessBaseAPI api = new tesseract.TessBaseAPI();

// Initialize tesseract-ocr with English, without specifying tessdata path

if (api.Init("/Users/Marcel/tesseract-ocr", "ENG") != 0) {

System.err.println("Could not initialize tesseract.");

System.exit(1);

}

// Open input image with leptonica library

PIX image = pixRead(filename);

api.SetImage(image);

// Get OCR result

outText = api.GetUTF8Text();

String string = outText.getString();

assertTrue(!string.isEmpty());

System.out.println("OCR output:\n" + string);

// Destroy used object and release memory

api.End();

outText.deallocate();

pixDestroy(image);

}

public static void main(String[] args) {

Main main = new Main();

String fileName = "src/main/resources/test.png";

main.tesseract(fileName);

}

}

I have tried some solutions from google, but it didnt solve this. I using Inteliji (with maven) on Mac OSX. Before i had problem with TESTDATA_PREFIX, but i changed api.init first parameter and now i get this:

dyld: lazy symbol binding failed: Symbol not found: __ZN9tesseract11TessBaseAPI8SetImageEPK3Pix

Referenced from: /private/var/folders/lq/3mb8s_jj1ql0klqzznm1j1tm0000gn/T/javacpp33697284992581/libjnitesseract.dylib

Expected in: /usr/local/lib/libtesseract.3.dylib

dyld: Symbol not found: __ZN9tesseract11TessBaseAPI8SetImageEPK3Pix

Referenced from: /private/var/folders/lq/3mb8s_jj1ql0klqzznm1j1tm0000gn/T/javacpp33697284992581/libjnitesseract.dylib

Expected in: /usr/local/lib/libtesseract.3.dylib

网友答案:

This is because of 2 conflicting libtesseract.3.dylib. If you have installed tesseract on mac using brew then it is referring to the libtesseract.3.dylib inside tesseract folder /usr/local/Cellar/tesseract/3.04.01_1/lib/ instead of /usr/local/lib/libtesseract.3.dylib

相关阅读:
Top