if (waitKey(10) >= 0){
imwrite("/home/adrian/workspace/Snapshots/foto.jpg", image); //take snapshot when key is pressed
cont=cuenta;
cont=cont-1;
// read image
Mat imagen = imread("/home/adrian/workspace/foto.jpg");
// initilize tesseract OCR engine
putenv("TESSDATA_PREFIX=/usr/local/share/");
setlocale(LC_ALL, "C");
tesseract::TessBaseAPI api;
if (api.Init(NULL, "eng")) {
fprintf( stderr, " Could not intialize tesseract!!!!\n" );
exit(1);
}
api.SetImage(imagen.data, imagen.size().width,imagen.size().height, imagen.channels(), imagen.step1());
// set region of interest (ROI), i.e. regions that contain text
Rect text1ROI(162, 110, 157 , 129);
// recognize text
api.TesseractRect( imagen.data, 1, imagen.step1(), text1ROI.x, text1ROI.y, text1ROI.width, text1ROI.height);
const char *text1 = api.GetUTF8Text();
// remove "newline"
string t1(text1);
t1.erase( std::remove(t1.begin(), t1.end(), '\n'), t1.end() );
// print found text
printf("text: \n");
printf( "%s",t1.c_str() );
printf("\n");
// draw text on original image
Mat scratch = imread("/home/adrian/workspace/OCR/foto.jpg");
int fontFace = FONT_HERSHEY_PLAIN;
double fontScale = 2;
int thickness = 2;
putText(scratch, t1, Point(text1ROI.x, text1ROI.y), fontFace, fontScale, Scalar(0, 255, 0), thickness, 8);
rectangle(scratch, text1ROI, Scalar(0, 0, 255), 2, 8, 0);
imshow("tesseract-opencv", scratch);
}