Giter Club home page Giter Club logo

emgucvzxingbarcodeexample's Introduction

TestBarcode

TestBarcode is an example project on how to read barcodes from an image with EmguCV and ZXing. The project was written and tested in .Net 4.7.

Build status

Images that can be read:

The images below can be read by the barcode reader (because the rotation is correct according to a horizontal line):

Images that can't be read:

The image below can't be read by the barcode reader (because the rotation is wrong according to a horizontal line):

Example images that can be read:

Example images that can't be read:

Example code:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using ZXing;

namespace TestBarcode
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void TestImage_Click(object sender, EventArgs e)
        {
            IBarcodeReader reader = new BarcodeReader();
			//Load barcode file.
            var barcodeBitmap = (Bitmap) Image.FromFile("C:\\Users\\ASDF\\Desktop\\Test.jpg");
			//Convert the image to an EmguCV frame
            var frame = new Image<Bgr, byte>(barcodeBitmap);
			//Convert the image to a gray frame.
            var grayFrame = frame.Convert<Gray, byte>();
			//Perform a threshold transformation (usually 87 to 170 is a good value for the first parameter).
            grayFrame = grayFrame.ThresholdBinary(new Gray(TrackBar.Value), new Gray(255));
			//Show the read image.
            PictureBoxImage.Image = grayFrame.ToBitmap();
            reader.Options.TryHarder = true;
			//Set the barcode format.
            reader.Options.PossibleFormats = new List<BarcodeFormat> {BarcodeFormat.CODE_39};
			//Specify some options.
            reader.Options.UseCode39ExtendedMode = true;
            reader.Options.UseCode39RelaxedExtendedMode = true;
			//Decode and display barcode.
            var result = reader.Decode(grayFrame.ToBitmap());
            if (result != null)
            {
                RichTextBoxText.Text = result.BarcodeFormat.ToString();
                RichTextBoxContent.Text = result.Text;
                return;
            }
            RichTextBoxText.Text = string.Empty;
            RichTextBoxContent.Text = string.Empty;
        }

        private void TrackBar_Scroll(object sender, EventArgs e)
        {
            label1.Text = TrackBar.Value.ToString();
            TestImage_Click(sender, e);
        }
    }
}

Change history

  • Version 1.0.0.0 (2017-09-01) : 1.0 release.

emgucvzxingbarcodeexample's People

Contributors

tiham07 avatar sepppenner avatar

Watchers

James Cloos avatar 高升 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.