如何使用参数优化Dynamsoft Barcode Reader解码性能

许多企业喜欢使用Dynamsoft Barcode Reader SDK,因为它具有灵活的参数配置和强大的对多个条形码的解码能力。在本文中,让我们看一下条形码SDK模板以及从开发人员的角度优化解码性能的可能方法。

如何配置用于解码性能的模板

如果您从未尝试过Dynamsoft Barcode Reader SDK,则可以在在线条形码游乐场玩耍,只需更改模式即可直接比较性能差异。
æ¡ç è§£ç æ€§èƒ½çš„æ¨¡æ¿

此外,如果您是专家,则可以单击高级设置自行调整一系列参数。

为了方便开发人员,我向Github上传了五个有用的模板文件:

Speed.json
Balanced.json
Coverage.json
Morecoverage.json
Mostcoverage.json
解码速度还是解码精度?您可以权衡取舍,具体取决于特定的使用方案。
这是我的测试图像:
æ‰€æœ‰æ¡å½¢ç ç±»åž‹

我们来看一下使用不同模板的检测准确性和时间成本:

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

显然,一张测试图像没有任何意义。理想情况下,您应该使用图像数据集来衡量性能。因此,如果您有兴趣,现在就去动手吧。

本文章转载自【慧都科技】。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,尊重他人劳动成果

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值