Dynamsoft Barcode Reader SDK一款多功能的條碼讀取控件,只須要幾行代碼就能夠將條碼讀取功能嵌入到Web或桌面應用程序。這能夠節省數月的開發時間和成本。能支持多種圖像文件格式以及從攝像機或掃描儀獲取的DIB格式。使用Dynamsoft Barcode Reader SDK,你能夠建立強大且實用的條形碼掃描儀軟件,以知足你的業務需求。html
點擊下載Dynamsoft Barcode Reader最新版json
許多企業喜歡使用Dynamsoft Barcode Reader SDK,由於它具備靈活的參數配置和強大的對多個條形碼的解碼能力。在本文中,讓咱們看一下條形碼SDK模板以及從開發人員的角度優化解碼性能的可能方法。多線程
如何配置用於解碼性能的模板性能
若是您從何嘗試過Dynamsoft Barcode Reader SDK,則能夠在在線條形碼遊樂場玩耍,只需更改模式便可直接比較性能差別。
此外,若是您是專家,則能夠單擊高級設置自行調整一系列參數。測試
爲了方便開發人員,我向Github上傳了五個有用的模板文件:優化
- Speed.json
- Balanced.json
- Coverage.json
- Morecoverage.json
- Mostcoverage.json
解碼速度仍是解碼精度?您能夠權衡取捨,具體取決於特定的使用方案。spa
這是個人測試圖像:
咱們來看一下使用不一樣模板的檢測準確性和時間成本:線程
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。code
使用多線程能夠加快多條形碼解碼的性能嗎?orm
按照咱們的常識,解碼單個條形碼的時間成本應小於解碼多個條形碼的時間成本。所以,讀取多個條形碼的一種可能的優化方法是建立多個工做線程,以同時處理不一樣的條形碼符號。
這是用於順序解碼一維和二維條形碼的代碼:
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
顯然,一張測試圖像沒有任何意義。理想狀況下,您應該使用圖像數據集來衡量性能。所以,若是您有興趣,如今就去動手吧。
本文章轉載自【慧都科技】。歡迎任何形式的轉載,但請務必註明出處、不得修改原文相關連接,尊重他人勞動成果