Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active October 8, 2022 09:50
Show Gist options
  • Save aspose-com-gists/1525478baca6911adec86bd0204d7142 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/1525478baca6911adec86bd0204d7142 to your computer and use it in GitHub Desktop.
Image to Text Conversion | Aspose.OCR for C++

Extract Text from Images BMP, JPG, GIF, PNG using C++ OCR Library

C++ codes listed below demonstrating how to extract text from image pages, specific areas of image or having single line information

More details at https://products.aspose.com/ocr/cpp/conversion/

Here is the list of all supported image formats https://docs.aspose.com/ocr/cpp/supported-file-formats/

For code integration there few prerequisite listed in installation section below.

Installation

Install from command line as nuget install Aspose.OCR.Cpp or via Package Manager Console of Visual Studio with Install-Package Aspose.OCR.Cpp.

Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads.

For further features of C++ OCR Library visit its detail documentation : https://docs.aspose.com/ocr/cpp/

std::string png_image_path = "sample.png";
// Prepare buffer for result (in symbols, len_byte = length * sizeof(wchar_t))
const size_t leng = 4096;
wchar_t bffr[leng] = { 0 };
// Perform OCR on Page
size_t size = aspose::ocr::page(png_image_path.c_str(), bffr, leng);
//Print result
std::wcout << bffr << L"\n";
std::string path = "sourceImage.jpg";
// Prepare buffer for result (in symbols, len_byte = length * sizeof(wchar_t))
const size_t leng = 4096;
wchar_t bfr[leng] = { 0 };
int x = 138, y = 352, w = 2033, h = 537;
// Perform OCR of page selected area
size_t size = aspose::ocr::page_rect(path.c_str(), bfr, leng, x, y, w, h);
//Print result
std::wcout << bfr << L"\n";
std::string path = "sample_image.jpg";
// Prepare buffer for result (in symbols, len_byte = len * sizeof(wchar_t))
const size_t leng = 4096;
wchar_t bffr[leng] = { 0 };
// Perform OCR to extract line text from image
size_t size = aspose::ocr::line(image_path.c_str(), bffr, leng);
//Print result
std::wcout << bffr << L"\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment