Dynamsoft最近提供了支持MIPS64的一维码,二维码的C++ SDK。我在统信UOS上用C++和Python上做了测试,可以正常使用。
SDK下载
统信UOS环境配置
使用sudo apt update
的时候可能会碰到错误:无法安全地用该源进行更新,所以默认禁用该源
。解决方法是在/etc/apt/sources.list
中更换源deb https://mirrors.aliyun.com/debian stable main contrib non-free
。
C++识别一维码,二维码
创建一个CMake工程,包含CMakeLists.txt
,BarcodeReaderDemo.cpp
, DynamsoftBarcodeReader.h
, DynamsoftCommon.h
以及libDynamsoftBarcodeReader.so
。
CMakeLists.txt
文件很简单。配置一下头文件,库文件路径以及源文件:
cmake_minimum_required(VERSION 3.0.0)
project(BarcodeReaderDemo)
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/../include")
LINK_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/../lib")
add_executable(BarcodeReaderDemo BarcodeReaderDemo.cpp)
target_link_libraries (BarcodeReaderDemo "DynamsoftBarcodeReader")
C++的实现很简单:读取图片文件,调用文件解码接口:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fstream>
#include <streambuf>
#include <iostream>
#include <sstream>
#if defined(_WIN64) || defined(_WIN32)
#include <windows.h>
#include <conio.h>
#define snprintf sprintf_s
#else
#include <sys/time.h>
#endif
#include "DynamsoftBarcodeReader.h"
#include "DynamsoftCommon.h"
using namespace dynamsoft::dbr;
void decode(CBarcodeReader& reader, const char *file)
{
unsigned long ullTimeBegin = 0;
unsigned long ullTimeEnd = 0;
ullTimeBegin = GetTiming();
int ret = reader.DecodeFile(file, "");
ullTimeEnd = GetTiming();
OutputResult(reader, ret, (((float)(ullTimeEnd - ullTimeBegin)) / 1000));
}
int main(int argc, const char* argv[])
{
if (argc != 3)
{
printf("Usage: BarcodeReader <license_file> <image_file>\r\n");
return 0;
}
// License file
std::ifstream licenseFile(argv[1]);
std::stringstream strStream;
strStream << licenseFile.rdbuf();
std::string licenseStr = strStream.str();
// Image file
std::string sImageFile = argv[2];
BarcodeFormatSet iBarcodeFormatId = {
0,