Baumer工业相机堡盟工业相机使用BGAPI SDK将图像数据转换为Bitmap的几种方式(C#)(RGB)

@[TOC](Baumer工业相机堡盟工业相机使用BGAPI SDK将图像数据转换为Bitmap的几种方式(C#)(RGB))

Baumer工业相机

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

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

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

Baumer工业相机图像数据转为Bitmap的技术背景

将工业相机图像数据转换为位图格式通常包括几个步骤:

  1. 从工业相机中获取图像数据,这可能需要使用专门的图像采集设备。
  2. 将图像数据从相机采集的原始格式转换为可由软件处理的标准化格式。
  3. 对图像数据进行预处理,以纠正原始图像中可能存在的失真或其他问题。
  4. 将预处理后的图像数据转换为位图格式,这是一种常用的文件格式,用于在计算机系统上存储图像。

这些步骤的具体技术细节会因所使用的具体相机和软件的不同而不同,但这个过程中使用的一些常用工具和技术可能包括:

  • SDK(软件开发工具包),提供访问相机硬件和处理原始图像数据的库和API
  • 图像处理软件,如MATLAB或OpenCV,可用于纠正图像失真并对图像数据应用过滤器或其他调整。
  • 图像转换库,如ImageMagick或GDAL,可用于将预处理的图像数据转换为位图格式。

本文这里介绍使用BGAPISDK的方法转换Baumer工业相机图像数据为Bitmap图像的几种方法(彩色RGB)。

Baumer工业相机使用BGAPISDK将图像数据转换为Bitmap的几种方式

下面介绍在C#里Baumer工业相机如何使用BGAPISDK转换原始图像数据为Bitmap的几种方式(彩色RGB)

1.引用合适的类文件

代码如下(示例):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BGAPI2;
using System.Runtime.InteropServices;
using System.IO;
using CSCameraDemo.Properties;
using System.Globalization;
using WindowsFormsApplication1;
using System.Threading.Tasks;
using System.Threading;
using System.Drawing.Imaging;

2.BGAPI SDK原始图像数据为Bitmap的几种方式(RGB)

如下转换格式仅限于RGB格式的图像数据转换Bitmap。

第一种方式如下所示:

//将相机内部图像内存数据转为bitmap数据
if ((mBufferFilled.PixelFormat == "BGR8Packed") || (mBufferFilled.PixelFormat == "BGR8"))
{
    
    
	System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)mBufferFilled.Width, (int)mBufferFilled.Height, 		(int)mBufferFilled.Width * 3,
    System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)((ulong)mBufferFilled.MemPtr + 	mBufferFilled.ImageOffset));
    string filenameBMP = mBufferFilled.Parent.Parent.Model + "_ImageBGR8_" + mBufferFilled.FrameID + "_time_" + mBufferFilled.Timestamp + ".bmp";
    bitmap.Save(filenameBMP, System.Drawing.Imaging.ImageFormat.Bmp);
    System.Console.Write(" Image {0, 5:d}  saved as {1}\r\n", mBufferFilled.FrameID, filenameBMP);

	#region//bitmap的图像数据复制pBitmap
	Bitmap clonebitmap = (Bitmap)bitmap.Clone();
	BitmapData data = clonebitmap.LockBits(new Rectangle(0, 0, clonebitmap.Width, clonebitmap.Height), 	ImageLockMode.ReadOnly, clonebitmap.PixelFormat);
	clonebitmap.UnlockBits(data);
	pBitmap = clonebitmap;
	#endregion
}
        

第二种方式如下所示:


//将相机内部图像内存数据转为BGAPI2.Image
BGAPI2.Image pImage = pImgProcessor.CreateImage((uint)mBufferFilled.Width, (uint)mBufferFilled.Height, mBufferFilled.PixelFormat, mBufferFilled.MemPtr, mBufferFilled.MemSize);
BGAPI2.Image pTranImage = pImgProcessor.CreateTransformedImage(pImage, "BGR8");

//制作一个相关大小的空白Bitmap图像
int w = (int)pTranImage.Width;
int h = (int)pTranImage.Height;
pBitmap = new System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

//将图像数据写入前面生成的空白Bitmap图像
imagebuffer = pTranImage.Buffer;
System.Drawing.Imaging.BitmapData bmpdata;
System.Drawing.Imaging.BitmapData bmpdata2;

bmpdata = pBitmap.LockBits(prcSource, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
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);         
					

Baumer工业相机图像转换为Bitmap图像的优势

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

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

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

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

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

Baumer工业相机图像转换为Bitmap图像的行业应用

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

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

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

    1. 机器人技术: Bitmap图像可用于机器人应用,在生产过程中向机器人提供视觉反馈。它们使机器人能够识别和绕过障碍物,并执行任务,如精确地挑选和放置物体。
    1. 监视: Bitmap图像可用于监控系统,以检测和识别入侵者或嫌疑人。它们可以用来捕捉车牌、人脸和其他识别特征的图像。

猜你喜欢

转载自blog.csdn.net/xianzuzhicai/article/details/130549468