Baumer工业相机堡盟工业相机如何使用BGAPISDK联合Halcon进行读码识别(C#)

Baumer工业相机

Baumer工业相机堡盟相机是一种高性能、高质量的工业相机,可用于各种应用场景,如物体检测、计数和识别、运动分析和图像处理。

Baumer的万兆网相机拥有出色的图像处理性能,可以实时传输高分辨率图像。此外,该相机还具有快速数据传输、低功耗、易于集成以及高度可扩展性等特点。

Baumer工业相机由于其性能和质量的优越和稳定,常用于高速同步采集领域,通常使用各种图像算法来提高其捕获的图像的质量。

Baumer工业相机图像数据联合Halcon进行读码的技术背景

工业相机图像数据联合Halcon进行读码的技术背景主要涉及到机器视觉和图像处理领域。

工业相机是一种专门用于工业生产过程中的图像采集设备,其主要功能是通过采集并处理物体的图像信息,实现自动化生产过程的监控和控制。而读码则是一种对于二维码、条形码等符号进行识别和解码的技术。

Halcon是一种流行的机器视觉开发工具,其提供了丰富的图像处理和分析功能,可以对工业相机采集的图像数据进行处理、分析和识别,实现对于二维码、条形码等符号的读码功能。

因此,将工业相机图像数据与Halcon进行联合,可以实现高效、准确的读码功能,为工业生产过程中的自动化监控和控制提供了有力的支持。

Baumer工业相机使用BGAPISDK将图像数据转换为ImageSource方式

下面介绍在C#里Baumer工业相机如何使用BGAPISDK转换原始图像数据为ImageSource的方式

1.引用合适的类文件

代码如下(示例):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Data;
using System.Globalization;
using System.Diagnostics;
using System.IO;
using HalconDotNet;

2.使用BGAPISDK联合Halcon进行读码的方式

核心代码如下所示:

public ImageSource ToImageSource(BGAPI2.Buffer Image)
{
    if (Image== null || Image.IsEmpty)
    {
        Debug.Print("ImageToImageSourceConverter: Image is null or empty");
        return null;
    }
    else
    {
        Codes.Clear();
        //Check for the Halcon-License (Dongle/File)
        if (HalconLicenseCheck())
        {
            //NeoAPI.Image to Halcon-Image 
            HImage hImage = new("byte", (int)Image.Width, (int)Image.Height, Image.ImageData);

            //Create HDataCode2DModel
            HDataCode2D hDataCode2D = new();
            hDataCode2D.CreateDataCode2dModel("Data Matrix ECC 200", new HTuple(), new HTuple());

            //Find DataCodes
            HXLDCont hXLDCont;
            hXLDCont = hImage.FindDataCode2d(hDataCode2D, "stop_after_result_num", "20", out HTuple resultHandle, out HTuple decodedDataStrings);

            //determine the coordinates for each code found
            for (int i = 0; i < decodedDataStrings.Length; i++)
            {
                //Get Contoure Data
                hXLDCont[i + 1].GetContourXld(out HTuple rowHXLDCont, out HTuple colHXLDCont);

                Point TopLeft = new(System.Convert.ToInt32((double)colHXLDCont[0]), System.Convert.ToInt32((double)rowHXLDCont[0]));
                Point TopRight = new(System.Convert.ToInt32((double)colHXLDCont[1]), System.Convert.ToInt32((double)rowHXLDCont[1]));
                Point BottomRight = new(System.Convert.ToInt32((double)colHXLDCont[2]), System.Convert.ToInt32((double)rowHXLDCont[2]));
                Point BottomLeft = new(System.Convert.ToInt32((double)colHXLDCont[3]), System.Convert.ToInt32((double)rowHXLDCont[3]));
                String Text = decodedDataStrings[i];
                Code code = new(TopLeft, TopRight, BottomLeft, BottomRight, Text);
                Codes.Add(code);
            }
        }

        //copy NeoAPI-Image int a writeableBitmap 
        NeoAPI.Image transformedImage;

        Boolean isChanged = false;
        if (width != System.Convert.ToInt32(Image.Width))
        {
            isChanged = true;
            width = System.Convert.ToInt32(Image.Width);
        }

        if (height != System.Convert.ToInt32(Image.Height))
        {
            isChanged = true;
            height = System.Convert.ToInt32(Image.Height);
        }

        if (isChanged)
        {
            writeableBitmap = new WriteableBitmap(width, height, dpiX, dpiY, PixelFormats.Bgr24, null);
            backBuffer = writeableBitmap.BackBuffer;
        }

        transformedImage = Image.Convert("BGR8");
        CopyMemory(backBuffer, transformedImage.ImageData, System.Convert.ToUInt32(transformedImage.Width) * System.Convert.ToUInt32(transformedImage.Height) * 3);
                
        Image.Dispose();
                                
        if(transformedImage!=null) transformedImage.Dispose();

        //draw the writeableBitmap into a DrawingImage, draw a frame around the codes and draw text with the content next to it
        DrawingGroup dGroup = new();
                
        Pen pen = new(Brushes.Lime, 10);

        if (writeableBitmap != null)
        {
            writeableBitmap.Lock();
            writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
            writeableBitmap.Unlock();


            using DrawingContext dc = dGroup.Open();

            dc.DrawImage(writeableBitmap, new Rect(0, 0, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight));
            foreach (Code code in Codes)
            {
                dc.DrawLine(pen, code.TopLeft, code.TopRight);
                dc.DrawLine(pen, code.TopRight, code.BottomRight);
                dc.DrawLine(pen, code.BottomRight, code.BottomLeft);
                dc.DrawLine(pen, code.BottomLeft, code.TopLeft);

                Point TextPoint = new(code.TopRight.X, code.TopRight.Y - 250);
                Rect rect = new(TextPoint.X - 10, TextPoint.Y - 10, 600, 240);
                Pen rectPen = new(Brushes.DarkGreen, 10.0f);
                dc.DrawRectangle(Brushes.DarkGreen, rectPen, rect);
                FormattedText formattedText = new(code.Text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Arial"), 46, Brushes.Lime, 96);
                dc.DrawText(formattedText, TextPoint);
            }
        }
        DrawingImage dImageSource = new(dGroup);
        return dImageSource;               
    }
}

private static bool HalconLicenseCheck()
{
    bool LicenseIsValid;
    try
    {
        HImage ho_ImageTest = new();
        ho_ImageTest.GenImageConst("byte", 100, 100);
        LicenseIsValid = true;
    }
    catch(Exception ex)
    {
        Debug.Print("Exception during HalconLicenseCheck. Message = " + ex.Message);
        LicenseIsValid = false;
    }
    return LicenseIsValid;
}

    

Baumer工业相机图像联合Halcon进行读码的优势

工业相机图像联合Halcon进行读码的优势主要体现在以下几个方面:

高效准确:Halcon具备强大的图像处理和分析功能,可以对工业相机采集的图像数据进行高效、准确的处理和识别,提高读码的准确率和效率。

可定制性强:Halcon提供了丰富的图像处理算法和函数库,可以根据不同的应用场景和需求,进行定制化的二维码、条形码等符号的识别算法开发,提高读码的适应性和可靠性。

可扩展性强:Halcon支持多种编程语言和平台,可以与其他软件和硬件系统进行集成,实现更加完整和高效的工业自动化控制系统。

可追溯性强:通过Halcon对二维码、条形码等符号的读码,可以实现对产品生产、质量检测等环节的全程追溯,提高生产管理的效率和质量。

综上所述,工业相机图像联合Halcon进行读码具有高效准确、可定制性强、可扩展性强和可追溯性强等优势,可以为工业自动化生产提供更加可靠和高效的控制和管理。

Baumer工业相机图像联合Halcon进行读码的行业应用

工业相机图像联合Halcon进行读码在工业自动化领域有着广泛的应用,以下是几个行业应用的例子:

电子制造业:在电子制造过程中,需要对电子元器件和产品进行标识和追溯,工业相机图像联合Halcon进行二维码或条形码的读码,可以实现对于电子元器件和产品的识别和追溯。

医疗器械制造业:在医疗器械制造过程中,需要对器械进行标识和追溯,工业相机图像联合Halcon进行二维码的读码,可以实现对医疗器械的识别和追溯,提高医疗器械的质量和安全性。

物流行业:在物流行业中,需要对包裹、货物进行标识和追溯,工业相机图像联合Halcon进行二维码或条形码的读码,可以实现对包裹、货物的识别和追溯,提高物流运输的效率和质量。

食品制造业:在食品制造过程中,需要对食品进行标识和追溯,工业相机图像联合Halcon进行二维码或条形码的读码,可以实现对食品的识别和追溯,提高食品安全和质量。

综上所述,工业相机图像联合Halcon进行读码在电子制造、医疗器械制造、物流行业、食品制造等领域都有着广泛的应用,可以提高生产效率、产品质量和安全性,为企业的可持续发展提供有力的支持。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

格林威

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值