ZXing: finding the bounding bar of a barcode

I experimented with ResultPoints, which returns the points associated with the barcode in the image.
For a QR code, ResultPoints returns a set of four points, which are the coordinates of the four fields in each corner of the QR code. When I experimented with a barcode, it returns two points that indicate the width of the barcode. How to find the bounding bar of a barcode? Is there a way I can calculate the coordinates of the upper left corner and lower right corner of the barcode using an array of ResultPoints?

After a little research, I found the WhiteRectangleDetector class. This was exactly what interested me, but when I started playing with him, it gave me partial results, but not exact results. I attached an image of the result obtained using the WhiteRectangleDetector, but, as we can see, it simply paints the middle part of the barcode, and not the entire rectangular part of the barcode. So I was wondering if I could obscure the entire rectangular part of the barcode.

My code is:

        barcodeBitmap = (Bitmap)Bitmap.FromFile("barcode-image.png");
        var luminanceSource = new ZXing.BitmapLuminanceSource(barcodeBitmap);
        var binarizer = new ZXing.Common.HybridBinarizer(luminanceSource);
        var bitMatrix = binarizer.BlackMatrix;

        var whiterect = WhiteRectangleDetector.Create(bitMatrix);

        ResultPoint[] whiterectpts = whiterect.detect();
        if (whiterectpts != null)
        {
            Console.WriteLine("\nWhiteRectangleDetector\n");
            foreach (var w in whiterectpts)
            {
                Console.WriteLine(w);
            }
            Rectangle whiterectangle = new Rectangle((int)whiterectpts[0].X, (int)whiterectpts[0].Y, (int)(whiterectpts[2].X - whiterectpts[1].X), (int)(whiterectpts[1].Y - whiterectpts[0].Y));
            img = Image.FromFile("barcode-image.png");
            g = Graphics.FromImage(img);
            g.DrawRectangle(pen, whiterectangle);
            img.Save("crop2.png");
        }

Image after cropping

+3
source share
3 answers

Through ResultPoints, you have sides of the barcode. Through the WhiteRectangleDetector (WRDet) you have the y coordinate of the vertex and the height of the barcode. Combining all this information, you get the exact coordinates!

Explicit exception:

  • left-top: y top WRDet, x ResultPoint
  • right-top: y top WRDet, x ResultPoint
  • left-bottom: y top WRDet + height WRDet, x ResultPoint
  • right-bottom: y top WRDet + height WRDet, x ResultPoint

ResultPoints WRDet, WRDet , -. :

public WhiteRectangleDetector(BitMatrix image, int initSize, int x, int y)

, x ResultPoint, y y .


, , WhiteRectangleDetector . , , . , 1D .

WhiteRectangleDetector 2D- ( ), , , , .

+1

, , , , : initSize WhiteRectangleDetector.java 1D -.

public WhiteRectangleDetector ( BitMatrix, int initSize, int x, int y) throws NotFoundException {...}

: WhiteRectangleDetector 1D / QR-? MonochromeRectangleDetector?

0

QR-: ZXING, . qr- :

0: bottomLeft 1: topLeft index 2: topRight

, , , resultPoints , qr . #, Xamarin, java :

public class QRCodeCoordinates
{
    public float X1 { get; set; }
    public float X2 { get; set; }
    public float Y1 { get; set; }
    public float Y2 { get; set; }

    public QRCodeCoordinates(ZXing.ResultPoint[] resultPoints)
    {
        this.X1 = resultPoints[0].X; // index 0: bottom left
        this.X2 = resultPoints[2].X; // index 2: top right
        this.Y1 = resultPoints[2].Y; // index 2: top right
        this.Y2 = resultPoints[0].Y; // index 0: bottom left            
    }
}
0

All Articles