我试图做简单的OCR应用程序,但我得到这样的错误:
码:
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);
}
}
我已经尝试了谷歌的一些解决方案,但是并没有解决这个问题。我在Mac OSX上使用Inteliji(带有Maven)。在我对TESTDATA_PREFIX遇到问题之前,但是我更改了api.init第一个参数,现在我得到了:
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
最佳答案
这是因为2个冲突libtesseract.3.dylib
。
如果您在Mac上使用brew安装了tesseract
,则它是指libtesseract.3.dylib
文件夹tesseract
中的/usr/local/Cellar/tesseract/3.04.01_1/lib/
代替/usr/local/lib/libtesseract.3.dylib
关于java - Java Tesseract dyld:未找到符号:,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34347703/