Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting QR code using zxing

Tags:

c#

zxing

I'm working on detecting the qrcode. My requirement is when the user show’s his/her QR code to the camera, the program has to detect and draw one box around the QR code. I’m using zxing library + C#. I searched many things but I’m not able to find any samples in this. Kindly anyone help me in this.

like image 736
user1081305 Avatar asked Aug 21 '26 16:08

user1081305


1 Answers

You can use the detector class for this. The detector constructor takes a BitMatrix object as its sole argument which can be obtained from the BlackMatrix property of the BinaryBitmap object...

public string Detect(Bitmap bitmap)
    {
        try
        {
            com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
            var binarizer = new HybridBinarizer(source);
            var binBitmap = new BinaryBitmap(binarizer);
            BitMatrix bm = binBitmap.BlackMatrix;
            Detector detector = new Detector(bm);
            DetectorResult result = detector.detect();

            string retStr = "Found at points ";
            foreach (ResultPoint point in result.Points)
            {
                retStr += point.ToString() + ", ";
            }

            return retStr;
        }
        catch
        {
            return "Failed to detect QR code.";
        }
    }
like image 140
eNaught Avatar answered Aug 24 '26 06:08

eNaught



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!