How to Refine Image to Read a License Plate

I've written a few posts recently on figurer vision and optical character recognition. This fourth dimension, I idea I'd write about a more traditional mode of allowing computers to read printed information – barcode scanning.

I've run across a few instances in my career where applications have a need for this – for example, scanning stock inventory in and out of a warehouse. The traditional fashion of doing this would be to apply a hardware barcode scanner connected to a computer.  These are basically the aforementioned engineering as you'd see at your local supermarket – the scanner is pointed at the item'south barcode (usually a one-D barcode), and when a valid barcode is detected, the textual representation of the code is piped to the computer'due south cursor (often finishing with a newline graphic symbol).

WP_20160402_20_05_41_Pro_LI

In the barcode scanner shown above, I didn't demand to install any software to my Windows x computer – non fifty-fifty a driver, or an SDK. Getting this to work was easy – open notepad, point the scanner at the barcode, clasp the scanner'due south trigger and the numeric representation of the barcode appears in notepad, with a newline graphic symbol at the cease.

What about reading and writing barcodes in C#?

A barcode scanner might not be always exist suitable for our applications – you may already take a digital image, and desire to know what this barcode represents in English text. As well, this scanner only reads 1-D barcodes, which agree a small corporeality of data. 2-D barcodes (sometimes known as QR codes) are now common, which can hold a lot more information.

There's several .Net solutions available to allow us to read barcodes from an prototype- the i I'm going to look at today is ZXing.Internet. This is a .Net port of a Coffee project, and it's available on Nuget under the Apache 2 licence at a beta status.

Let's look at some examples and lawmaking.

Reading Barcodes with ZXing.NET in C#

Offset thing is to import the ZXing.NET nuget package into your projection.

            Install-Parcel ZXing.Net                      

Next, allow's get a barcode – I've uploaded a PNG of the QR barcode that I desire to decode.

qrimage

Nosotros tin employ the code beneath to read from this image from my desktop:

            staticvoid Main(cord[] args) {// create a barcode reader instancevar barcodeReader=newBarcodeReader();// create an in retentivity bitmapvar barcodeBitmap= (Bitmap)Bitmap            .FromFile(@"C:\Users\jeremy\Desktop\qrimage.bmp");// decode the barcode from the in memory bitmapvar barcodeResult= barcodeReader.Decode(barcodeBitmap);// output results to consoleConsole            .WriteLine($"Decoded barcode text:{barcodeResult?.Text}");Console            .WriteLine($"Barcode format:{barcodeResult?.BarcodeFormat}"); }

The output on the console shows that this barcode contains a link to my twitter feed, and correctly identifies the format equally a QR code:

Decoded barcode text: https://twitter.com/jeremylindsayni Barcode format: QR_CODE

At that place's more nearly the dissimilar barcode formats here.

The code above isn't an example of best practice – it's but just to show how to read a barcode.

Writing Barcodes with ZXing.Net in C#

Let'south suppose we want to programmatically generate a barcode in C# – it's pretty piece of cake to do this as well.

Say we want to generate a QR code of a link to my web log –

            staticvoid Master(string[] args) {// instantiate a writer objectvar barcodeWriter=newBarcodeWriter();// ready the barcode format            barcodeWriter.Format=BarcodeFormat            .QR_CODE;// write text and generate a two-D barcode as a bitmap            barcodeWriter.Write("https://jeremylindsayni.wordpress.com/").Save(@"C:\Users\jeremy\Desktop\generated.bmp"); }

The output shown below:

generated

Determination

I hope this is helpful to anyone trying to read or generate barcodes – the code is pretty unproblematic. Every bit I mentioned higher up, ZXing.Internet is licenced under the Apache two licence and is open up sourced at Codeplex. I more thing that is worth mentioning is that at the fourth dimension of writing, it's still in beta and the present nuget package – version 0.14.0.1 – hasn't been updated since April 2014.

yorkperaweltake.blogspot.com

Source: https://jeremylindsayni.wordpress.com/2016/04/02/how-to-read-and-create-barcode-images-using-c-and-zxing-net/

0 Response to "How to Refine Image to Read a License Plate"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel