Reading multiple barcode in an image

Mar 27, 2012 at 7:27 AM

Hi,

Does the IBarcodeReader.Decode() function reads all the barcodes there are on an image?

If so, how do I read back the coordinates for each barcode?

Thanks.

 

boonlong

Coordinator
Mar 27, 2012 at 10:53 AM

No, it doesn't return ALL barcodes at once. It returns the first barcode which could be found and decoded without an error.

The coordinates are returned via the callback delegate ResultPointCallback.
The Windows Forms demo client shows how you can use it.

https://zxingnet.svn.codeplex.com/svn/trunk/Clients/WindowsFormsDemo

Mar 28, 2012 at 3:11 AM

Ah... it would be great if it could return all the barcodes found and the rectangles in an array.

Maybe u can put this in the wish list for future?

Thanks for the reply.

Coordinator
Mar 28, 2012 at 8:00 AM

I'm not sure that I would implement such a feature.
The current API is very close to the original java version. I want to stay as near as possible to the java version. It makes it easier to port future changes from java to C#.
A second problem is the scanning speed. At the moment the decoding calls return as fast as possible if a result is found. If the library should look for all barcodes within an image it would take much longer. The library doesn't know how many barcodes are within the image. It doesn't know which types of barcodes are within. In the worst case it has to scan the whole picture with all available barcode readers.

What are the use cases you have in mind for multiple barcodes within one image?

If I understand what you want to do it would be possible that I will find a solution for that.

May 26, 2012 at 4:50 PM

One solution to this might be using a computer vision package like AForge.net to detect each barcode image and return their coordinates, which can then be passed to ZXing.net for decoding. AForge is a small dependency, is pretty fast, and easy to learn (in my experience), so I suggest giving it a shot.

Coordinator
May 26, 2012 at 5:49 PM

Nice idea.

It would be nice if someone find the time to build such a solution on top of zxing.net.
The solution should be a separate assembly in my opinion.

Jun 5, 2012 at 4:09 AM

Wouldn't it be better to add this as a new function? 

E.g. have a DecodeMany() function to read many barcodes.

Coordinator
Jun 5, 2012 at 6:52 PM

That could be one way. But I hate dependencies which are only for a small number of users necessary.
If it stay inside an own assembly it is easier to maintain. Users can decide if they want to use only the core library without external dependencies or some additional assemblies.

But the main problem is not the method which needs to be added. The challenge is the algorithm behind the method which has to find the barcodes inside the image. You don't know the number of barcodes or the location of them. How deep should the algo look into the image? ...

Coordinator
Jul 12, 2012 at 6:08 AM

What a shame, I don't know my own port of the library.

The zxing team implemented a multiple barcode reader for QR Code. I didn't test it.
The reader can be found below the namespace ZXing.Multi.

Aug 1, 2012 at 4:37 AM

I tried the functions in ZXing.Multi but it crashed.

Have to find some time to try and debug it.

Coordinator
Aug 1, 2012 at 8:10 PM

I fixed the bug. You can get the working source code from the repository.

Aug 2, 2012 at 4:03 AM

Thanks.

Aug 2, 2012 at 10:44 AM

Hi,

I'm just built the latest one...no luck here.. I may wrong but can someone provide me a working sample for GenericMultipleBarcodeReader...

Thx

Coordinator
Aug 2, 2012 at 2:41 PM

What means "no luck here"?
Did you get an error or no results? Can you post the source code which you wrote?

Aug 3, 2012 at 1:35 AM

I'm having problem binarizing the bitmap.

How do u get the LuminanceSource from a Bitmap?

I tried using RGBLuminanceSource but when calling the decode, it said "does not support rotation" or something like that.

Aug 3, 2012 at 6:58 AM

hi,

thx for the quick response.

I meant no results.

here is my code :

QRCodeMultiReader QRreader = new QRCodeMultiReader();

GenericMultipleBarcodeReader reader = new GenericMultipleBarcodeReader(QRreader);

LuminanceSource source = new RGBLuminanceSource(BitmapImage2Bitmap(bmp));

BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

var i = reader.decodeMultiple(bitmap);

bmp is a bitmap that I can read with the „single” reader.

rgds

From: micjahn [email removed]
Sent: Thursday, August 02, 2012 4:41 PM
To: xbpass@hotmail.com
Subject: Re: Reading multiple barcode in an image [ZXingNet:350156]

From: micjahn

What means "no luck here"?
Did you get an error or no results? Can you post the source code which you wrote?

Coordinator
Aug 3, 2012 at 7:08 PM

Please send me your sample barcode image.

What does BitmapImage2Bitmap do?

Aug 6, 2012 at 7:09 AM

Hello

here is my Bitmap converter

private Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)

{

// BitmapImage bitmapImage = new BitmapImage(new Uri("../Images/test.png", UriKind.Relative));

using (MemoryStream outStream = new MemoryStream())

{

BitmapEncoder enc = new BmpBitmapEncoder();

enc.Frames.Add(BitmapFrame.Create(bitmapImage));

enc.Save(outStream);

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);

return new Bitmap(bitmap);

}

}

here is my test image :

https://profile.live.com/cid-e5a927e9dc61ea1e/?wlexpid=26D130C6050A4C39BC0D70678000D1BA&wlrefapp=2#!https://skydrive.live.com/?sc=photos&cid=e5a927e9dc61ea1e!cid=E5A927E9DC61EA1E&id=E5A927E9DC61EA1E%21619&sc=photos

From: micjahn [email removed]
Sent: Friday, August 03, 2012 9:09 PM
To: xbpass@hotmail.com
Subject: Re: Reading multiple barcode in an image [ZXingNet:350156]

From: micjahn

Please send me your sample barcode image.

What does BitmapImage2Bitmap do?

Coordinator
Aug 7, 2012 at 2:58 PM

I could decode the barcodes within the image. You have to set the TryHarder hint to true. Or without it the image has to be rotated.
But you will only get one result because both barcodes have the same content.

Coordinator
Aug 7, 2012 at 3:02 PM

@long1000

multiple barcode reader needs support for cropping. The patch is already within the repository and will released with version 0.8.

Aug 8, 2012 at 6:43 AM

hello

ok, thank you very much, I’ll try out and let you know

bt


Gabor

From: micjahn [email removed]
Sent: Tuesday, August 07, 2012 4:58 PM
To: xbpass@hotmail.com
Subject: Re: Reading multiple barcode in an image [ZXingNet:350156]

From: micjahn

I could decode the barcodes within the image. You have to set the TryHarder hint to true. Or without it the image has to be rotated.
But you will only get one result because both barcodes have the same content.

Aug 9, 2012 at 2:02 PM
micjahn wrote:

@long1000

multiple barcode reader needs support for cropping. The patch is already within the repository and will released with version 0.8.

Ok, will wait for 0.8

Thanks.

Coordinator
Aug 22, 2012 at 7:22 AM
Edited Aug 23, 2012 at 9:08 PM

Version 0.8 is available.

The new version supports BitmapImage instances directly via BitmapSourceLuminanceSource.
No need for BitmapImage2Bitmap anymore.

Decoding of multiple barcodes can be done via BarcodeReader now.

Aug 25, 2012 at 2:31 AM
Edited Aug 25, 2012 at 2:40 AM

i test in version 0.8 already will done.

Aug 27, 2012 at 5:12 AM
Edited Aug 27, 2012 at 5:13 AM

I downloaded the latest copy but when compiling, there are some errors.

E.g. in func.cs, line 24, it says "Type expected" and also, "Identifier expected"

The same error also occurs in line 32, 42, 54.

In IBarcodeWriterGeneric.cs, line 24

"Error 7 Invalid token 'out' in class, struct, or interface member declaration"

and some other error.

Anybody having the same problem? Can advise?

I'm using VS2008.

Thanks.

Coordinator
Aug 27, 2012 at 9:12 AM

I declared the type parameter of the generic declaration as covariant (out keyword).

But that language feature is only supported by visual studio 2010 and above.

http://msdn.microsoft.com/en-us/library/dd469487%28v=vs.100%29.aspx

Aug 28, 2012 at 2:35 AM

Is it possible to not use it? I do not have VS2010.

Also, am not intending to use .NET 4.0

Thanks.

Coordinator
Aug 28, 2012 at 7:30 PM

Can you use the prebuild binaries? If not it should be possible for you to remove the out keyword.
It is a language feature not restricted to .Net 4.0. Please try to remove the out keyword. Drop a post here if it doesn't work.

Sep 4, 2012 at 3:46 AM
micjahn wrote:

Can you use the prebuild binaries? If not it should be possible for you to remove the out keyword.
It is a language feature not restricted to .Net 4.0. Please try to remove the out keyword. Drop a post here if it doesn't work.

I've removed "in" and "out" and can compile now.

Thanks.

 

Is there are sample on how to use the multiple barcode reader? I tried the code below but it gave me error:

        private readonly IMultipleBarcodeReader multiReader;

            multiReader = new MultiFormatReader();

Error:

Cannot implicitly convert type 'ZXing.MultiFormatReader' to 'ZXing.IMultipleBarcodeReader'

 

I did not see any DecodeMultiple function in BarcodeReader.

Thanks

Coordinator
Sep 4, 2012 at 7:35 PM
Edited Sep 4, 2012 at 7:38 PM

The MultiFormatReader isn't the "MultipleDecodeReader".

Please use the following code:

var reader = new BarcodeReader();
var result = reader.DecodeMultiple(bitmap);

The interface IMultipleBarcodeReader is missing at BarcodeReader. My mistake. But the functionality is there. And the generic version of the interface works, too.

If you want to do it by hand you have to use the class ZXing.Multi.GenericMultipleBarcodeReader or ZXing.Multi.QrCode.QRCodeMultiReader.

Sep 5, 2012 at 3:25 AM

Thanks Mic. Its working now.

Btw, I notice the that multiple barcode reader does not always read all the barcodes in the image especially if the barcodes are on the same row.

I presume this is the current limitation?

Coordinator
Sep 5, 2012 at 8:05 PM

Yes, there are some limitations. Perhaps there are some bugs, too.

Feel free to optimize it.

Apr 22, 2013 at 1:46 PM
Edited Apr 22, 2013 at 2:09 PM
Hi Guys, i'm trying to use zxing to read a barcode from a TIFF file but it keeps giving me this error:
 java.lang.NullPointerException
at com.google.zxing.client.j2se.BufferedImageLuminanceSource.<init>(BufferedImageLuminanceSource.java:39)
it works almost perfect with JPG files but doesnt work on TIFF, anybody knows why?
Coordinator
Apr 23, 2013 at 8:26 PM
The main problem: this discussion list is for the C#/.Net based version of zxing. You are using the original java one.
I'm not sure if I can really help you, but make sure that the BufferedImage which you have to use for the constructor isn't null.
Perhaps the image loader classes of J2SE doesn't support TIFF which results in an uninitialized BufferedImage.