vs2013+tesseract配置

(大部分乃转载http://blog.youkuaiyun.com/suninsky_plate/article/details/52820800,按照这个过程中间回出现一些问题,将修改方法指明)

编译

在C盘创建一个文件夹叫tesseract-build 
切换到该文件夹下,输入下面命令

git clone https://github.com/charlesw/tesseract-vs2012.git
 
 
  • 1


打开 VS 2013 Developer Command Prompt (VS2013 开发人员命令提示)切换到C:\tesseract-build\tesseract-vs2012 
执行下面命令 msbuild build.proj

结束以后显示300多个警告,0个错误,代表这一步成功了。

(并不一定立即成功,liblept\src\boxfunc1.c和liblept\src\utils.c中的l_int全部改成int,并且将attributes的类型由l_uint32改成int,则无错) 
把 C:\tesseract-build\tesseract-vs2012\release 下的include lib 复制到C:\tesseract-build下。 
把 C:\tesseract-build\tesseract-vs2012 里的 vs2013+64bit_support.patch 复制到C:\tesseract-build下。

git clone https://github.com/tesseract-ocr/tesseract.git
 
 
  • 1

切换到tesseract文件夹,右键运行git bash 
执行

git checkout -b 3.04-vs2013 3.04.00
git am --signoff < ../vs2013+64bit_support.patch
 
 
  • 1
  • 2

打开C:\tesseract-build\tesseract\vs2013\tesseract.sln ,按F7生成解决方案。Release和Debug都生成一下。(生成解决方案时出错,修改方法:修改tesseract中equationdetect.cpp文件,将

  1. static const STRING kCharsToEx[] = {"'""`""\"""\\", ",", ".",  
  2.     "〈""〉""《""》""」""「"""};  
修改为
  1. static const STRING kCharsToEx[] = { "'""`""\"""\\", ",", ".",  
  2.     "<"">""<<"">>""" };  

配置

C:\tesseract-build\lib\Win32里的liblept开头的文件复制到C:\tesseract-build\lib

新建工程,在项目属性页的包含目录中添加:

C:\tesseract-build\include
C:\tesseract-build\include\leptonica
 
 
  • 1
  • 2

在库目录中添加:

C:\tesseract-build\lib
 
 
  • 1

附加依赖项中添加:

liblept171.lib
libtesseract304.lib
 
 
  • 1
  • 2

libtesseract304.dlllibtesseract304d.libliblept171.dllliblept171d.dll拷贝到C:\Windows\System32和C:\Windows\System目录下。

测试代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <opencv2\opencv.hpp>
#include <tesseract\baseapi.h>
#include <iostream>
#include <stdlib.h>

tesseract::TessBaseAPI ocr;

char* identifyText(cv::Mat input, char* language = "eng")
{
    ocr.Init(NULL, language, tesseract::OEM_TESSERACT_ONLY);
    ocr.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);
    ocr.SetImage(input.data, input.cols, input.rows, 1, input.step);
    char* text = ocr.GetUTF8Text();
    std::cout << "Text:" << std::endl;
    std::cout << text << std::endl;
    std::cout << "Confidence:" << ocr.MeanTextConf() << std::endl;
    return text;
}

int main(int argc, char* argv[])
{
    cv::Mat image = cv::imread("D:/2.jpg", 0);
    if (image.empty())
    {
        return -1;
    }
    cv::Mat binary;
    cv::threshold(image, binary, 100, 255, CV_THRESH_BINARY);
    identifyText(binary);
    system("pause");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值