首页 > 解决方案 > 使用 ZXing 的 Delphi 版本解码旋转条码

问题描述

我从 ZXing 端口https://github.com/Spelt/ZXing.Delphi编译了网络摄像头示例

它工作正常,但我想扫描一维条形码,即使它们旋转 90 度,这样我就可以使用笔记本电脑的内置网络摄像头扫描代码,而不会将牛奶洒在键盘上 :)

这个库有一个“魔法”标志 TRY_HARDER 承诺在内部旋转图像。我这样使用它:

_hints: TDictionary<TDecodeHintType, TObject>;
_listFormats: TList<TBarcodeFormat>;
_scanManager: TScanManager;

_listFormats := TList<TBarcodeFormat>.Create();
_listFormats.Add(TBarcodeFormat.AUTO);

_hints := TDictionary<TDecodeHintType, TObject>.Create();
_hints.Add(POSSIBLE_FORMATS, _listFormats);
_hints.Add(TRY_HARDER, nil);
_scanManager := TScanManager.Create(TBarcodeFormat.AUTO, _hints);

一旦我添加了 TRY_HARDER 标志,库就完全停止识别代码。

该怎么办?

目前我通过在位图到达 TScanManager 之前旋转位图来解决这个问题:

_bmp: TBitmap;
_bmp90: TBitmap;

var ReadResult: TReadResult;

ReadResult := _scanManager.Scan(_bmp);
if ReadResult = nil then begin
  _rotateBmp90(_bmp, _bmp90);
  ReadResult := _scanManager.Scan(_bmp90);
end;

但我有一种轻微的感觉,它不是最佳的。CPU 使用率也从 10% 增加到 13%。

标签: zxingdelphi-10.4.2

解决方案


推荐阅读