从图像中识别文本

Posted

技术标签:

【中文标题】从图像中识别文本【英文标题】:text recognition from image 【发布时间】:2011-11-21 07:20:35 【问题描述】:

如何识别手写文字?

我尝试了 teseract 库(第 2 版),但这不是很好。它的更新版本运行不佳。我已经下载了一个演示项目袖珍 OCR,但也没有编译。 我已经编译并集成了 tesseract 库,但现在它给了我如下链接错误

    Ld /Users/Arkenea/Library/Developer/Xcode/DerivedData/OCR-airiipqjvidtcogttlxdbnqufnnl/Build/Products/Debug-iphonesimulator/OCR.app/OCR normal i386
    cd "/Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2"
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang++ -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/Users/Arkenea/Library/Developer/Xcode/DerivedData/OCR-airiipqjvidtcogttlxdbnqufnnl/Build/Products/Debug-iphonesimulator "-L/Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2" "-L/Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/../../tesseract-ocr-svn" "-L/Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/../../tesseract-ocr-svn/outdir" "-L/Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/lib" -F/Users/Arkenea/Library/Developer/Xcode/DerivedData/OCR-airiipqjvidtcogttlxdbnqufnnl/Build/Products/Debug-iphonesimulator -filelist /Users/Arkenea/Library/Developer/Xcode/DerivedData/OCR-airiipqjvidtcogttlxdbnqufnnl/Build/Intermediates/OCR.build/Debug-iphonesimulator/OCR.build/Objects-normal/i386/OCR.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=30102 -framework Foundation -framework UIKit -framework CoreGraphics -framework MessageUI -ltesseract_api -ltesseract_ccstruct -ltesseract_ccutil -ltesseract_classify -ltesseract_cutil -ltesseract_dict -ltesseract_image -ltesseract_textord -ltesseract_training -ltesseract_viewer -ltesseract_wordrec -ltesseract_main -llept.2.0.0 -llept.2 -llept -llept -ltesseract.3.0.1 -ltesseract.3 -ltesseract -ltesseract -o /Users/Arkenea/Library/Developer/Xcode/DerivedData/OCR-airiipqjvidtcogttlxdbnqufnnl/Build/Products/Debug-iphonesimulator/OCR.app/OCR

ld: warning: directory not found for option '-L/Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/../../tesseract-ocr-svn'
ld: warning: directory not found for option '-L/Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/../../tesseract-ocr-svn/outdir'
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_api.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_ccstruct.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_ccutil.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_classify.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_cutil.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_dict.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_image.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_textord.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_training.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_viewer.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_wordrec.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/libtesseract_main.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/lib/liblept.2.0.0.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/lib/liblept.2.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/lib/liblept.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/lib/libtesseract.3.0.1.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/lib/libtesseract.3.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /Users/Arkenea/Desktop/suraj/notepad/rcarlsen-Pocket-OCR-9912da9 2/lib/libtesseract.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
  "tesseract::TessBaseAPI::End()", referenced from:
      -[OCRDisplayViewController dealloc] in OCRDisplayViewController.o
  "tesseract::TessBaseAPI::TessBaseAPI()", referenced from:
      -[OCRDisplayViewController viewDidLoad] in OCRDisplayViewController.o
  "tesseract::TessBaseAPI::Init(char const*, char const*, tesseract::OcrEngineMode, char**, int, GenericVector<STRING> const*, GenericVector<STRING> const*, bool)", referenced from:
      tesseract::TessBaseAPI::Init(char const*, char const*) in OCRDisplayViewController.o
  "tesseract::TessBaseAPI::TesseractRect(unsigned char const*, int, int, int, int, int, int)", referenced from:
      -[OCRDisplayViewController readAndProcessImage:] in OCRDisplayViewController.o
      -[OCRDisplayViewController threadedReadAndProcessImage:] in OCRDisplayViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

有人可以帮助我或指出一些很棒的资源吗?

【问题讨论】:

【参考方案1】:

为此,我们必须在其中设置一些设置 像 tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], "eng"); tesseract->SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.!@#$%^&*()_+/|:?,~`"); tesseract->AllWordConfidences();

给它白名单作为您的要求

并将模式设置为默认值 或根据您的要求

【讨论】:

以上是关于从图像中识别文本的主要内容,如果未能解决你的问题,请参考以下文章

如何在 iOS 中使用 Tesseract OCR 库从图像中识别准确的文本?

如何在python中使用OCR从图像中获取文本识别器的坐标

没有从图像中获取印地语文本

google vision api 可以从图像中识别代码文本(例如 javascript)吗?

使用 PIL 从 url 打开图像文件以使用 pytesseract 进行文本识别

如何利用图像识别语音识别文本挖掘做好鉴黄?