【OCR】AspriseOCR 条码识别 C++

源码:

// 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)icon-default.png?t=M4ADhttps://github.com/cike0cop/AspriseOCRDemo

免费在线条形码生成器-条码生成制作工具 (cnaidc.com)http://barcode.cnaidc.com/html/BCGcode128b.php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值