ZXing: Finding the bounding rectangle of Barcode

前端 未结 3 1973
走了就别回头了
走了就别回头了 2021-01-03 02:28

I was experimenting with ResultPoints which returns the points related to the barcode in the image.
For a QR Code, ResultPoints returns a set of 4 points which are the

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-03 03:21

    For QR codes: After studying the source code of ZXING I've found a simple solution for the problem. The resultsPoints of each qr code contain the following points in the following order:

    index 0: bottomLeft index 1: topLeft index 2: topRight

    So you can for example create your own class with the resultPoints as a constructor parameter to create objects that hold the qr code coordinates within an image. The following code is written in C# as we use Xamarin but the java code would look similar:

    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            
        }
    }
    

提交回复
热议问题