Skip to content

Instantly share code, notes, and snippets.

@noelyahan
Created January 29, 2016 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noelyahan/e5c350a1cf44b69b142c to your computer and use it in GitHub Desktop.
Save noelyahan/e5c350a1cf44b69b142c to your computer and use it in GitHub Desktop.
#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