翻譯|使用教程|編輯:楊鵬連|2020-07-30 10:29:11.170|閱讀 558 次
概述:許多企業(yè)喜歡使用Dynamsoft Barcode Reader SDK,因?yàn)樗哂徐`活的參數(shù)配置和強(qiáng)大的對(duì)多個(gè)條形碼的解碼能力。在本文中,讓我們看一下條形碼SDK模板以及從開(kāi)發(fā)人員的角度優(yōu)化解碼性能的可能方法。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
Dynamsoft Barcode Reader SDK一款多功能的條碼讀取控件,只需要幾行代碼就可以將條碼讀取功能嵌入到Web或桌面應(yīng)用程序。這可以節(jié)省數(shù)月的開(kāi)發(fā)時(shí)間和成本。能支持多種圖像文件格式以及從攝像機(jī)或掃描儀獲取的DIB格式。使用Dynamsoft Barcode Reader SDK,你可以創(chuàng)建強(qiáng)大且實(shí)用的條形碼掃描儀軟件,以滿足你的業(yè)務(wù)需求。
點(diǎn)擊下載Dynamsoft Barcode Reader最新版
許多企業(yè)喜歡使用Dynamsoft Barcode Reader SDK,因?yàn)樗哂徐`活的參數(shù)配置和強(qiáng)大的對(duì)多個(gè)條形碼的解碼能力。在本文中,讓我們看一下條形碼SDK模板以及從開(kāi)發(fā)人員的角度優(yōu)化解碼性能的可能方法。
如何配置用于解碼性能的模板
如果您從未嘗試過(guò)Dynamsoft Barcode Reader SDK,則可以在在線條形碼游樂(lè)場(chǎng)玩耍,只需更改模式即可直接比較性能差異。
此外,如果您是專家,則可以單擊高級(jí)設(shè)置自行調(diào)整一系列參數(shù)。
為了方便開(kāi)發(fā)人員,我向Github上傳了五個(gè)有用的模板文件:
這是我的測(cè)試圖像:
我們來(lái)看一下使用不同模板的檢測(cè)準(zhǔn)確性和時(shí)間成本:
BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt speed.json Total barcode(s) found: 12. Time cost: 63 ms BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt balanced.json Total barcode(s) found: 13. Time cost: 140 ms BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt coverage.json Total barcode(s) found: 13. Time cost: 844 ms BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt morecoverage.json Total barcode(s) found: 13. Time cost: 1610 ms BarcodeReader.exe AllSupportedBarcodeTypes.png license.txt mostcoverage.json Total barcode(s) found: 13. Time cost: 3156 ms就我而言,要保證準(zhǔn)確性和解碼速度,最合適的模板是balance.json。
使用多線程可以加快多條形碼解碼的性能嗎?
按照我們的常識(shí),解碼單個(gè)條形碼的時(shí)間成本應(yīng)小于解碼多個(gè)條形碼的時(shí)間成本。因此,讀取多個(gè)條形碼的一種可能的優(yōu)化方法是創(chuàng)建多個(gè)工作線程,以同時(shí)處理不同的條形碼符號(hào)。
這是用于順序解碼一維和二維條形碼的代碼:
barcode_decoding(buffer, size, BF_CODE_39, 1, license, config);
barcode_decoding(buffer, size, BF_QR_CODE, 1, license, config);
barcode_decoding(buffer, size, BF_PDF417, 1, license, config);
barcode_decoding(buffer, size, BF_DATAMATRIX, 1, license, config);
總時(shí)間成本為407毫秒:
Thread id: 22536. Type: CODE_39 Thread id: 22536. Total barcode(s) found: 1. Time cost: 235 ms Thread id: 22536. Type: QR_CODE Thread id: 22536. Total barcode(s) found: 1. Time cost: 47 ms Thread id: 22536. Type: PDF417 Thread id: 22536. Total barcode(s) found: 1. Time cost: 62 ms Thread id: 22536. Type: DATAMATRIX Thread id: 22536. Total barcode(s) found: 1. Time cost: 63 ms為了優(yōu)化解碼性能,我可以創(chuàng)建四個(gè)線程來(lái)執(zhí)行相同的操作:
int starttime = gettime(); thread t1(barcode_decoding, buffer, size, BF_CODE_39, 1, license, config); thread t2(barcode_decoding, buffer, size, BF_QR_CODE, 1, license, config); thread t3(barcode_decoding, buffer, size, BF_PDF417, 1, license, config); thread t4(barcode_decoding, buffer, size, BF_DATAMATRIX, 1, license, config); t1.join(); t2.join(); t3.join(); t4.join(); int endtime = gettime(); printf("Thread time cost: %d ms\n\n", (endtime - starttime));最終時(shí)間成本為265毫秒:
Thread id: 24024. Type: QR_CODE Thread id: 24024. Total barcode(s) found: 1. Time cost: 78 ms Thread id: 17384. Type: DATAMATRIX Thread id: 17384. Total barcode(s) found: 1. Time cost: 78 ms Thread id: 24264. Type: PDF417 Thread id: 24264. Total barcode(s) found: 1. Time cost: 94 ms Thread id: 4060. Type: CODE_39 Thread id: 4060. Total barcode(s) found: 1. Time cost: 265 ms Thread time cost: 265 ms到目前為止,似乎還不錯(cuò)。但是,如果將多種條形碼類型傳遞給Dynamsoft條形碼解碼API,則會(huì)發(fā)生神奇的事情:
barcode_decoding(buffer, size, BF_CODE_39 | BF_DATAMATRIX | BF_QR_CODE | BF_PDF417, 1, license, config);
它比您自己的多線程解決方案快:
Thread id: 20308. Type: PDF417 Thread id: 20308. Type: QR_CODE Thread id: 20308. Type: DATAMATRIX Thread id: 20308. Type: CODE_39 Thread id: 20308. Total barcode(s) found: 4. Time cost: 250 ms
原因是所有Dynamsoft條形碼解碼API均在線程中實(shí)現(xiàn)。因此,您無(wú)需創(chuàng)建線程來(lái)優(yōu)化解碼性能。
線程數(shù)如何影響Dynamsoft Barcode SDK性能?您可能已經(jīng)注意到,有一個(gè)名為maxAlgorithmThreadCount的參數(shù)。我們可以通過(guò)增加線程數(shù)來(lái)提高SDK性能嗎?
我根據(jù)硬件線程做了一個(gè)簡(jiǎn)單的測(cè)試:
每次我運(yùn)行該應(yīng)用程序時(shí),都會(huì)得到不同的結(jié)果。通過(guò)使用我的測(cè)試圖像,性能沒(méi)有顯著差異:
const auto processor_count = std::thread::hardware_concurrency();
int minimum_count = 1, minimum_timecost = 0;
for (int i = 0; i < processor_count; i++)
{
printf("Thread count: %d. ", i + 1);
int timecost = barcode_decoding(buffer, size, formats, i, license, config);
if (i == 0)
{
minimum_count = 1;
if (timecost > 0)
{
minimum_timecost = timecost;
}
}
else {
if (timecost < minimum_timecost)
{
minimum_count = i + 1;
minimum_timecost = timecost;
}
}
}
printf("Multi-thread best performance: thread_count = %d, timecost = %d \n\n", minimum_count, minimum_timecost);
Thread count: 1. Thread id: 26376. Total barcode(s) found: 13. Time cost: 141 ms
Thread count: 2. Thread id: 26376. Total barcode(s) found: 13. Time cost: 141 ms
Thread count: 3. Thread id: 26376. Total barcode(s) found: 13. Time cost: 125 ms
Thread count: 4. Thread id: 26376. Total barcode(s) found: 13. Time cost: 140 ms
Thread count: 5. Thread id: 26376. Total barcode(s) found: 13. Time cost: 157 ms
Thread count: 6. Thread id: 26376. Total barcode(s) found: 13. Time cost: 203 ms
Thread count: 7. Thread id: 26376. Total barcode(s) found: 13. Time cost: 156 ms
Thread count: 8. Thread id: 26376. Total barcode(s) found: 13. Time cost: 140 ms
Multi-thread best performance: thread_count = 3, timecost = 125
顯然,一張測(cè)試圖像沒(méi)有任何意義。理想情況下,您應(yīng)該使用圖像數(shù)據(jù)集來(lái)衡量性能。因此,如果您有興趣,現(xiàn)在就去動(dòng)手吧。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: