Wednesday, November 16, 2011

How to detect and decode QR code using Emgucv and Zxing library

  1. Install Emgucv library which is a version for C#. 
  2. Create new WindowsFormsApplication on Visual Studio named QRCodedetection or whatever you want
  3. Copy Emgucv dll files (opencv_contrib231.dll etc)which are located in bin folder to your own project's bin folder
  4. Go to your project 
  5. Project-> Add Reference-> Browse  add opencv dll files which you copied before
Now lets make Application GUI:
Go to your project designer part. And add one button which is named captureButton to capture a stream, UImageBox to display captured video. and make 2 label to see the result of decoded qrcode.
Double click in your button on designer and copy below 
     if (capture == null)
            {
                try
                {
                    capture = new Capture();
                }
                catch (NullReferenceException exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }
            if (capture != null)
            {
                if (Capturing)
                {
                    captureButton.Text = "Start Capture";
                    Application.Idle -= Main;
                }
                else
                {
                    captureButton.Text = "Stop Capture";
                    Application.Idle += Main;
                }
                Capturing = !Capturing;
            }
        }
        private void Release()
        {
            if (capture != null)
                capture.Dispose();
        }    

And those variables should be declared 
        Capture capture;
        bool Capturing;
        Bitmap bimap;
        private Reader reader;
        private Hashtable hint;

Now let's do decoding part.


  1. download zxing.dll file 
  2. Copy to your project bin folder
  3. Add to your project same with emgucv
  4. Copy them top of your program