9

I have written a windows store app in XAML & C# to read image from tablet's webcam and decode the barcode using Zxing's lbrary. The code is working fine on a given tablet having an i5 processor while it fails to run on an actual tablet with 2MP camera and "Intel Baytrail Quad-Core" processor.

Any ideas on why this could happen?

Please let me know if you need to see my code for this issue ad I will share.

I am wondering how can the same code work on 1 tablet while fail on another tablet.

Thanks in advance for any help provided.

EDIT

Code used to scan the barcode and read as below - The last if/else block is what I get to. No exception raised :(

string barcodeData = string.Empty;
            using (var imageStream = new InMemoryRandomAccessStream())
            {
                processingImage = true;
                var encodingProperties = new ImageEncodingProperties();
                encodingProperties.Subtype = "Jpeg";
                encodingProperties.Width = 400;
                encodingProperties.Height = 400;

                await captureMgr.CapturePhotoToStreamAsync(encodingProperties, imageStream);
                await imageStream.FlushAsync();
                imageStream.Seek(0);

                var bitmap = new WriteableBitmap(400, 400);
                bitmap.SetSource(imageStream);
                preview1.Source = bitmap; //preview1 is an Image control to display the captured image

                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.SetSource(imageStream);

                imageStream.Seek(0);

                var bitmapDecoder = await BitmapDecoder.CreateAsync(BitmapDecoder.JpegDecoderId, imageStream);

                var data = await bitmapDecoder.GetPixelDataAsync(
                    BitmapPixelFormat.Bgra8,
                    BitmapAlphaMode.Straight,
                    new BitmapTransform(),
                    ExifOrientationMode.IgnoreExifOrientation,
                    ColorManagementMode.DoNotColorManage
                    );
                if (data != null)
                {
                    BarcodeReader barcodeReader = new BarcodeReader();

                    var result = barcodeReader.Decode(
                        data.DetachPixelData(),
                        (int)bitmapDecoder.PixelWidth,
                        (int)bitmapDecoder.PixelHeight,
                        ZXing.RGBLuminanceSource.BitmapFormat.BGR32
                        );
                    if (result != null)
                    {
                        //Barcode found
                    }
                    else
                       //No data found.
                }
            }
Nitesh
  • 2,286
  • 2
  • 43
  • 65
  • 1
    Logs? Exceptions? At least post the code that captures the image and calls ZXing. Posting your code is a rule in StackOverflow. – Panagiotis Kanavos Dec 10 '14 at 12:59
  • And? Where do you detect that you have no image? Do you check `imageStream` to see whether it contains any data? Do you log anything if `data` or `result` are null? – Panagiotis Kanavos Dec 10 '14 at 13:08
  • 2
    I also had some issues with barcodes, and I think the main problem was that the tablet's camera produced blurry pictures when positioning the barcode to near to the sensor.. – Rico Suter Dec 10 '14 at 13:10
  • I am using the same barcode image to test on both tablets. It shows the barcode correctly on 1 but not on 2nd. To show the image, I am using the code I have edited above and it does show the image ok on both tablets. – Nitesh Dec 10 '14 at 13:11
  • 1
    @RicoSuter, I did notice the image is not as sharp as on the 1st tablet where it read successfully. Any way to read in high resolution? – Nitesh Dec 10 '14 at 13:12
  • 1
    I dont know, maybe you can sharpen them by software? However the library should be fault tolerant enough to handle this internally... In my test I had to print the barcode on a bit paper so that it could be recognized... – Rico Suter Dec 10 '14 at 13:23
  • Sharpen the image by software? Any links please. I have already printed the barcodes on paper to test – Nitesh Dec 10 '14 at 13:28
  • If the problem is blurry images and/or lack of focus then perhaps you need to keep asking the camera for pictures until you get one that is valid. That is also how barcodescanners have worked for me in the past. – Zache Dec 17 '14 at 14:06
  • @Zache I have tried focusing the camera on the barcode in the most focused way and I am also displaying the captured image in a Image control so, I see the image captured is good, not of highest quality, but a good one to be read. – Nitesh Dec 17 '14 at 18:11
  • I have no experience with zxing, but I believe that problem lies in the image quality. From waht I can see, you are referingo to JPEG encoding - can you switch it to something loseless(png,tiff)? Another thing is photo settings on the device - is there any "image enhancement" filter active? – cyberhubert Dec 22 '14 at 11:16
  • @cyberhubert, I tried with all possible settings of zxing and EncodingProperties class, but no luck. Dont think any filter is active on the tablet device. – Nitesh Dec 22 '14 at 18:09
  • and have you tried to process stored photo instead of photo stream? You could also try to store some photos on one device and try to process them on another - that way you could see which part fails - taking photo or processing – cyberhubert Dec 23 '14 at 08:54
  • yes, have tried but with no luck :( – Nitesh Dec 23 '14 at 13:45

2 Answers2

5

I guess you are using ZXing.NET library. Have you ever considered moving to another barcode scanner library?

Accessing the "ISSUES" section in ZXing.NET Library, you can see that there's a lot of bugs still opened for Windows Phone (and should be Window Store also).

http://zxingnet.codeplex.com/workitem/list/basic

One of it called my attention. Check out this comment:

While the WP samples all target Silverlight, you must not forget that the new WP8.1 base is WinRT - so I suggest you use the WinRT sample as a base.

I tried to do the same, but truth to be told, ZXing lacks a lot ATM for WinRT Universal Apps - it's slow, unreliable, and barely ever recognizes a thing.

http://zxingnet.codeplex.com/workitem/13311

I don't know how reliable this is, but the last time the project was updated was on April 7th!!!!

You should really consider changing you library!

Community
  • 1
  • 1
rodrigogq
  • 1,943
  • 1
  • 16
  • 25
0

Hi,

I made a lib for WinRT using ZXing & Imaging SDK. It works well (but does not include any additional focus feature). https://github.com/stepheUp/VideoScanZXing4WP81 There is a lib and a sample app that you can try. It works for barcodes and QRCode (barcode by default but just change the optional parameter in the scan function code to use QRCode)

Hope it helps, Stéphanie