I'm working on an app, and I need a way to extract numbers from images similar to how banking apps extract your credit card number from a picture. I don't have any preference on language but probably Python would be more useful.


You could look at using the LEADTOOLS SDK to perform OCR, on images for text and numbers. Here is a small code snippet in C API which you could probably connect to a python application in some way. As a disclaimer, this is a paid for SDK and I work for the vendor.


   BITMAPHANDLE bitmap = { 0 }; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrPage ocrPage = NULL; 
   // Create an instance of the engine 
   std::wcout << L"Creating OCR engine instance...\n"; 
   L_INT retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
   // Start the engine using default parameters 
   std::wcout << L"Starting up OCR engine...\n"; 
   L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR); 
   // Load an image to process 
   std::wcout << L"Loading page to process...\n"; 
   L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
   // Create an OCR page to handle processing 
   L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL); 
   // Transfer ownership 
   bitmap.Flags.Allocated = 0; 
   // Find text in the image 
   std::wcout << L"Finding text within page...\n"; 
   L_OcrPage_AutoZone(ocrPage, NULL, NULL); 
   // Recognize the text 
   std::wcout << L"Recognizing the text...\n"; 
   L_OcrPage_Recognize(ocrPage, NULL, NULL); 
   // Loop through zones and output the text 
   L_UINT zoneCount = 0; 
   L_OcrPage_GetZoneCount(ocrPage, &zoneCount); 
   std::wcout << L"Zone count: " << zoneCount << std::endl; 
   std::wcout << L"Show recognized text:\n"  
      << L"**********************************************\n"; 
   for(L_UINT zoneIndex = 0; zoneIndex < zoneCount; zoneIndex++) 
      L_WCHAR* text = NULL; 
      L_UINT textLength = 0; 
      L_OcrPage_GetText(ocrPage, zoneIndex, &text, &textLength); 
      std::wcout << text << std::endl; 
   std::wcout << L"**********************************************\n"; 
   std::wcout << L"Disposing of resources used..."; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.