Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 19, 2022 23:47
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 aspose-com-gists/41945dce2c829c0c2a99ccee0f7969c4 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/41945dce2c829c0c2a99ccee0f7969c4 to your computer and use it in GitHub Desktop.
Convert Image to Text using C++
std::string image_path = "sample_line.jpg";
// Prepare buffer for result (in symbols, len_byte = len * sizeof(wchar_t))
const size_t len = 4096;
wchar_t buffer[len] = { 0 };
int x = 138, y = 352, w = 2033, h = 537;
// Perform OCR or selected area
size_t size = aspose::ocr::page_rect(image_path.c_str(), buffer, len, x, y, w, h);
//Print result
std::wcout << buffer << L"\n";
std::string image_path = "sample_line.jpg";
// Prepare buffer for result (in symbols, len_byte = len * sizeof(wchar_t))
const size_t len = 4096;
wchar_t buffer[len] = { 0 };
// Perform OCR
size_t size = aspose::ocr::line(image_path.c_str(), buffer, len);
//Print result
std::wcout << buffer << L"\n";
std::string image_path = "sample.png";
// Prepare buffer for result (in symbols, len_byte = len * sizeof(wchar_t))
const size_t len = 4096;
wchar_t buffer[len] = { 0 };
// Perform OCR
size_t size = aspose::ocr::page(image_path.c_str(), buffer, len);
//Print result
std::wcout << buffer << L"\n";
@Octet3290
Copy link

Hello, Can you help me in explaining this code ?

@Octet3290
Copy link

I want to make a project in C++ that can convert image to text !

@aspose-com-gists
Copy link
Author

@Octet3290,

We suggest reading all the details at Convert Image to Text using C++ OCR Library.

In case you face any issues, please feel free to reach out to us at the forum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment