Считывание нескольких штрих-кодов с одного изображения с использованием php или javascript

Есть ли способ сканировать несколько штрих-кодов с одного изображения одновременно, используя PHP или JavaScript. Я гуглил, но могу сканировать только один штрих-код из изображения.

Я пробовал этот код: https://gist.github.com/tobytailor/421369

2

Решение

Если вы не можете найти хорошие SDK для PHP или JavaScript, вы можете попробовать некоторые из C / C ++ SDK. Я просто покажу вам пример того, как обернуть методы C / C ++ в JavaScript и PHP.

Вот изображение с несколькими штрих-кодами.
введите описание изображения здесь

Ты можешь использовать Dynamsoft Barcode SDK декодировать изображение и преобразовать все возвращаемые результаты в тип данных JavaScript или PHP.

Для JavaScript:

#include <node.h>

#include "If_DBR.h"#include "BarcodeFormat.h"#include "BarcodeStructs.h"#include "ErrorCode.h"

#ifdef _WIN64
#pragma comment(lib, "DBRx64.lib")
#else
#pragma comment(lib, "DBRx86.lib")
#endif

using namespace v8;

void SetOptions(pReaderOptions pOption, int option_iMaxBarcodesNumPerPage, int option_llBarcodeFormat){

if (option_llBarcodeFormat > 0)
pOption->llBarcodeFormat = option_llBarcodeFormat;
else
pOption->llBarcodeFormat = OneD;

if (option_iMaxBarcodesNumPerPage > 0)
pOption->iMaxBarcodesNumPerPage = option_iMaxBarcodesNumPerPage;
else
pOption->iMaxBarcodesNumPerPage = INT_MAX;

}

void DecodeFile(const FunctionCallbackInfo<Value>& args) {

Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);

// convert v8 string to char *
String::Utf8Value utfStr(args[0]->ToString());
char *pFileName = *utfStr;

int option_iMaxBarcodesNumPerPage = -1;
int option_llBarcodeFormat = -1;

pBarcodeResultArray pResults = NULL;
ReaderOptions option;
SetOptions(&option, option_iMaxBarcodesNumPerPage, option_llBarcodeFormat);

// decode barcode image file
int ret = DBR_DecodeFile(
pFileName,
&option,
&pResults
);

if (ret == DBR_OK){
int count = pResults->iBarcodeCount;
pBarcodeResult* ppBarcodes = pResults->ppBarcodes;
pBarcodeResult tmp = NULL;

// javascript callback function
Local<Function> cb = Local<Function>::Cast(args[1]);
const unsigned argc = 1;

// array for storing barcode results
Local<Array> barcodeResults = Array::New(isolate);

for (int i = 0; i < count; i++)
{
tmp = ppBarcodes[i];

Local<Object> result = Object::New(isolate);
result->Set(String::NewFromUtf8(isolate, "format"), Number::New(isolate, tmp->llFormat));
result->Set(String::NewFromUtf8(isolate, "value"), String::NewFromUtf8(isolate, tmp->pBarcodeData));

barcodeResults->Set(Number::New(isolate, i), result);
}

// release memory
DBR_FreeBarcodeResults(&pResults);

Local<Value> argv[argc] = { barcodeResults };
cb->Call(isolate->GetCurrentContext()->Global(), argc, argv);
}
}

void Init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "decodeFile", DecodeFile);
}

NODE_MODULE(dbr, Init)

введите описание изображения здесь

Для PHP:

#include "php_dbr.h"
#include "If_DBR.h"#include "BarcodeFormat.h"#include "BarcodeStructs.h"#include "ErrorCode.h"
#ifdef _WIN64
#pragma comment(lib, "DBRx64.lib")
#else
#pragma comment(lib, "DBRx86.lib")
#endif

void SetOptions(pReaderOptions pOption, int option_iMaxBarcodesNumPerPage, int option_llBarcodeFormat){

if (option_llBarcodeFormat > 0)
pOption->llBarcodeFormat = option_llBarcodeFormat;
else
pOption->llBarcodeFormat = OneD;

if (option_iMaxBarcodesNumPerPage > 0)
pOption->iMaxBarcodesNumPerPage = option_iMaxBarcodesNumPerPage;
else
pOption->iMaxBarcodesNumPerPage = INT_MAX;

}

ZEND_FUNCTION(DecodeBarcodeFile);

zend_function_entry CustomExtModule_functions[] = {
ZEND_FE(DecodeBarcodeFile, NULL)
{NULL, NULL, NULL}
};

zend_module_entry CustomExtModule_module_entry = {
STANDARD_MODULE_HEADER,
"Dynamsoft Barcode Reader",
CustomExtModule_functions,
NULL, NULL, NULL, NULL, NULL,
NO_VERSION_YET, STANDARD_MODULE_PROPERTIES
};

ZEND_GET_MODULE(CustomExtModule)

ZEND_FUNCTION(DecodeBarcodeFile){
array_init(return_value);

// Get Barcode image path
char* pFileName = NULL;
int iLen = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pFileName, &iLen) == FAILURE) {
RETURN_STRING("Invalid parameters", true);
}

// Dynamsoft Barcode Reader: init
int option_iMaxBarcodesNumPerPage = -1;
int option_llBarcodeFormat = -1;
pBarcodeResultArray pResults = NULL;
ReaderOptions option;

SetOptions(&option, option_iMaxBarcodesNumPerPage, option_llBarcodeFormat);

// decode barcode image file
int ret = DBR_DecodeFile(
pFileName,
&option,
&pResults
);

if (ret == DBR_OK)
{
int count = pResults->iBarcodeCount;
pBarcodeResult* ppBarcodes = pResults->ppBarcodes;
pBarcodeResult tmp = NULL;

// loop all results
for (int i = 0; i < count; i++)
{
tmp = ppBarcodes[i];

// convert format type to string
char format[64];
sprintf (format, "%d", tmp->llFormat);

// (barcode type, result)
add_assoc_string(return_value, format, tmp->pBarcodeData, 1);
}

// Dynamsoft Barcode Reader: release memory
DBR_FreeBarcodeResults(&pResults);
}
else
{
RETURN_STRING("No Barcode detected", true);
}

}

введите описание изображения здесь

Для получения более подробной информации вы можете обратиться к примеру кода из GitHub. https://github.com/Dynamsoft/Dynamsoft-Barcode-Reader/tree/master/samples/Node.js
https://github.com/Dynamsoft/Dynamsoft-Barcode-Reader/tree/master/samples/PHP

0

Другие решения

Вы также можете использовать API распознавания штрих-кода как тот из HP IDOL OnDemand (я работаю для HP). Я запустил изображение выше через онлайн-консоль для быстрого теста и смог извлечь следующую информацию из файла изображения …

{
"barcode": [
{
"text": "CODE128",
"barcode_type": "code-128",
"left": 1498,
"top": 552,
"width": 598,
"height": 262,
"additional_information": {}
},
{
"text": "CODE39",
"barcode_type": "code-39",
"left": 300,
"top": 552,
"width": 768,
"height": 262,
"additional_information": {}
},
{
"text": "0012345678905",
"barcode_type": "ean-13",
"left": 1480,
"top": 1466,
"width": 619,
"height": 260,
"additional_information": {
"country": "U.S. and Canada"}
},
{
"text": "1234567890128",
"barcode_type": "ean-13",
"left": 366,
"top": 1922,
"width": 584,
"height": 260,
"additional_information": {
"country": "U.S. (reserved for later use)"}
},
{
"text": "01234565",
"barcode_type": "ean-8",
"left": 1696,
"top": 2022,
"width": 390,
"height": 160,
"additional_information": {}
},
{
"text": "012345",
"barcode_type": "codabar",
"left": 300,
"top": 1010,
"width": 672,
"height": 260,
"additional_information": {}
},
{
"text": "CODE93",
"barcode_type": "code-93",
"left": 300,
"top": 1466,
"width": 730,
"height": 260,
"additional_information": {}
},
{
"text": "00123456",
"barcode_type": "i25",
"left": 1501,
"top": 1010,
"width": 264,
"height": 260,
"additional_information": {}
},
{
"text": "00",
"barcode_type": "i25",
"left": 1394,
"top": 1029,
"width": 242,
"height": 242,
"additional_information": {}
}
]
}
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector