Baumer工业相机

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

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

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

Baumer工业相机NEOAPI SDK是用于Baumer工业相机的一款最新的软件开发工具包(SDK)。它为开发人员提供了一系列API和工具,用于与Baumer工业相机进行通信和控制,控制方式极为便捷类似Halcon的相机助手类控制方式。​

Baumer工业相机NEOAPI SDK实现Bitmap的图像转换功能技术背景

Baumer工业相机的NEOAPI SDK是Baumer公司开发的针对其相机产品系列的一套软件开发工具包。该SDK提供了一组API,使开发人员可以编写专业应用程序,从而控制、捕获、处理和显示Baumer相机的图像和数据。BGAPI SDK支持多种编程语言,包括C++、C#、Visual Basic、LabVIEW、Matlab等,并提供了大量示例代码和文档,以帮助用户轻松上手,快速完成应用程序的开发。

NEOAPI SDK提供了丰富的功能,可以控制Baumer相机的所有参数,包括曝光时间、增益、白平衡、触发模式等,以及支持各种数据格式,例如Raw、BMP、JPG等,同时还提供了实时显示、数据采集、图像处理等功能,为开发人员提供了高度定制化的解决方案。此外,BGAPI SDK还支持多相机系统的开发,并可支持各种计算机操作系统,如Windows、Linux、Mac OS等。

工业相机获取的数据通常不是直接的图像格式,而是一块缓存区(buffer)。不同的图像处理软件需要的图像数据格式不一样,例如OpenCV存储图像用cv::Mat,Halcon存储图像用Halcon::HObject或者Halcon::HImage。因此,将工业相机图像转换为位图(Bitmap)格式需要经过一系列的步骤:

首先,从工业相机中获取图像数据,这可能需要使用专门的图像采集设备。然后,将图像数据从相机采集的原始格式转换为可由软件处理的标准化格式。最后,通过特定的函数或库,如BGAPI SDK或C#编程语言,实现Raw图像到Bitmap图像的转换并进行保存。

这种转换技术广泛应用于机器视觉领域,以适应不同的应用场景和需求。

Baumer工业相机通过NEOAPI SDK实现Bitmap的图像转换功能

下面介绍在C#里Baumer工业相机如何通过NEOAPI SDK实现Bitmap的图像转换

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 NeoAPI;

2.通过NEOAPI SDK实现Bitmap的图像转换功能

Baumer工业相机实现Bitmap的图像转换模式核心代码如下所示:

private   String pImgFileDir;       
public    Bitmap pBitmap;        
public    Rectangle prcSource;
public    Rectangle prcPBox;
private   Byte[] pImgBits;
        
NeoAPI.Cam camera = new NeoAPI.Cam();
camera.Connect();                                       // connect to a camera

bool isColor = true;
Feature pixelformat = new Feature();
camera.f.ExposureTime.Value = 10000;

if (camera.IsConnected)
{
     NeoAPI.Image image = camera.GetImage(); //相机采集一张图像
     IntPtr imagebuffer = new IntPtr();
     imagebuffer = image.ImageData;

     int w = 0; int h = 0;
     w = (int)image.Width;
     h = (int)image.Height;
     prcSource.X = 0; prcSource.Y = 0;
     prcSource.Width = w; prcSource.Height = h;

     string PixelFormatstr = camera.f.PixelFormat.ValueString;
     if (PixelFormatType.Contains("Mono8") | PixelFormatType.Contains("bayer"))
     {
          pBitmap = new System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
          pImgBits = new Byte[w * h];
    }
    else
    {
         pBitmap = new System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
         pImgBits = new Byte[w * h * 3];
    }

   System.Drawing.Imaging.BitmapData bmpdata;
   if (PixelFormatstr.Contains("Mono"))
   {
        System.Drawing.Imaging.ColorPalette palette = pBitmap.Palette;
        for (int i = 0; i < 256; i++)
        {
             palette.Entries[i] = Color.FromArgb(255, i, i, i);
        }
        pBitmap.Palette = palette;
   }

   if (PixelFormatstr.Contains("Mono"))
      bmpdata = pBitmap.LockBits(prcSource, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
   else
      bmpdata = pBitmap.LockBits(prcSource, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);


  if (PixelFormatstr.Contains("Mono") | PixelFormatType.Contains("bayer"))
  {
       System.Runtime.InteropServices.Marshal.Copy(imagebuffer, pImgBits, 0, w * h);
       System.Runtime.InteropServices.Marshal.Copy(pImgBits, 0, bmpdata.Scan0, w * h);
  }
  else
  {
       System.Runtime.InteropServices.Marshal.Copy(imagebuffer, pImgBits, 0, w * h * 3);
       System.Runtime.InteropServices.Marshal.Copy(pImgBits, 0, bmpdata.Scan0, w * h * 3);
  }
  pBitmap.UnlockBits(bmpdata);
     
  string strtime = DateTime.Now.ToString("yyyyMMddhhmmssfff");
  string saveimagepath = pImgFileDir + "\\" + strtime + "-" + imageid + ".jpg";
  if (pImgFileDir == "" | !Directory.Exists(pImgFileDir))
  {
       OnNotifyShowRecieveMsg("路径未设置或路径不存在,本次不保存图像");
  }
  else
  {
      pBitmap.Save(saveimagepath, System.Drawing.Imaging.ImageFormat.Bmp);
      OnNotifyShowRecieveMsg(strtime + "-" + imageid + ".jpg:" + "图像保存成功");
  }
}

Baumer工业相机实现Bitmap的图像转换功能的优势

  1. 兼容性: Bitmap图像具有普遍的兼容性,几乎可以在任何设备或平台上查看,包括电脑、智能手机和平板电脑。

  2. 简化处理: Bitmap图像可以很容易地使用标准的图像处理软件进行处理和编辑,使其成为工业应用中自动处理的理想选择。

  3. 高质量的图像: Bitmap图像提供高分辨率和色彩深度,从而产生高质量的图像,准确捕捉物体和场景的细节。

  4. 减少文件大小: Bitmap图像的尺寸通常比其他图像格式小,这使得它们更容易存储和传输。

  5. 易于整合: Bitmap图像很容易与其他软件和系统集成,使它们成为广泛的工业应用的理想选择。

Baumer工业相机实现Bitmap的图像转换功能的行业应用

  1. 质量控制: Bitmap图像可用于检测产品的缺陷、损坏或不完善之处。例如,在汽车行业,Bitmap图像可用于识别车身的划痕、凹痕和其他缺陷。

  2. 机器视觉: Bitmap图像可用于机器视觉系统,在制造过程中检测和检查产品的部件。它们可以用来测量尺寸,检查正确的装配,并检测缺陷或故障。

  3. 医学成像: Bitmap图像被广泛用于医学成像应用,如X射线、CT扫描和MRI扫描。它们可以用来帮助诊断病情和计划治疗。

  4. 机器人技术: Bitmap图像可用于机器人应用,在生产过程中向机器人提供视觉反馈。它们使机器人能够识别和绕过障碍物,并执行任务,如精确地挑选和放置物体。

  5. 监视: Bitmap图像可用于监控系统,以检测和识别入侵者或嫌疑人。它们可以用来捕捉车牌、人脸和其他识别特征的图像。

01-19 07:24