使用 Tesseract 进行 OCR 时,使用 OpenCV 可以获得Mat与使用 Leptonica相同的质量结果。Pix
C++17、OpenCV 3.4.1、Tesseract 3.05.01、Leptonica 1.74.4、Visual Studio Community 2017、Windows 10 专业版 64 位
我正在使用 Tesseract 和 OCR,并发现了我认为奇怪的行为。
这是我的代码:
#include "stdafx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
using namespace cv;
using namespace tesseract;
void opencvVariant(string titleFile);
void leptonicaVariant(const char* titleFile);
int main()
{
cout << "Tesseract with OpenCV and Leptonica" << endl;
const char* titleFile = "raptor-companion-2.jpg";
opencvVariant(titleFile);
leptonicaVariant(titleFile);
cout …Run Code Online (Sandbox Code Playgroud) 我正在 WinForms 中运行自动化应用程序并使用 Tesseract,当我在本地主机上运行时,它工作正常,但是当我将文件夹发布或导出bin到另一台计算机时,它会显示以下错误:
System.DIINotFoundException: Failed to find library "leptonica-1.80.0.dll" for platform x86.
in InteropDotNet.LibraryLoader.LoadLibrary(String fileName, String platformName)
in
Interop Runtimelmplementer.LeptonicaApiSignaturesInstance.Leptonica ApiSignaturesImplementation..ctor(LibraryLoader loader)
Run Code Online (Sandbox Code Playgroud)
myproject\packages\Tesseract.4.1.1\lib\net45\leptonika-1.80.0.dll.不成功好吧,整个故事是,我试图在C++中使用Leptonica + Tesseract OCR截取屏幕截图,将其保存为*.bmp文件,然后将其加载回OCR.我不需要经常这样做,但由于我似乎无法将屏幕截图数据直接复制到Leptonica PIX结构中,我需要先将其保存到文件中......实际上,最好是解决这个问题.
这是我在网上找到的一些代码,试图帮助我.
屏幕上限:
HBITMAP ScreenCapture(){
int width=100;
int height=100;
// get the device context of the screen
HDC hScreenDC = CreateDC(L"DISPLAY", NULL, NULL, NULL);
// and a device context to put it in
HDC hMemoryDC = CreateCompatibleDC(hScreenDC);
int x = GetDeviceCaps(hScreenDC, HORZRES);
int y = GetDeviceCaps(hScreenDC, VERTRES);
// maybe worth checking these are positive values
HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, x, y);
// get a new bitmap
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemoryDC, hBitmap);
BitBlt(hMemoryDC, 0, 0, width, height, …Run Code Online (Sandbox Code Playgroud) 我需要在C++中在OpenCV Mat图像和Leptonica Pix图像格式之间进行转换.这用于8位灰度图像的二值化.
我正在运行Tesseract 2.04来读取PNG文件,但我收到此错误: -
Tesseract Open Source OCR Engine
name_to_image_type:Error:Unrecognized image type:png.png
IMAGE::read_header:Error:Can't read this image type:png.png
Tessedit:Error:Read of file failed:png.png
Signal_exit 31 ABORT. LocCode: 3 AbortCode: 3
Run Code Online (Sandbox Code Playgroud)
我到处搜索并尝试了几件事,但找不到根本原因.有些页面提示安装一些Leptonica库,但没有具体说明.似乎每个人的Tesseract版本都可以默认读取PNG文件.我能错过什么?
谢谢!