Baumer industrial camera Baumer industrial camera uses BGAPI SDK to convert image data into several ways of Bitmap (C#) (RGB)

@[TOC](Baumer industrial camera Baumer industrial camera uses BGAPI SDK to convert image data into Bitmap several ways (C#) (RGB))

Baumer industrial camera

Baumer Industrial Cameras Baumer cameras are high-performance, high-quality industrial cameras that can be used in various application scenarios, such as object detection, counting and recognition, motion analysis and image processing.

Baumer's 10 Gigabit cameras have excellent image processing performance and can transmit high-resolution images in real time. In addition, the camera features fast data transfer, low power consumption, easy integration, and high scalability.
​Baumer
industrial cameras are often used in the field of high-speed synchronous acquisition due to their superior and stable performance and quality, and usually use various image algorithms to improve the quality of the captured images.

The technical background of converting Baumer industrial camera image data into Bitmap

Converting industrial camera image data to a bitmap format usually involves several steps:

  1. Acquire image data from industrial cameras, which may require the use of specialized image acquisition equipment.
  2. Convert image data from the raw format captured by the camera to a standardized format that can be processed by software.
  3. Image data is preprocessed to correct distortion or other problems that may have been present in the original image.
  4. Converts preprocessed image data to bitmap format, a common file format used to store images on computer systems.

The exact technical details of these steps will vary depending on the specific camera and software used, but some common tools and techniques used in the process may include:

  • SDK (Software Development Kit), providing libraries and APIs to access camera hardware and process raw image data
  • Image processing software, such as MATLAB or OpenCV, can be used to correct image distortions and apply filters or other adjustments to image data.
  • Image conversion libraries, such as ImageMagick or GDAL, can be used to convert preprocessed image data into a bitmap format.

This article introduces several methods of converting Baumer industrial camera image data into Bitmap images (color RGB) using the method of BGAPISDK.

Several ways for Baumer industrial cameras to use BGAPISDK to convert image data into Bitmap

The following introduces how to use BGAPISDK to convert raw image data to Bitmap in Baumer industrial camera in C# (color RGB)

1. Reference the appropriate class file

The code is as follows (example):

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. Several methods of BGAPI SDK raw image data as Bitmap (RGB)

The following conversion formats are limited to image data conversion Bitmap in RGB format.

The first way looks like this:

//将相机内部图像内存数据转为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
}
        

The second way looks like this:


//将相机内部图像内存数据转为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);         
					

Advantages of converting Baumer industrial camera images to Bitmap images

  1. Compatibility: Bitmap images are universally compatible and can be viewed on virtually any device or platform, including computers, smartphones and tablets.

  2. Simplified Processing: Bitmap images can be easily processed and edited using standard image processing software, making them ideal for automated processing in industrial applications.

  3. High-quality images: Bitmap images provide high resolution and color depth, resulting in high-quality images that accurately capture the details of objects and scenes.

  4. Reduced file size: Bitmap images are generally smaller in size than other image formats, which makes them easier to store and transfer.

  5. Ease of Integration: Bitmap images are easily integrated with other software and systems, making them ideal for a wide range of industrial applications.

Industrial application of Baumer industrial camera image conversion to Bitmap image

  1. Quality Control: Bitmap images can be used to detect defects, damage or imperfections in a product. For example, in the automotive industry, Bitmap images can be used to identify scratches, dents, and other defects on car bodies.

  2. 2. Machine vision: Bitmap images can be used in machine vision systems to detect and inspect parts of products during the manufacturing process. They can be used to measure dimensions, check for proper assembly, and detect defects or malfunctions.

  3. Medical Imaging: Bitmap images are widely used in medical imaging applications such as X-rays, CT scans, and MRI scans. They can be used to help diagnose conditions and plan treatment.

    1. Robotics: Bitmap images can be used in robotics applications to provide visual feedback to robots during production. They enable robots to recognize and navigate around obstacles and perform tasks such as picking and placing objects with precision.
    1. Surveillance: Bitmap images can be used in surveillance systems to detect and identify intruders or suspects. They can be used to capture images of license plates, faces and other identifying features.

Guess you like

Origin blog.csdn.net/xianzuzhicai/article/details/130549468