I made a simple application to collect bar codes and downloading to a desktop app using ZXing and Delphi 10.3. The cell application runs fine but it does not recognize the labels when attached over dark backgrounds. I have plenty experience using Delphi and barcodes, but I´m a newbie with Android and ZXing. How can I get my cell app to scan such labels? I found a unit ZXing.Common.Detector.WhiteRectangleDetector that seems to address the issue but I don´t understand how interacts with or how can it be used with TScanManager
The code goes like this:
ScanManager := TScanManager.Create(TBarcodeFormat.CODE_128,Nil);
.
.
.
procedure TfrmMain.camMainSampleBufferReady(Sender: TObject; const ATime: MediaTime);
begin
camMain.SampleBufferToBitmap(SomeBitmap, True);
ReadResult := ScanManager.Scan(SomeBitmap);
If (Assigned(ReadResult)) Then
DoSomething()
end
Labels scanned outside the gray containers do it fine. But once attached they are no longer read. I attached one to my laptop and got the same result
Image here
Edit Based on ZXing: Finding the bounding rectangle of Barcode I made this small program:
program Rectangle;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
FMX.Graphics,
ZXing.Common.BitMatrix,
ZXing.BinaryBitmap,
ZXing.Common.Detector.WhiteRectangleDetector,
ZXing.LuminanceSource,
ZXing.HybridBinarizer,
ZXing.Binarizer,
ZXing.ResultPoint;
Var
barcodeBitmap : TBitmap;
luminanceSource : TLuminanceSource;
binarizer : THybridBinarizer;
bitMatrix : TBitMatrix;
whiterect : TWhiteRectangleDetector;
ResultPoint : TArray<IResultPoint>;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
barcodeBitmap := TBitmap.CreateFromFile('oscuro.jpg');
luminanceSource := TLuminanceSource.Create(barcodeBitmap.Width,barcodeBitmap.Height); // ?
binarizer := THybridBinarizer.Create(luminanceSource); // ?
bitMatrix := binarizer.BlackMatrix;
whiterect := TWhiteRectangleDetector.New(bitMatrix);
ResultPoint := whiterect.detect();
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
However, it seems there is no such unit in Delphi for:
var luminanceSource = new ZXing.BitmapLuminanceSource(barcodeBitmap);
The program crashes with an Abstract Error exception on
bitMatrix := binarizer.BlackMatrix;