源码:
// AspriseOCRDemo.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "DLL/asprise_ocr_api.h"
#include <iostream>
using namespace std;
void testOcr() {
// CHANGE TO THE ACTUAL PATH to the folder where the aocr.dll or aocr.so locates in
const char* libFolder = "LIB_FOLDER";
// CHANGE TO THE ACTUAL PATH to the input image, can be jpeg, gif, png, tiff or pdf.
//const char* fileImg = "PATH/1.png";//barcode
const char* fileImg = "PATH/opencvtutorials.png";
LIBRARY_HANDLE libHandle = dynamic_load_aocr_library(libFolder);
//cout << "chcp 65001" << endl;
// one time setup
int setup = c_com_asprise_ocr_setup(false);
if (setup != 1) {
cerr << "Failed to setup. code: " << setup << endl;
return;
}
// starts the ocr engine; the pointer must be of long long type
long long ptrToApi = c_com_asprise_ocr_start("eng", OCR_SPEED_SLOW, NULL, NULL, NULL);
if (ptrToApi == 0) {
cerr << "Failed to start." << endl;
return;
}
/*char* s = c_com_asprise_ocr_recognize(ptrToApi, fileImg, -1, -1, -1, -1, -1,
OCR_RECOGNIZE_TYPE_BARCODE, OCR_OUTPUT_FORMAT_PDF,
"PROP_PDF_OUTPUT_FILE=result.pdf|PROP_PDF_OUTPUT_TEXT_VISIBLE=true|\
PROP_PDF_OUTPUT_RETURN_TEXT=text", "|", "=");*/ //barcode
char* s = c_com_asprise_ocr_recognize(ptrToApi, fileImg, -1, -1, -1, -1, -1,
OCR_RECOGNIZE_TYPE_TEXT, OCR_OUTPUT_FORMAT_PDF,
"PROP_PDF_OUTPUT_FILE=result.pdf|PROP_PDF_OUTPUT_TEXT_VISIBLE=true|\
PROP_PDF_OUTPUT_RETURN_TEXT=text", "|", "=");
string ss = s;
cout << "Returned: " << ss << endl;
// do more recognition here ...
// finally, stops the OCR engine.
c_com_asprise_ocr_stop(ptrToApi);
cout << "Unload: " << (dynamic_unload_aocr_library(libHandle) ? "OK" : "Failed") << endl;
}
int main()
{
testOcr();
std::cout << "Press ENTER to exit: ";
std::cin.ignore();
return 0;
}
参考:
cike0cop/AspriseOCRDemo: AspriseOCRDemo (github.com)https://github.com/cike0cop/AspriseOCRDemo
免费在线条形码生成器-条码生成制作工具 (cnaidc.com)http://barcode.cnaidc.com/html/BCGcode128b.php