3

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.

oberfreak
  • 1,799
  • 13
  • 20
user1081305
  • 51
  • 3
  • 5
  • See also http://stackoverflow.com/questions/8339612/zxing-sample-code-to-detect-qrcode-in-an-image. – rekire Dec 06 '11 at 05:46
  • If I read you well, you first want to detect *that* a QR code is in view and later (triggered by some user action?) read *what* is in there? – Gert Arnold Dec 06 '11 at 10:41
  • yes GertArnold that is what i want. – user1081305 Dec 07 '11 at 09:31
  • @user1081305: detecting the presence of a QR code must be possible with zxing, because that's what it does internally. I never did it. Look into the source if there is any public method that you can use. – Gert Arnold Dec 08 '11 at 09:30
  • i saw there is a seperate class called detector is avilable in side the Zxing. but they are giving bitmatrix as a input to the detector and i'm not able to convert the bitmap image into bitmatrix in c#.(i think it is avilable in java,i'm not sure).if u know how kindly let me know. – user1081305 Dec 08 '11 at 10:29

1 Answers1

2

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.";
        }
    }
eNaught
  • 81
  • 6