0

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;
alvaroc
  • 433
  • 5
  • 14

1 Answers1

0

There is a way that takes three steps. It solved the problem and although requires user collaboration it seems less CPU intensive than trying to find the white rectangle

  1. Showing a frame for the user to read the code

App screen

  1. Crop the area. There is still a dark background that confuses ZXing

Cropped area

  1. Draw a thick white rectangle around the cropped image and pass it to ZXing's ScanManager. The leftmost black bar is not part of the label but the dark background. Still, ZXing scanned it fine (Shown again in blue)

White rectangle

Blue rectangle

A non coding solution is to place a white label before the silver one. Since many items had already been attached, it is no solution in this case, but I will definitely check in the future before putting the labels

Label over label

alvaroc
  • 433
  • 5
  • 14