How to Read Barcode Image from Web Camera and Decode it with ByteScout Barcode Reader SDK - ByteScout

How to Read Barcode Image from Web Camera and Decode it with ByteScout Barcode Reader SDK

  • Home
  • /
  • Articles
  • /
  • How to Read Barcode Image from Web Camera and Decode it with ByteScout Barcode Reader SDK

BarCode Reader SDK and BarCode Reader free utility are capable of reading 1D and 2D barcodes from images fetched from a scanner or a web camera device.

DEVELOPERS: To load image from web-camera or scanner device into BarCode Reader SDK please use freeware Scan SDK (visit this page for free download). Scroll to the end of this tutorial to see ready-to-use source code snippets.

You can test how it works with BarCode Reader utility included into BarCode Reader SDK: run it, use Acquire Image button to load image from web-camera or scanner device.

Requirements for Web-Camera Devices:

  1. resolution 640×480 or higher;
  2. Ability to change the focus (in MANUAL FOCUS mode). Usually such web camera devices have a ring around lenses which can be used to adjust the focus. Web camera devices with ability to change focus: Microsoft LifeCam VX-1000, Logitech QuickCam Pro 9000, Labtec Webcam 2200 and any other with manual focus support.

    Why it’s important to have Manual Focus in a Web Camera? Manual focus is required to get sharp image of the barcode. With autofocus web camera devices usually are not able to take sharp photo of the barcode.

  3. you should put the image with the barcode 2-3 inches before the web-camera;
  4. make sure you have a sharp image and the barcode is not cut on the picture.

STEP-BY-STEP TUTORIAL (for cheap Hercules Classic Link webcam)

  1. Run BarCode Reader utility

  2. Turn on web camera

  3. Click Acquire Image

    Acquire barcode image

  4. Web camera selection dialog will appear:

    Select Web camera to acquire barcode picture

    Select WIA-Hercules Classic Link and click Select.

  5. Capture Pictures from Video dialog will appear:
    You will preview the picture
    Turn Manual Focus ring near the lens to get desired focus:
    BAD (adjust Manual Focus to get barcode focused):
    Bad web camera focus

    GOOD (after Manual Focus ring adjustments):
    Good web camera focus - sharp barcode image

    Now click Capture button and then Get Pictures button:

    Capture barcode image from video

    The image will be transferred to the BarCode Reader utility:

    Barcode image transferred to Barcode Reader

    Click Decode All (1D and 2D) button to find and decode barcode:

    Decode barcode image captured from web camera video

    You will see the utility found and decoded the barcode.

How to speed up decoding barcode images: you can speed up decoding by clicking Decode 1D only button or Decode 2D only button if you know the type of the barcode you have.

FOR SOFTWARE DEVELOPERS – here are the source code snippets to see how to scan and decode barcode from web camera (C# code):

  1. loading image from web-camera (the code called on Acquire Image button):
    /// <summary>
            /// Starts Asynchronous scan into images. When scan is finished
            /// then scan_TransferFinished event is called and array with
            /// images objects is passed into this event
    
            /// </summary>
            private void startScan()
            {
                // create new Scan object
    
                Scan scan = new Scan();
    
                // set Scan object to save images into images array
                // (will be passed as a parameter in scan_TransferFinished event
    
                scan.SaveTo = SaveTo.ImageObject;
    
                // set function for scan finished event to indicate when
                // image transfer is finished
    
                // see scan_TransferFinished event below
                scan.TransferFinished += scan_TransferFinished;
    
                // acquire images
    
                scan.AcquireImagesAsync(Handle);
            }
    
    
            // this event captures scanned images and fills images into tabs
    
            // you can also iterate through scannedImages array to get each
            // image as an Image object instead
            void scan_TransferFinished(Scan sender, ArrayList scannedImages)
    
            {
                List<string> files = new List<string>();
    
                for (int i = 0; i < Math.Min(scannedImages.Count, 1); i++)
    
                {
                    Image image = scannedImages[i] as Image;
    
                    string s = scannedImages[i] as string;
    
                    if (image != null)
                    {
                        string fileName = Path.GetTempFileName() + ".bmp";
    
                        image.Save(fileName);
                        m_filesToDelete.Add(fileName);
    
                        files.Add(fileName);
                    }
                    else if (s != null)
    
                        files.Add(s);
                }
    
                m_images = files.ToArray();
    
                m_currentImage = 0;
    
                updatePicture();
                updateButtons();
    
            }
    
  2. decoding the image from web-camera:
    private void decodeImage()
            {
                enableButtons(false);
    
                m_result = null;
    
    SymbologyFilter filter = m_reader.TypeToFind;                
    if (m_reader != null)
    
      m_reader.ReadFrom(m_images[m_currentImage]);
    }
                catch (Exception ex)
    
                {
                    MessageBox.Show(ex.Message);
                }
    
                m_reader.TypeToFind = filter;
                m_lastDecodingTime = m_decodingForm.LastDecodingTime;
    
                updatePicture();
    
                updateFound();
                enableButtons(true);
    
            }
    

Tutorials:

prev
next