call SetImage before attempting recognition. ERROR

1,586 views
Skip to first unread message

adrian company

unread,
Oct 2, 2013, 3:37:32 AM10/2/13
to tesser...@googlegroups.com
Hi everybody,
I'm new with tesseract and I have created a project to use it and recognize characters from a ethernet camera. The problem is when I execute the program an error like this:
Please call SetImage before attempting recognition.Please call SetImage before attempting recognition.terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid


is returned. I' ve tried adding SetImage and the same error is given. Anybody knows what is the reason of that error? Any clue?

Thanks in advance.
I paste the code where I have the problem:

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);
           
}


adrian company

unread,
Oct 2, 2013, 4:59:31 AM10/2/13
to tesser...@googlegroups.com
Upps, I' ve found the error the path where is the picture was wrong :$. I have changed the path and it works now.
Reply all
Reply to author
Forward
0 new messages