akorentlab / tesseract-ocr

Automatically exported from code.google.com/p/tesseract-ocr
Other
0 stars 0 forks source link

How do I recognize image just in memory? #837

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
String RecognizeImage(Stream *pImageStream, int width, int height, int 
bytes_per_pixel, int bytes_per_line)
{
    tesseract::TessBaseAPI api;  

    String StartupPath = AppBase::GetStartupPath();
    api.Init(StartupPath.ToMultiByte(), "eng", tesseract::OEM_DEFAULT);  
    api.SetVariable("tessedit_char_whitelist", "123456789");  

    api.SetImage((const unsigned char *)pImageStream->GetObjectData(), width, height, bytes_per_pixel, bytes_per_line);//How do I use api.SetImage() correctly?Because I got bad output in this way.(pImageStream->GetObjectData() is the data of bmp without header)
    char *presult = api.GetUTF8Text(); 
    api.End();
    if (presult != nullptr)  
    {  
        StartupPath.Copy(presult);
#ifndef _DEBUG
        delete[] presult;//linked libtesseract302-static.lib 
#endif // _DEBUG
        return StartupPath.TrimEnd();
    }
    return Nothing;  
}

String RecognizeImageFile(String ImageFile)
{
    tesseract::TessBaseAPI api;  

    String StartupPath = AppBase::GetStartupPath();
    api.Init(StartupPath.ToMultiByte(), "eng", tesseract::OEM_DEFAULT);  
    api.SetVariable("tessedit_char_whitelist", "123456789");  

    STRING text_out;
    Path ImageFilePath(ImageFile);  
    if (api.ProcessPages(ImageFilePath.GetDosPath().ToMultiByte(), NULL, 0, &text_out))  
    {  
        ImageFile.Copy(text_out.string());
        return ImageFile.Trim();//It work!But I don't want to use any files.
    }
    return Nothing;  
}

Original issue reported on code.google.com by rlib2014@gmail.com on 28 Jan 2013 at 12:21

GoogleCodeExporter commented 9 years ago
Issue tracker is not for putting questions[1]. Use forum for it.

[1] http://code.google.com/p/tesseract-ocr/wiki/FAQ#Rules_and_advices

Original comment by zde...@gmail.com on 28 Jan 2013 at 7:50