Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
snarasimhan
Posts: 24
Registered: ‎08-04-2010
My Device: Not Specified

ZXING Barcode Scanning API for OS 5.0

Hi all,

 

I know that we have barcode scanning api in JDE 6.0. But could someone help me with the exact procedure as to how we can use ZXING barcode scanning api for 5.0? I went through some of the links available, but haven't been able to get it working!

 

Thanks,

Suhas

Please use plain text.
Developer
IK828
Posts: 132
Registered: ‎11-20-2009
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

Were you able to get any answers for this? I am also wondering the same thing

Please use plain text.
Developer
diegotori
Posts: 50
Registered: ‎01-07-2010
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

[ Edited ]

You guys have to integrate ZXing core and the RIM specific bits into your app (better off just importing the ZXing library classes into your project).

 

Also, disregard the J2ME Image-specific LuminanceSource class, since it isn't as effective as using a native Bitmap subclass, which you have to implement on your own. In other words, J2ME Image's setRGB() in LCDUIImageLuminanceSource is almost identical to Bitmap's setARGB(), so it should be trivial to create a LuminanceSource subclass to support Bitmap instead of Image. Then, just find a way to create a Bitmap object from the captured image file (open file, get the file's inputstream to create EncodedImage, and then get that object's Bitmap). As a result of using Bitmap, I was able to scan 1D (w. auto-focus camera of course), and processing times decreased.

 

Also, make sure that the FileSystemJournalListener is removed only when you have an image file path (i.e. ends with ".jpg"), since there are cases where it sends back other non-image paths, or it sends image paths where it doesn't start with "IMG", since I recently saw this on the BB Torch when geotagging is enabled when capturing an image.

 

Finally, do not use the threading routines in the test app verbatim, since they are running on the Event Thread and that's a big no-no for a heavy task such as this one. Instead, spin them off as a separate Thread, and just get the event lock to close screens and so forth within it. Also, this task can hang if processing a large image, so you should find a way to check if it timed out (second watchdog thread to check if it's still processing).

Please use plain text.
Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

Diego, thanks for all your advices. It would be awesome if you could share your BitmapLuminaceSource with us.

 

I'm developing an application with 1D barcode reader that should support OS versions less than 5.0. I got it working but it's very hard to take a decent picture with these devices, actually I was able to decode only large barcode images from the internet.

 

Somebody told me that would be better to do a continuous scan rather than taking only one photo of the barcode, but I don't know how to do that, I'm new in using ZXing. Do you know anything about this approach?

 

Thank you.

 

Regards,

dan

Please use plain text.
Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

[ Edited ]

I got mine working doing what this guy said:

 

http://supportforums.blackberry.com/t5/Java-Development/Barcode-recognition/m-p/558812#M114179

 

Besides the whole library and core stuff, you will have to get the com.google.zxing.client.rim package and also the com.google.zxing.client.j2me  to get the LCDUIImageLuminescence file. Then just check how it's done in the ZXingLMMainScreen.

 

And follow what diegotri said.

 

Rgs

dan

Please use plain text.
Developer
diegotori
Posts: 50
Registered: ‎01-07-2010
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

[ Edited ]

That Bitmap-specific LuminanceSource file is currently proprietary to our app, so I can't share the source code. However, here's a hint: take a look at LCDUIImageLuminanceSource's setRGB functions. All I did was convert the J2ME Image object into Bitmap and modify it to its respective functions and that was it. Piece of cake it was. Also, if running this app on OS 6.0, make sure to give it different class name other than BitmapLuminanceSource, since it'll conflict with RIM's version.

 

Finally, for 1D, as long as you get a clean and sharp shot of the barcode from an auto-focus camera, it'll scan perfectly. Remember for ZXing, you have to define the type of barcodes you want the API to decode, so narrow the scope as to what you want to scan.

Please use plain text.
Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

[ Edited ]

Thanks diego!

 

But what about the continuous scanning using the video camera? Someone has told me that it works in the iPhone. I don't know, since it mainly would be getting many pictures to try to decode while the user points to the barcode, I think decoding the image take too much time to get an advantage from this approach. And it would not help anyway if the device camera doesn't have auto-focus.

 

Do you think it's worth a try?

 

Regards,

Dan

Please use plain text.
Developer
diegotori
Posts: 50
Registered: ‎01-07-2010
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

Continuous scan is next to impossible to pull off on anything below 6.0, since RIM doesn't allow devs access to the raw video frames. That and trying to capture it in a thread that takes images every second would just be too intensive for the platform. Even then, I was able to capture 1D on a single shot using the external camera a FileSystemJournalListener and it worked fine.

Please use plain text.
Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

That's it then.

 

Thank you.

 

Regards,

Dan

Please use plain text.
Developer
dannit
Posts: 48
Registered: ‎10-29-2009
My Device: Not Specified

Re: ZXING Barcode Scanning API for OS 5.0

Guys, I couldn't make this work. Even using devices which has the auto-focus feature, and taking good pics of the barcode.

 

This is how I'm proceeding:

 

1- Add a FileSystemJournalListener and invoke camera

2- When the fileJournalChanged is called (picture taken) I get the entry path and confirms that it is an image.

3- I run a new Thread to get the image, and then I create the BinaryBitmap, using a HybridBinarizer with the LCDUIImageLuminanceSource I got from the image file.

4- I try to decode using a MultiFormatReader with the hints: PURE_BARCODE and TRY_HARDER.

 

That's it, I get that from the ZXing Blackberry example, I didn't change much of it, but it didn't work as expected.  I was only able to decode large barcode images that I got in the internet. Is there anything else that I can do to improve the detection?

 

I would very much appreciate any help.

 

I'm sending the BarcodeReader file I created to do all that stuff.

 

Thanks,

Dan

Please use plain text.