Baumer industrial camera Baumer industrial camera how to convert and display polarized camera image 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. ​The BGAPI SDK for
Baumer
Therefore, it is able to utilize the polarization information in the application. This application note describes how to acquire the image data of a polarization camera and convert and display the functions.

Technical background of polarized cameras from Baumer Industrial Cameras

The BGAPI SDK of Baumer industrial cameras can provide the raw image data of the camera. Halcon has an extremely large image processing library, which is very powerful in the field of image processing and has rich functions, and is used in industrial visual inspection.

The SDK (Software Development Kit) of industrial cameras is a set of software tools provided to facilitate developers to control and image capture industrial cameras. Halcon is a powerful machine vision software capable of image processing, analysis, recognition and many other tasks.

The polarization camera in Baumer Industrial Camera is based on the Sony IMC250MZR sensor. The sensor is coated with a metal mesh that filters polarization information from 4 adjacent pixels. The polarization angles are filtered and arranged in the manner of 0°, 45°, 90°, and 135°.
With this information, the following data can be calculated:
Angle of Polarization (AOP).
Intensity of linear degree of polarization (DOLP)
angle and orthogonal degree of polarization (ADOLP)
images.

The Baumer industrial camera displays the image of the polarized camera in the callback function through the BGAPI SDK

The Baumer industrial camera integrates the polarization function. The following describes how the Baumer industrial camera displays the image of the polarization camera in C#

Baumer industrial cameras convert and display polarized camera images in BufferEvent

The image processing library of the Baumer industrial camera BGAPI SDK provides an image algorithm that can convert the polarized image format into a suitable format.

Convert and display the polarization format image in the callback function, the C# calling code is as follows:

static void mDataStream_NewBufferEvent(object sender, BGAPI2.Events.NewBufferEventArgs mDSEvent)
{
    
    
            
    BGAPI2.Image imagePolarized = null;
    BGAPI2.ImageProcessor pImgProcessor = null;

    try
    {
    
    
        BGAPI2.Buffer mBufferFilled = null;
        //System.Drawing.Bitmap pBitmap = null;
        //Byte[] pImgBits;
        mBufferFilled = mDSEvent.BufferObj;
        if (mBufferFilled == null)
        {
    
    
            MessageBox.Show("Error: Buffer Timeout after 1000 ms!");
        }
        else if (mBufferFilled.IsIncomplete == true)
        {
    
    
            //MessageBox.Show("Error: Image is incomplete!");
            // queue buffer again
            mBufferFilled.QueueBuffer();

        }
        else
        {
    
    
            // get information about the image from the buffer object
            uint width = (uint)(mBufferFilled.Width);
            uint height = (uint)(mBufferFilled.Height);
            IntPtr pBufferData = mBufferFilled.MemPtr;
            ulong bufferDataSize = mBufferFilled.MemSize;
            ulong imageOffset = mBufferFilled.ImageOffset;
            ulong imageDataSize = (bufferDataSize > imageOffset) ? (bufferDataSize - imageOffset) : 0;
            IntPtr pImageData = (IntPtr)((ulong)(pBufferData) + imageOffset);

            string sComponent = "ADOLP";
            string sPixelFormatRaw = "";
            sPixelFormatRaw = "BaumerPolarized8";

            if (imagePolarized == null)
            {
    
    

                imagePolarized =actform.pImgProcessor.CreateImage(width, height, sPixelFormatRaw, pImageData, imageDataSize);
                        

                // Enable the component to be calculated, disable all others
                       
                EnableSingleComponent(imagePolarized, sComponent);
            }
            else
            {
    
    
                imagePolarized.Init(width, height, sPixelFormatRaw, pImageData, imageDataSize);
                /* As the pixel format is the same for all images captured, the enabled components and the active component selector
                    are preserved, so you don't need to enable components on every image. */
            }

            // Calculate the required Polarisation format using a direct transformation from raw polarized image.

            BGAPI2.Image component = actform.pImgProcessor.CreateTransformedImage(imagePolarized
                , (sComponent != "ADOLP") ? "Mono8" : "RGB8");

            System.Console.Write("  component image: {0}\r\n", component.NodeList["ComponentSelector"].Value);

                   
            IntPtr imagebuffer = new IntPtr();

            BGAPI2.Image pImage = actform.pImgProcessor.CreateImage((uint)mBufferFilled.Width, (uint)mBufferFilled.Height, mBufferFilled.PixelFormat, mBufferFilled.MemPtr, mBufferFilled.MemSize);
            BGAPI2.Image pTranImage = null;
            pTranImage = actform.pImgProcessor.CreateTransformedImage(pImage, "BGR8");

            int w = 0;
            int h = 0;
            w = (int)pTranImage.Width;
            h = (int)pTranImage.Height;



            imagebuffer = component.Buffer;

            //Now you have the Imagebuffer and can do everything with it you want
            if (actform.bFirstFrame)
            {
    
    
                actform.pImgBits = new Byte[w * h * 3];
                //actform.pBitmap = new Bitmap(w,h,PixelFormat.Format8bppIndexed);
                //pBitmap = new System.Drawing.Bitmap(w,h,System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                // actform.pBitmap = new System.Drawing.Bitmap(w,h,System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                actform.pBitmap = new System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                actform.prcSource.X = 0;
                actform.prcSource.Y = 0;
                actform.prcSource.Width = w;
                actform.prcSource.Height = h;
                actform.bFirstFrame = false;
            }
            System.Drawing.Imaging.BitmapData bmpdata;
 
            bmpdata = actform.pBitmap.LockBits(actform.prcSource, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            System.Runtime.InteropServices.Marshal.Copy(imagebuffer, actform.pImgBits, 0, w * h * 3);
            System.Runtime.InteropServices.Marshal.Copy(actform.pImgBits, 0, bmpdata.Scan0, w * h * 3);
            actform.pBitmap.UnlockBits(bmpdata);

            System.Drawing.Graphics graph = System.Drawing.Graphics.FromHwnd(actform.pictureBoxA.Handle);
            graph.DrawImage(actform.pBitmap, actform.prcPBox, actform.prcSource, GraphicsUnit.Pixel);

            if (actform.bSaveImg)
            {
    
    
                String strPath;
                String strtime;
                strtime = DateTime.Now.ToString("yyyyMMddhhmmss");
                strPath = actform.pImgFileDir + "\\" + strtime + sComponent + ".bmp";
                actform.pBitmap.Save(strPath,System.Drawing.Imaging.ImageFormat.Png);
                        
            }

            mBufferFilled.QueueBuffer();
        }
    }
    catch (BGAPI2.Exceptions.IException ex)
    {
    
    
        {
    
    
            string str2;
			str2 = string.Format("ExceptionType:{0}! ErrorDescription:{1} in function:{2}",ex.GetType(),ex.GetErrorDescription(),ex.GetFunctionName());
			MessageBox.Show(str2);
        }
    }
    return;
}

The specific steps of Baumer industrial camera BGAPI SDK converting and displaying polarization images

C# calls the core code as follows:

if (imagePolarized == null)
{
    
    

    imagePolarized =actform.pImgProcessor.CreateImage(width, height, sPixelFormatRaw, pImageData, imageDataSize);                        
    // Enable the component to be calculated, disable all others                       
    EnableSingleComponent(imagePolarized, sComponent);
}
 else
{
    
    
    imagePolarized.Init(width, height, sPixelFormatRaw, pImageData, imageDataSize);
     /* As the pixel format is the same for all images captured, the enabled components and the active component selector are preserved, so you don't need to enable components on every image. */
}
 
// Calculate the required Polarisation format using a direct transformation from raw polarized image.

BGAPI2.Image component = actform.pImgProcessor.CreateTransformedImage(imagePolarized
                , (sComponent != "ADOLP") ? "Mono8" : "RGB8");
System.Console.Write("  component image: {0}\r\n", component.NodeList["ComponentSelector"].Value);                 
IntPtr imagebuffer = new IntPtr();

BGAPI2.Image pImage = actform.pImgProcessor.CreateImage((uint)mBufferFilled.Width, (uint)mBufferFilled.Height, mBufferFilled.PixelFormat, mBufferFilled.MemPtr, mBufferFilled.MemSize);
BGAPI2.Image pTranImage = null;
pTranImage = actform.pImgProcessor.CreateTransformedImage(pImage, "BGR8");

Why Baumer Industrial Cameras Use Polarized Camera Data

Polarization cameras use polarization filters to separate the polarization states of light, which can improve the contrast of images, so that subtle surface morphology, reflection and transmittance information can be accurately recorded. This information is very important for industrial quality control, surface morphology evaluation, material research, etc.

Compared with traditional industrial cameras, polarization cameras can also reduce light interference, improve image details, enhance measurement accuracy, and better adapt to complex industrial environments.

Therefore, industrial cameras using polarization camera data can more accurately determine product quality and improve production efficiency and benefits.

Advantages of Baumer Industrial Cameras Using Polarization Cameras

  1. Suppression of light retroreflection: The problem of light source reflection often occurs in industrial sites, which will interfere with the quality of the image. Polarized cameras allow only certain angles of light to be captured, while light from reflections is filtered out.

  2. Improve the surface detection of materials: In many industrial productions, it is necessary to detect surface defects of materials and products, such as glass and plastic. Polarization cameras can identify and differentiate defects on the surface of these materials and improve detection accuracy and speed.

  3. Improve object shape detection: Products may be deformed or have irregular shapes during the production process. These factors will affect the effect of shooting with ordinary cameras. The polarization camera uses polarized light, which can reduce these interferences and improve the accuracy of detection results.

  4. Enhance the contrast of the image: The image detected by the polarization camera can show the details and characteristics of the object surface, not just the basic properties such as color and brightness, thereby improving the contrast and resolution of the image, making the detection result more accurate and reliable.

Industrial applications of Baumer industrial cameras using polarization cameras

Industrial cameras, especially in machine vision applications, polarized cameras are used analytically to solve many problems, including surface defect detection, glass or transparent plastic crack detection, etc. Since the polarization camera can distinguish between different reflectivities of the material surface, surface reflections can be reduced and the presence of blurred images can be reduced.

In manufacturing and industrial applications, polarization cameras can be used to detect stress in different directions, which allows them to identify and track objects with specific process marks, thereby improving the accuracy of manufacturing and assembly.

In addition, polarization cameras are used in quality control in the food and pharmaceutical industries to detect foreign bodies and impurities in different materials.

Industrial cameras There are many industrial applications using polarization cameras. Some of these include:

  1. Automotive manufacturing: Polarization cameras can be used to detect defects and foreign objects on automotive surfaces, such as grease and dirt.
  2. Plastic industry: Polarization cameras can detect cracks, pores and foreign objects in plastic products.
  3. Food industry: Polarization cameras can be used to detect foreign objects in food, such as bones, plastic fragments, etc.
  4. Electronics industry: Polarization cameras can be used to detect the quality of electronic components, such as the quality of semiconductor devices and electronic circuit boards.
  5. Textile industry: Polarization cameras can be used to detect the quality of textiles, such as fiber orientation, density and strength.

In general, polarization cameras are widely used in industry and can help manufacturers improve product quality, increase production efficiency and reduce production costs.

Guess you like

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