This project has moved. For the latest updates, please go here.

Finding height of the barcode

Feb 3, 2014 at 5:27 PM
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 coordinates of the four boxes at each corner of the QR Code.
When I experimented the same with a Barcode, it returns two points which denote the width of the barcode.
How do I find the height of the barcode?
Is there any way by which I can calculate the coordinates of the top left corner and bottom right corner of the barcode using the ResultPoints array?

Thanks in advance.
Feb 3, 2014 at 7:23 PM
Edited Feb 3, 2014 at 7:24 PM
Ok, so after a bit of research I found the class WhiteRectangleDetector. It was exactly the thing I was interested in but when I started playing around with it, it gave me partial results but not exact results.
I have attached an image of the result obtained by using WhiteRectangleDetector but as we can see, it just colors the middle portion of the barcode and not the whole rectangular portion of the barcode. So I was wondering if I could be able to shade the whole rectangular portion of the barcode.

My code:
            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)
                foreach (var w in whiterectpts)
                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);
Image found here

Please help me out.