Hi I am having issues with sending a Mat image the I have opened through 
OpenCV to Tesseract using the "SetImage" function.  
I can use Tesseract on the image when I just input the commented out bit at 
the end of the line as: SetImage(image);

however when I run it as below the program will crash before even reaching 
this point and return to console "segmentation error"

I have found this code as being identical to somebody who previously did my 
project, and i have no idea why this error is occurring.


Please if somebody can help me or provide a working example of Tesseract 
using Mats from OpenCv I would greatly appreciate it.

kind regards,

Adam


int main(int argc, char** argv )
{

imgOriginal = imread(argv[1],1);          // open image
Mat img = imgOriginal;

.........

        namedWindow("img", WINDOW_NORMAL); 
imshow("img", img);
waitKey(0);                 // hold window open until user presses a key

    char *outText;
    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
    // Initialize tesseract-ocr with English, without specifying tessdata 
path
    if (api->Init("/usr/share/tesseract-ocr", "eng")) {
        fprintf(stderr, "Could not initialize tesseract.\n");
        exit(1);
    }
    
    // Open input image with leptonica library
    Pix *image = 
pixRead("/home/pi/opencv/sudoku_capture/sudoku2/Sudoku.jpg");
    api->TesseractRect( img.data, 1, img.step1(), 0, 0, img.cols, img.rows);
    api->SetImage((uchar*)img.data, img.size().width, img.size().height, 
img.channels(), img.step1());        //image);
    api->Recognize(0);
    
    // Get OCR result
    outText = api->GetUTF8Text();
    printf("OCR output:\n%s", outText);

    // Destroy used object and release memory
    api->End();
    delete [] outText;
    //pixDestroy(&image);

-- 
You received this message because you are subscribed to the Google Groups 
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tesseract-ocr+unsubscr...@googlegroups.com.
To post to this group, send email to tesseract-ocr@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tesseract-ocr/5248e483-3f5c-4834-9c31-341b6873ffe5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to