-
Notifications
You must be signed in to change notification settings - Fork 0
/
tesse2.cpp
44 lines (34 loc) · 1.04 KB
/
tesse2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <tesseract/baseapi.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
int main()
{
// Load image
cv::Mat im = cv::imread("image1.png");
if (im.empty())
{
std::cout << "Cannot open source image!" << std::endl;
return -1;
}
cv::Mat gray, dst;
cv::cvtColor(im, gray, CV_BGR2GRAY);
cv::threshold( gray, dst, 130, 255,1 );
namedWindow("revbin", CV_WINDOW_AUTOSIZE);
cv::imshow("revbin", gray);
// ...other image pre-processing here...
// Pass it to Tesseract API
tesseract::TessBaseAPI tess;
baseAPI.setVariable("tessedit_char_whitelist", "123456789+-/x");
tess.Init(NULL, "eng", tesseract::OEM_DEFAULT);
tess.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);
tess.SetImage((uchar*)dst.data, dst.cols, dst.rows, 1, dst.cols);
// Get the text
char* out = tess.GetUTF8Text();
std::cout << out << std::endl;
return 0;
}