使用 C# 条形码扫描器扫描书籍

博客分类:条形码   .NET

2025/06/09

使用条形码扫描器扫描书籍正逐渐成为图书馆、书店、档案馆和教育机构自动化流程中不可或缺的一部分。这种方法可以加快大型馆藏的处理速度,最大限度地减少统计错误,并为读者与书籍的互动提供新的方式。



图书条形码扫描软件的工作原理

软件扫描软件是一种专门的软件解决方案,它使用摄像头、扫描仪或移动设备自动识别和解码贴在图书上的条形码。它的应用使得快速、准确地进行电子记账、资金管理和交易处理成为可能,无需人工录入数据。

软件扫描软件的工作原理如下:设备(例如摄像头或扫描仪)读取图书封面或书页上的条形码图像,软件解密其中编码的信息(例如ISBN),并将该数据传输到图书馆或交易系统进行进一步处理。

书籍上的条形码

近几十年来出版的大多数书籍都带有条形码——通常是EAN-13格式的ISBN(国际标准书号)或二维码(用于新一代出版物)。条形码包含书籍的唯一标识符,通常还包含有关该书籍的附加信息。

使用摄像头和扫描仪

软件条形码扫描器是一种应用程序或库,它可以使用专用设备(扫描器、终端)以及网络摄像头或移动设备识别条形码,从而使扫描过程尽可能地移动化和便捷化。

识别和数据处理

图像处理算法能够识别书籍上的条形码,解码其包含的信息,并将其与目录、数据库和图书馆系统集成,从而确保快速准确的账务处理。



书籍扫描步骤

使用软件条形码扫描器扫描书籍包含多个连续步骤,每个步骤对于账务处理、借阅和归还流程的准确性和效率都至关重要。合理的工作流程可以显著缩短盘点时间,提高数据质量,并优化图书馆和书店的服务。

设备和软件准备

开始扫描前,您必须确保所使用的设备支持所选软件和条形码标准。然后:

扫描并识别条形码。

在此阶段,将实际读取图书上的条形码:
将图书放置到位,使条形码清晰可见,以便摄像头或扫描仪能够读取。

与图书馆或贸易系统集成

成功识别后,软件扫描器会自动将接收到的数据传输到信息系统:

数据存储、分析及后续处理

信息录入数据库后,即可实现会计和分析流程的自动化:



现代软件扫描器的技术特性和优势

现代软件条码扫描器具备以下技术解决方案:

对于任何寻求自动化、提高账务透明度和提升服务速度的图书馆或书店而言,现代条形码扫描软件都是至关重要的工具。借助此类软件,纸质馆藏的处理可以以最低的成本和最大的收益迈向现代化的数字化阶段。

选择软件解决方案

选择用于图书条码扫描的软件时,建议考虑以下因素:

通用解决方案应易于集成到 IT 基础设施中,并支持在各种设备上使用:从台式电脑到手机。建议选择界面简洁、可更新且提供技术支持的产品。

发展前景

使用软件条形码扫描器的图书扫描技术正迅速发展。在不久的将来,二维条形码(例如 DataMatrix 和 QR 码)预计将得到更广泛的应用,因为它们可以包含更多信息——例如电子书链接、注释和安全标识符。

扫描仪与云服务和数字图书馆的融合日益加深,这将使用户能够自动访问在线资源并获得更丰富的服务。未来,预计还将引入智能功能:自动分析图书状态、生成推荐,以及开发端到端的分析和监控图书馆资金流动情况。

结论

选择条形码扫描软件解决方案需要仔细考虑诸多因素,包括支持的格式、速度、集成能力和易用性。技术发展前景广阔,为自动化开辟了新的天地,提高了图书馆系统的效率,并改善了用户服务。

VintaSoft 开发的 VintaSoft Barcode .NET SDK 可显著简化图书馆条形码系统的创建。这款强大的工具支持多种格式的条形码,扫描速度快、精度高,并且能够轻松集成到现有的图书馆系统中。借助 VintaSoft Barcode .NET SDK,图书馆可以快速高效地自动化所有与账簿管理相关的流程,从而提高服务质量并显著节省资源。


以下是一段 C# 代码,演示如何识别从相机捕获的图像中的 ISBN 条形码:
/// <summary>
/// Reads barcode from a <see cref="System.Drawing.Bitmap"/>.
/// </summary>
/// <param name="bitmap">A bitmap with barcodes.</param>
public static void ReadIsbnBarcodesFromBitmap(System.Drawing.Bitmap bitmap)
{
    // create barcode reader
    using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
    {
        // specify that reader must search for ISBN barcodes
        reader.Settings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.ISBN;

        // read barcodes from image
        Vintasoft.Barcode.IBarcodeInfo[] infos = Vintasoft.Barcode.GdiExtensions.ReadBarcodes(reader, bitmap);

        // if barcodes are not detected
        if (infos.Length == 0)
        {
            System.Console.WriteLine("No barcodes found.");
        }
        // if barcodes are detected
        else
        {
            // get information about extracted barcodes

            System.Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
            System.Console.WriteLine();
            for (int i = 0; i < infos.Length; i++)
            {
                Vintasoft.Barcode.IBarcodeInfo info = infos[i];
                System.Console.WriteLine(string.Format("[{0}:{1}]", i + 1, info.BarcodeType));
                System.Console.WriteLine(string.Format("Value:      {0}", info.Value));
                System.Console.WriteLine(string.Format("Region:     {0}", info.Region));
                System.Console.WriteLine();
            }
        }
    }
}



以下是一段 C# 代码,演示如何在 WinForms 应用程序中从 DirectShow 相机(VintaSoft Imaging .NET SDK)捕获图像,并识别捕获图像中的 ISBN 条形码(VintaSoft Barcode .NET SDK):
public partial class IsbnBarcodeScannerForm : Form
{
    /// <summary>
    /// The camera barcode scanner.
    /// </summary>
    ImagingCameraBarcodeScanner _cameraBarcodeScanner;

    /// <summary>
    /// Initializes a new instance of the <see cref="IsbnBarcodeScannerForm"/> class.
    /// </summary>
    public IsbnBarcodeScannerForm()
    {
        InitializeComponent();

        _cameraBarcodeScanner = new ImagingCameraBarcodeScanner();
        _cameraBarcodeScanner.BarcodeScanner.FrameScanFinished += BarcodeScanner_FrameScanFinished;
        _cameraBarcodeScanner.ScanningException += CameraBarcodeScanner_ScanningException;

        _cameraBarcodeScanner.BarcodeScanner.ScannerSettings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.QR;
    }

    /// <summary>
    /// Starts the capturing of images from seleced device and recognition of barcodes in captured images.
    /// </summary>
    private void startButton_Click(object sender, EventArgs e)
    {
        textBox1.Text = "Scan Barcodes Types: " + _cameraBarcodeScanner.BarcodeScanner.ScannerSettings.ScanBarcodeTypes.ToString();

        _cameraBarcodeScanner.CaptureDevice = _cameraBarcodeScanner.CaptureDevices[0];
        _cameraBarcodeScanner.StartScanning();
    }

    /// <summary>
    /// Stops the capturing of images from seleced device and recognition of barcodes in captured images.
    /// </summary>
    private void stopButton_Click(object sender, EventArgs e)
    {
        textBox1.Text = "";

        _cameraBarcodeScanner.StopScanning();
    }

    /// <summary>
    /// Shows an error.
    /// </summary>
    private void CameraBarcodeScanner_ScanningException(object sender, Vintasoft.Imaging.ExceptionEventArgs e)
    {
        MessageBox.Show(e.Exception.ToString());
    }

    /// <summary>
    /// Handles the FrameScanFinished event of the BarcodeScanner.
    /// </summary>
    private void BarcodeScanner_FrameScanFinished(object sender, Vintasoft.Barcode.FrameScanFinishedEventArgs e)
    {
        if (e.FoundBarcodes.Length > 0)
            Invoke(new ShowRecognitionResultsDelegate(ShowRecognitionResults), new object[] { e.FoundBarcodes });
    }

    /// <summary>
    /// Shows barcode recognition results.
    /// </summary>
    private void ShowRecognitionResults(Vintasoft.Barcode.IBarcodeInfo[] barcodes)
    {
        StringBuilder result = new StringBuilder();

        foreach (Vintasoft.Barcode.IBarcodeInfo barcode in barcodes)
            result.AppendLine(string.Format("{0}: {1}", barcode.BarcodeType, barcode.Value));

        // show barcode recognition in text box
        textBox1.Text = result.ToString();
    }

    delegate void ShowRecognitionResultsDelegate(Vintasoft.Barcode.IBarcodeInfo[] barcodeInfo);
}


/// <summary>
/// Allows to capture images from DirectShow camera (VintaSoft Imaging .NET SDK) and recognize barcodes in captured images (VintaSoft Barcode .NET SDK).
/// </summary>
public class ImagingCameraBarcodeScanner : IDisposable
{

    #region Fields

    /// <summary>
    /// Monitor for capture devices.
    /// </summary>
    Vintasoft.Imaging.Media.ImageCaptureDevicesMonitor _captureDevicesMonitor;

    /// <summary>
    /// Image capture source for barcode recognition.
    /// </summary>
    Vintasoft.Imaging.Media.ImageCaptureSource _imageCaptureSource;

    #endregion



    #region Constructors

    /// <summary>
    /// Initializes a new instance of the <see cref="ImagingCameraBarcodeScanner"/> class.
    /// </summary>
    public ImagingCameraBarcodeScanner()
    {
        _barcodeScanner = new Vintasoft.Barcode.CameraBarcodeScanner();
        _barcodeScanner.FrameScanException += BarcodeScanner_FrameScanException;
        _barcodeScanner.ScannerSettings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.ISBN;

        _captureDevicesMonitor = new Vintasoft.Imaging.Media.ImageCaptureDevicesMonitor();
        _captureDevicesMonitor.CaptureDevicesChanged += CaptureDevicesMonitor_CaptureDevicesChanged;

        if (!Vintasoft.Imaging.ImagingEnvironment.IsInDesignMode)
            _captureDevicesMonitor.Start();

        _imageCaptureSource = new Vintasoft.Imaging.Media.ImageCaptureSource();
        _imageCaptureSource.CaptureCompleted += ImageCaptureSource_CaptureCompleted;

    }

    #endregion



    #region Properties

    Vintasoft.Imaging.Media.ImageCaptureDevice _captureDevice;
    /// <summary>
    /// Gets or sets current capture device.
    /// </summary>
    public Vintasoft.Imaging.Media.ImageCaptureDevice CaptureDevice
    {
        get
        {
            return _captureDevice;
        }
        set
        {
            if (_captureDevice != value)
            {
                _captureDevice = value;

                UpdateCapureFormats();
            }
        }
    }

    ReadOnlyCollection<Vintasoft.Imaging.Media.ImageCaptureFormat> _captureFormats = null;
    /// <summary>
    /// Gets the available capture formats of current capture device.
    /// </summary>
    /// <seealso cref="CaptureDevice"/>
    public ReadOnlyCollection<Vintasoft.Imaging.Media.ImageCaptureFormat> CaptureFormats
    {
        get
        {
            return _captureFormats;
        }
    }

    /// <summary>
    /// Gets available capture devices.
    /// </summary>
    public ReadOnlyCollection<Vintasoft.Imaging.Media.ImageCaptureDevice> CaptureDevices
    {
        get
        {
            return Vintasoft.Imaging.Media.ImageCaptureDeviceConfiguration.GetCaptureDevices();
        }
    }

    Vintasoft.Barcode.CameraBarcodeScanner _barcodeScanner;
    /// <summary>
    /// Gets the barcode scanner.
    /// </summary>
    public Vintasoft.Barcode.CameraBarcodeScanner BarcodeScanner
    {
        get
        {
            return _barcodeScanner;
        }
    }

    /// <summary>
    /// Gets a value indicating whether barcode scanning is started.
    /// </summary>
    public bool IsStarted
    {
        get
        {
            return _imageCaptureSource.State == Vintasoft.Imaging.Media.ImageCaptureState.Started;
        }
    }

    #endregion



    #region Methods

    #region PUBLIC

    /// <summary>
    /// Starts the capturing of images from seleced device and recognition of barcodes in captured images.
    /// </summary>
    public void StartScanning()
    {
        try
        {
            if (CaptureDevice == null)
                throw new ArgumentNullException("CaptureDevice");

            if (CaptureFormats == null || CaptureFormats.Count == 0)
                throw new ArgumentNullException("CaptureFormats");

            if (_imageCaptureSource.State != Vintasoft.Imaging.Media.ImageCaptureState.Started)
            {
                if (CaptureDevice.DesiredFormat == null)
                    CaptureDevice.DesiredFormat = CaptureFormats[0];

                _barcodeScanner.StartScanning();

                _imageCaptureSource.CaptureDevice = _captureDevice;
                _imageCaptureSource.Start();
                _imageCaptureSource.CaptureAsync();

                OnScanningStart(EventArgs.Empty);
            }
        }
        catch (Exception ex)
        {
            OnScanningException(new Vintasoft.Imaging.ExceptionEventArgs(ex));
        }
    }

    /// <summary>
    /// Stops the capturing of images from seleced device and recognition of barcodes in captured images.
    /// </summary>
    public void StopScanning()
    {
        try
        {
            if (_imageCaptureSource.State != Vintasoft.Imaging.Media.ImageCaptureState.Stopped)
            {
                _barcodeScanner.StopScanning();
                _imageCaptureSource.Stop();

                OnScanningStop(EventArgs.Empty);
            }
        }
        catch (Exception ex)
        {
            OnScanningException(new Vintasoft.Imaging.ExceptionEventArgs(ex));
        }
    }

    /// <summary>
    /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    /// </summary>
    public void Dispose()
    {
        _captureDevicesMonitor.CaptureDevicesChanged -= CaptureDevicesMonitor_CaptureDevicesChanged;
        _barcodeScanner.BarcodeReader.Dispose();
    }

    #endregion


    #region PROTECTED

    /// <summary>
    /// Raises the <see cref="CaptureDevicesChanged" /> event.
    /// </summary>
    /// <param name="args">The <see cref="ImageCaptureDevicesChangedEventArgs"/> instance containing the event data.</param>
    protected virtual void OnCaptureDevicesChanged(Vintasoft.Imaging.Media.ImageCaptureDevicesChangedEventArgs args)
    {
        if (CaptureDevicesChanged != null)
            CaptureDevicesChanged(this, args);
    }

    /// <summary>
    /// Raises the <see cref="ScanningException" /> event.
    /// </summary>
    /// <param name="args">The <see cref="ExceptionEventArgs"/> instance containing the event data.</param>
    protected virtual void OnScanningException(Vintasoft.Imaging.ExceptionEventArgs args)
    {
        if (ScanningException != null)
            ScanningException(this, args);
    }

    /// <summary>
    /// Raises the <see cref="ScanningStart" /> event.
    /// </summary>
    /// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param>
    protected virtual void OnScanningStart(EventArgs args)
    {
        if (ScanningStart != null)
            ScanningStart(this, args);
    }

    /// <summary>
    /// Raises the <see cref="ScanningStop" /> event.
    /// </summary>
    /// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param>
    protected virtual void OnScanningStop(EventArgs args)
    {
        if (ScanningStop != null)
            ScanningStop(this, args);
    }

    #endregion


    #region PRIVATE

    /// <summary>
    /// Handles the FrameScanException event of the BarcodeScanner control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="Vintasoft.Barcode.FrameScanExceptionEventArgs"/> instance containing the event data.</param>
    private void BarcodeScanner_FrameScanException(object sender, Vintasoft.Barcode.FrameScanExceptionEventArgs e)
    {
        OnScanningException(new Vintasoft.Imaging.ExceptionEventArgs(e.Exception));
    }

    /// <summary>
    /// Handles the CaptureCompleted event of the ImageCaptureSource.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="ImageCaptureCompletedEventArgs"/> instance containing the event data.</param>
    private void ImageCaptureSource_CaptureCompleted(object sender, Vintasoft.Imaging.Media.ImageCaptureCompletedEventArgs e)
    {
        try
        {
            // get captured image
            Vintasoft.Imaging.VintasoftImage image = e.GetCapturedImage();

            // recognize barcodes from captured image
            using (Vintasoft.Imaging.VintasoftBitmap bitmap = image.GetAsVintasoftBitmap())
                _barcodeScanner.ScanFrame(bitmap);

            // if image capturing is started
            if (_imageCaptureSource.State == Vintasoft.Imaging.Media.ImageCaptureState.Started)
            {
                // capture next image
                _imageCaptureSource.CaptureAsync();
            }
        }
        catch (Exception ex)
        {
            OnScanningException(new Vintasoft.Imaging.ExceptionEventArgs(ex));
        }
    }

    /// <summary>
    /// Handles the CaptureDevicesChanged event of the CaptureDevicesMonitor.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="ImageCaptureDevicesChangedEventArgs"/> instance containing the event data.</param>
    private void CaptureDevicesMonitor_CaptureDevicesChanged(object sender, Vintasoft.Imaging.Media.ImageCaptureDevicesChangedEventArgs e)
    {
        if (Array.IndexOf(e.RemovedDevices, CaptureDevice) >= 0)
        {
            StopScanning();
        }

        OnCaptureDevicesChanged(e);
    }

    /// <summary>
    /// Updates the capture formats.
    /// </summary>
    private void UpdateCapureFormats()
    {
        Vintasoft.Imaging.Media.ImageCaptureDevice device = CaptureDevice;
        if (device == null || device.SupportedFormats == null)
        {
            _captureFormats = null;
        }
        else
        {
            List<Vintasoft.Imaging.Media.ImageCaptureFormat> captureFormats = new List<Vintasoft.Imaging.Media.ImageCaptureFormat>();

            List<uint> imageCaptureFormatSizes = new List<uint>();
            for (int i = 0; i < device.SupportedFormats.Count; i++)
            {
                // if format has bit depth less or equal than 12 bit
                if (device.SupportedFormats[i].BitsPerPixel <= 12)
                {
                    // ignore formats with bit depth less or equal than 12 bit because they may cause issues on Windows 8
                    continue;
                }

                uint imageCaptureFormatSize = (uint)(device.SupportedFormats[i].Width | (device.SupportedFormats[i].Height << 16));
                if (!imageCaptureFormatSizes.Contains(imageCaptureFormatSize))
                {
                    imageCaptureFormatSizes.Add(imageCaptureFormatSize);

                    captureFormats.Add(device.SupportedFormats[i]);
                }
            }
            _captureFormats = captureFormats.AsReadOnly();
        }
    }

    #endregion

    #endregion



    #region Events

    /// <summary>
    /// Occurs when barcode scanning is started.
    /// </summary>
    public event EventHandler ScanningStart;

    /// <summary>
    /// Occurs when barcode scanning is stopped.
    /// </summary>
    public event EventHandler ScanningStop;

    /// <summary>
    /// Occurs when barcode scanning error occurs.
    /// </summary>
    public event EventHandler<Vintasoft.Imaging.ExceptionEventArgs> ScanningException;

    /// <summary>
    /// Occurs when <see cref="CaptureDevices"/> property is changed.
    /// </summary>
    public event EventHandler<Vintasoft.Imaging.Media.ImageCaptureDevicesChangedEventArgs> CaptureDevicesChanged;

    #endregion

}