Created
January 29, 2016 10:54
-
-
Save noelyahan/e5c350a1cf44b69b142c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <iostream> | |
#include "opencv2/imgproc/imgproc.hpp" | |
#include "opencv2/highgui/highgui.hpp" | |
#include "opencv2/flann/miniflann.hpp" | |
#include <tesseract/baseapi.h> | |
using namespace cv; | |
using namespace std; | |
using namespace cv::flann; | |
// compile >> g++ <file.cpp> -o app `pkg-config --cflags --libs opencv` -ltesseract | |
// app "image.jpg" | |
int main( int argc, char** argv ) { | |
Mat img = imread(argv[1]); | |
cvtColor(img,img,CV_BGR2GRAY); | |
cv::Mat img_bw; | |
cv::threshold(img, img_bw, 128.0, 255.0, THRESH_BINARY); | |
bitwise_not ( img_bw, img_bw ); | |
tesseract::TessBaseAPI tess; | |
tess.Init(NULL, "eng", tesseract::OEM_DEFAULT); | |
tess.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); | |
tess.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK); | |
tess.SetImage((uchar*)img_bw.data, img_bw.cols, img_bw.rows, 1, img_bw.cols); | |
char* out = tess.GetUTF8Text(); | |
std::cout << out << std::endl; | |
imshow("img",img_bw); | |
waitKey(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment