- Install Emgucv library which is a version for C#.
- Create new WindowsFormsApplication on Visual Studio named QRCodedetection or whatever you want
- Copy Emgucv dll files (opencv_contrib231.dll etc)which are located in bin folder to your own project's bin folder
- Go to your project
- Project-> Add Reference-> Browse add opencv dll files which you copied before
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
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();}
Capture capture;And those variables should be declared
bool Capturing;
Bitmap bimap;
private Reader reader;
private Hashtable hint;
Now let's do decoding part.
- download zxing.dll file
- Copy to your project bin folder
- Add to your project same with emgucv
- Copy them top of your program
using com.google.zxing.qrcode;
using com.google.zxing.common;
and now you are possible to use zxing library . Copy below code to your main function
Image<Bgr, Byte> image = capture.QueryFrame();
if (image != null)
{
bimap = image.ToBitmap();
pictureBox1.Image = bimap;
reader = new QRCodeReader();
hint = new Hashtable();
hint.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
RGBLuminanceSource source = new RGBLuminanceSource(bimap, bimap.Width, bimap.Height);
BinaryBitmap img = new BinaryBitmap(new GlobalHistogramBinarizer(source));
Result result = null;
try
{
result = reader.decode(img, hint);
}
catch
{
}
if (result == null)
{
label1.Text = " no decode";
}
else
{
label1.Text = result.Text;
label2.Text = result.BarcodeFormat.ToString();
}
}
OK that's all
No comments:
Post a Comment