翻譯|使用教程|編輯:楊鵬連|2020-07-30 10:29:11.170|閱讀 558 次
概述:許多企業喜歡使用Dynamsoft Barcode Reader SDK,因為它具有靈活的參數配置和強大的對多個條形碼的解碼能力。在本文中,讓我們看一下條形碼SDK模板以及從開發人員的角度優化解碼性能的可能方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Dynamsoft Barcode Reader SDK一款多功能的條碼讀取控件,只需要幾行代碼就可以將條碼讀取功能嵌入到Web或桌面應用程序。這可以節省數月的開發時間和成本。能支持多種圖像文件格式以及從攝像機或掃描儀獲取的DIB格式。使用Dynamsoft Barcode Reader SDK,你可以創建強大且實用的條形碼掃描儀軟件,以滿足你的業務需求。
點擊下載Dynamsoft Barcode Reader最新版
許多企業喜歡使用Dynamsoft Barcode Reader SDK,因為它具有靈活的參數配置和強大的對多個條形碼的解碼能力。在本文中,讓我們看一下條形碼SDK模板以及從開發人員的角度優化解碼性能的可能方法。
如何配置用于解碼性能的模板
如果您從未嘗試過Dynamsoft Barcode Reader SDK,則可以在在線條形碼游樂場玩耍,只需更改模式即可直接比較性能差異。
此外,如果您是專家,則可以單擊高級設置自行調整一系列參數。
為了方便開發人員,我向Github上傳了五個有用的模板文件:
這是我的測試圖像:
我們來看一下使用不同模板的檢測準確性和時間成本:
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就我而言,要保證準確性和解碼速度,最合適的模板是balance.json。
使用多線程可以加快多條形碼解碼的性能嗎?
按照我們的常識,解碼單個條形碼的時間成本應小于解碼多個條形碼的時間成本。因此,讀取多個條形碼的一種可能的優化方法是創建多個工作線程,以同時處理不同的條形碼符號。
這是用于順序解碼一維和二維條形碼的代碼:
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);
總時間成本為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為了優化解碼性能,我可以創建四個線程來執行相同的操作:
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));最終時間成本為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到目前為止,似乎還不錯。但是,如果將多種條形碼類型傳遞給Dynamsoft條形碼解碼API,則會發生神奇的事情:
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均在線程中實現。因此,您無需創建線程來優化解碼性能。
線程數如何影響Dynamsoft Barcode SDK性能?您可能已經注意到,有一個名為maxAlgorithmThreadCount的參數。我們可以通過增加線程數來提高SDK性能嗎?
我根據硬件線程做了一個簡單的測試:
每次我運行該應用程序時,都會得到不同的結果。通過使用我的測試圖像,性能沒有顯著差異:
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
顯然,一張測試圖像沒有任何意義。理想情況下,您應該使用圖像數據集來衡量性能。因此,如果您有興趣,現在就去動手吧。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: