Baumer Industrial Camera Baumer Industrial Camera How to use BGAPI2.Buffer to BGAPI2.Image function through BGAPISDK (C#)

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.

Technical background of Baumer industrial camera BGAPISDK and image conversion

The BGAPI SDK for Baumer industrial cameras is a set of software development kits developed by Baumer for its camera product series. The SDK provides a set of APIs that enable developers to write professional applications to control, capture, process and display images and data from Baumer cameras. BGAPI SDK supports multiple programming languages, including C++, C#, Visual Basic, LabVIEW, Matlab, etc., and provides a large number of sample codes and documents to help users get started easily and quickly complete application development.

The BGAPI SDK provides a wealth of functions to control all parameters of the Baumer camera, including exposure time, gain, white balance, trigger mode, etc., and supports various data formats, such as Raw, BMP, JPG, etc., and also provides real-time display , data acquisition, image processing and other functions, providing developers with highly customized solutions. In addition, BGAPI SDK also supports the development of multi-camera systems, and can support various computer operating systems, such as Windows, Linux, Mac OS, etc.

This article introduces the function of using BGAPI SDK to convert BGAPI2.Buffer to BGAPI2.Image.

Baumer industrial camera BGAPI2.Buffer to BGAPI2.Image function

The following describes how to transfer BGAPI2.Buffer to BGAPI2.Image using BGAPISDK for Baumer industrial cameras in C#

1. Reference the appropriate class file

The code is as follows (example):

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;

2. Convert BGAPI2.Buffer to BGAPI2.Image through BGAPISDK

The core code of Baumer industrial camera BGAPI2.Buffer to BGAPI2.Image is as follows:

public class BufferHolder
{
    
    
    private ImageProcessor imageProcessor;
    private BGAPI2.Buffer buffer;

    private BGAPI2.Image transformedImage;
    public String BgapiPixelFormat {
    
     get; protected set; }
    public PixelFormat PixelFormat {
    
     get; protected set; }
    public Boolean IsColor {
    
     get; protected set; }
    public UInt32 BitsPerPixel {
    
     get; protected set; }
    public UInt32 Width {
    
     get; protected set; }
    public UInt32 Height {
    
     get; protected set; }
    public IntPtr ImageData {
    
     get; protected set; }
    public UInt32 ImageDataBytes {
    
     get; protected set; }



    public BufferHolder(BGAPI2.Buffer buffer)
    {
    
    
        this.buffer = buffer;
        //Debug.Print("CreateBufferHolder: " + buffer.Id);

        imageProcessor = new ImageProcessor();

        if (buffer.PixelFormat == "Mono8")
        {
    
    
            PixelFormat = PixelFormats.Gray8;
            BitsPerPixel = 8;
            IsColor = false;
            transformedImage = imageProcessor.CreateImage((UInt32)buffer.Width, (UInt32)buffer.Height, buffer.PixelFormat, buffer.MemPtr, buffer.MemSize);
        }
        else if (buffer.PixelFormat == "BGR8")
        {
    
    
            PixelFormat = PixelFormats.Bgr24;
            BitsPerPixel = 24;
            IsColor = true;
            transformedImage = imageProcessor.CreateImage((UInt32)buffer.Width, (UInt32)buffer.Height, buffer.PixelFormat, buffer.MemPtr, buffer.MemSize);
        }
        else if (buffer.PixelFormat.Contains("Mono"))
        {
    
    
            PixelFormat = PixelFormats.Gray8;
            BitsPerPixel = 8;
            IsColor = false;
            imageProcessor = new ImageProcessor();
            BGAPI2.Image image = imageProcessor.CreateImage((UInt32)buffer.Width, (UInt32)buffer.Height, buffer.PixelFormat, buffer.MemPtr, buffer.MemSize);
            transformedImage = imageProcessor.CreateTransformedImage(image,"Mono8");
            // transformedImage = image.TransformImage("Mono8");
        }
        else
        {
    
    
            PixelFormat = PixelFormats.Bgr24;
            imageProcessor = new ImageProcessor();
            BitsPerPixel = 24;
            IsColor = true;
            BGAPI2.Image image = imageProcessor.CreateImage((UInt32)buffer.Width, (UInt32)buffer.Height, buffer.PixelFormat, buffer.MemPtr, buffer.MemSize);
            transformedImage = imageProcessor.CreateTransformedImage(image, "BGR8");
            // transformedImage = image.TransformImage("BGR8");
        }

        this.Width = Convert.ToUInt32(transformedImage.Width);
        Height = Convert.ToUInt32(transformedImage.Height);
        BgapiPixelFormat = buffer.PixelFormat;
        ImageData = transformedImage.Buffer;
        ImageDataBytes = Width * Height * BitsPerPixel / 8;
    }

    ~BufferHolder()
    {
    
    
        //if (buffer.Parent.IsOpen && buffer.Parent.IsGrabbing)
        Debug.Print("BufferHolder.Destructor: QueueBuffer: " + buffer.Id);
        buffer.QueueBuffer();            
    }
}
    

Advantages of Baumer industrial camera BGAPI2.Buffer to BGAPI2.Image function

The advantages of converting BGAPI2.Buffer to BGAPI2.Image for Baumer industrial cameras are mainly to facilitate image processing and data transmission, and to improve the stability of the program. Here are the specific instructions:

Convenient image processing: After converting BGAPI2.Buffer to BGAPI2.Image, image processing operations can be performed more conveniently, such as deformation, rotation, cropping, etc., and the processed image data can also be directly output or saved as needed.

Facilitate data transmission: As an internal object of BGAPI2, BGAPI2.Image has higher data transmission efficiency and can be directly integrated with other image processing libraries, such as OpenCV.

Improve program stability: BGAPI2.Buffer will have a memory leak problem, but using BGAPI2.Image can effectively avoid this situation and improve program stability.

High flexibility: BGAPI2.Image can handle more image formats than BGAPI2.Buffer, including Mono8, Raw16, BGR8, etc., so it can adapt to a wider range of image processing scenarios.

Strong program readability: The code of BGAPI2.Image is more concise and more readable, which is convenient for later modification and maintenance.

Therefore, converting BGAPI2.Buffer to BGAPI2.Image can improve image data processing efficiency, program stability, adapt to a wider range of image processing scenarios, and reduce code complexity and readability.

Industrial application of Baumer industrial camera BGAPI2.Buffer to BGAPI2.Image

Baumer industrial camera BGAPI2.Buffer to BGAPI2.Image has been widely used in many fields, the following are some of the main application fields:

Electronics industry: The electronics industry needs the production and testing of micro-sized electronic components. Such data collection requires extremely high speed, high precision collection and image processing. At this time, BGAPI2.Buffer to BGAPI2.Image technology can process a large amount of data, adapt to data conversion and fast transmission, thus ensuring the accuracy and stability of data collection.
2 Food industry: The food industry needs to carry out quality inspection of food. BGAPI2.Buffer to BGAPI2.Image can help to take pictures of food, process images, check food defects, color and other attributes, so as to ensure the accuracy and stability of food testing.

Medical industry: In the medical industry, BGAPI2.Buffer to BGAPI2.Image can process high-resolution images such as CT and MRI, and help in accurate medical diagnosis and instrument detection.

Machinery manufacturing industry: In the machinery manufacturing industry, BGAPI2.Buffer to BGAPI2.Image can help to perform non-destructive detection and detailed analysis of workpieces, ensuring product quality and manufacturing accuracy.

To sum up, BGAPI2.Buffer to BGAPI2.Image technology is widely used in many fields such as industry, medical treatment, food, machinery manufacturing, etc. It can improve data acquisition and image resolution and stability, and help improve product quality and production efficiency.

Guess you like

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