Baumer Industrial Camera How does Baumer industrial camera combine BGAPISDK and Halcon to realize image histogram algorithm enhancement (C#)

How does Baumer industrial camera combine BGAPISDK and Halcon to realize image histogram algorithm enhancement (C#)

  • Baumer industrial camera
  • Baumer industrial cameras use image algorithms to add technical background to images
  • Baumer industrial camera uses BGAPI SDK and Halcon to use histogram image enhancement algorithm
    • 1. Reference the appropriate class file
    • 2. BGAPI SDK references Halcon’s histogram transformation enhancement algorithm in the image callback
    • 3. Combined with Halcon to perform histogram transformation algorithm for image enhancement
  • Advantages of Baumer industrial cameras using image algorithms to enhance images
  • Industrial applications of Baumer industrial cameras using image algorithms to enhance images

?

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.

Baumer industrial cameras use image algorithms to increase the technical background of images

Industrial cameras often use various image algorithms to improve the quality of the images they capture. These algorithms are designed to improve image clarity, contrast, color accuracy, and overall image quality.

One of the most commonly used algorithms is the noise reduction algorithm. This algorithm is used to remove any random noise or grain that may be present in the image. Another popular algorithm is the image stabilization algorithm. This algorithm is used to reduce blur caused by camera shake.

Another popular image algorithm for industrial cameras is the edge enhancement algorithm. This algorithm is used to improve the sharpness of edges in an image. It works by detecting edges in an image and then increasing the contrast of those edges.

Histogram equalization is another image algorithm used in industrial cameras. The algorithm improves the contrast of an image by reassigning pixel values to cover the entire range of values available in the image.

Collectively, these image algorithms help industrial cameras capture clear and high-quality images. They play a vital role in modern imaging systems and are critical in fields such as robotics, microscopy and medical imaging.

In this article, we only simply use the image algorithm of Baumer industrial camera combined with Halcon to perform logarithmic Log transformation.

Baumer industrial camera uses BGAPI SDK and Halcon to use histogram image enhancement algorithm

The following introduces the demonstration of Baumer industrial camera in C# and Halcon directly performing histogram transformation and image enhancement in the callback function

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;

using HalconDotNet;

2.BGAPI SDK references Halcon’s histogram transformation enhancement algorithm in the image callback

The code is as follows (example), and the C# calling code is as follows:

void mDataStream_NewBufferEvent(object sender, BGAPI2.Events.NewBufferEventArgs mDSEvent)
{<!-- -->
    try
    {<!-- -->
        BGAPI2.Buffer mBufferFilled = null;
        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
        {<!-- -->
            #region//Get the current FrameID
            FrameIDInt = (int)mBufferFilled.FrameID;
            OnNotifySetFrameID(FrameIDInt. ToString());
            #endregion

            //Convert the internal image memory data of the camera to bitmap data
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)mBufferFilled.Width, (int)mBufferFilled.Height, (int)mBufferFilled.Width,
                System.Drawing.Imaging.PixelFormat.Format8bppIndexed, (IntPtr)((ulong)mBufferFilled.MemPtr + mBufferFilled.ImageOffset));
                                      
            #region//Mono image data conversion. Color image data conversion is different from this
            System.Drawing.Imaging.ColorPalette palette = bitmap.Palette;
            int nColors = 256;
            for (int ix = 0; ix < nColors; ix ++ )
            {<!-- -->
                uint Alpha = 0xFF;
                uint Intensity = (uint)(ix * 0xFF / (nColors - 1));
                palette.Entries[ix] = System.Drawing.Color.FromArgb((int)Alpha, (int)Intensity, (int)Intensity, (int)Intensity);
            }
            bitmap.Palette = palette;
            #endregion


            #region//Callback function to save the image function
            if (bSaveImg)
            {<!-- -->
                //Use bitmap's own function to save
                string strtime = DateTime.Now.ToString("yyyyMMddhhmmssfff");
                string saveimagepath = pImgFileDir + "\" + strtime + ".jpg";
                bitmap.Save(saveimagepath, System.Drawing.Imaging.ImageFormat.Bmp);
          
                bSaveImg = false;//Variable control single save image
            }
            #endregion

           //Convert Bitmap data to Halcon's Hobject
Rectangle rect = new Rectangle(0, 0, bmp. Width, bmp. Height);
BitmapDat srcBmpData=bmp.LockBits(rect,ImageLockMode.ReadOnly,
PixelFormat.Format8bppIndexed);
HOperatorSet.GenImage1(out image, "byte", bmp.Width, bmp.Height, srcBmpData.Scan0);
bmp. UnlockBits(srcBmpData);

            #region//Enhance the histogram transformation algorithm for grayscale images
            Hobject ImageEquHisto;
HOperatorSet. EquHistoImage (image, ImageEquHisto)
            #endregion


            #region//bitmap image data copy pBitmap
            Bitmap clonebitmap = (Bitmap)bmp. Clone();
            BitmapData data = clonebitmap.LockBits(new Rectangle(0, 0, clonebitmap.Width, clonebitmap.Height), ImageLockMode.ReadOnly, clonebitmap.PixelFormat);
            clonebitmap. UnlockBits(data);
            pBitmap = clonebitmap;
            #endregion
            #region//Display the pBitmap image data on the PictureBox control of the UI interface
            prcSource.X = 0;prcSource.Y = 0;
            prcSource.Width = (int)mBufferFilled.Width;prcSource.Height = (int)mBufferFilled.Height;
            System.Drawing.Graphics graph = System.Drawing.Graphics.FromHwnd(pictureBoxA.Handle);
            graph.DrawImage(pBitmap, prcPBox, prcSource, GraphicsUnit.Pixel);
            #endregion

            clonebitmap.Dispose(); //Clear the memory space occupied by the temporary variable clonebitmap
            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;
}

3. Combine Halcon with histogram transformation algorithm for image enhancement

The C# calling code is as follows:

//Convert Bitmap data to Halcon's Hobject
Rectangle rect = new Rectangle(0, 0, bmp. Width, bmp. Height);
BitmapDat srcBmpData=bmp.LockBits(rect,ImageLockMode.ReadOnly,
PixelFormat.Format8bppIndexed);
HOperatorSet.GenImage1(out image, "byte", bmp.Width, bmp.Height, srcBmpData.Scan0);
bmp. UnlockBits(srcBmpData);

   
#region//Enhance the histogram transformation algorithm for grayscale images
Hobject ImageEquHisto;
HOperatorSet. EquHistoImage (image, ImageEquHisto)
#endregion

#endregion

The rendering effect is as follows:
(No histogram equalization image algorithm used)
No histogram equalization image algorithm
(using histogram equalization image algorithm)

Advantages of Baumer industrial cameras using image algorithms to enhance images

  1. Improved image quality: With the use of image algorithms, industrial cameras can produce highly detailed and clear images. These algorithms reduce noise, accentuate edges, and increase contrast to produce better image quality.

  2. Increased Accuracy: Imagery algorithms can also provide highly accurate measurements and data. By using image analysis techniques such as edge detection and pattern recognition, industrial cameras can more precisely identify and measure objects.

  3. Cost-effectiveness: By improving image quality and accuracy, industrial cameras can reduce the need for manual inspection, reducing costs associated with quality control and product rejection.

  4. Increased efficiency: By automating the image analysis process, industrial cameras can increase throughput, reduce cycle times, and make production lines more efficient.

  5. Better Decision Making: With improved image quality and accuracy, industrial cameras can provide decision makers with highly detailed and reliable data, enabling them to make more informed decisions about production processes and quality control.

Industrial applications of Baumer industrial cameras using image algorithms to enhance images

Industrial cameras with image algorithms are widely used in various industries to enhance images to improve product quality, safety and efficiency. Here are some examples of its application:

  1. Manufacturing: Industrial cameras with imaging algorithms are used to inspect assembly lines for defects, check the quality of products, and ensure compliance with safety standards. They can also be used to inspect parts during manufacturing, which can help detect defects early and prevent costly production delays.

  2. Automotive industry: In the automotive industry, industrial cameras with image algorithms are widely used in safety inspections, to detect defects in auto parts, and to ensure the safety of drivers and passengers. They can also be used for damage assessment after an accident.

  3. Aerospace: Industrial cameras are used in the aerospace industry to inspect components of satellites, rockets, and other spacecraft during and after assembly. Image algorithms can help detect flaws and failures in critical components to ensure astronaut safety and the success of space missions.

  4. Medical: Industrial cameras with image algorithms are used in medical applications to detect and diagnose diseases and medical conditions. They are also used in medical research, analysis and monitoring the health of patients.

  5. Agriculture: Industrial cameras can be used to monitor the growth of crops, check the quality of agricultural products, and detect pests and diseases of crops. Image algorithms can help detect problems early, enabling farmers to take corrective action to protect their crops.

In all these industries, the use of industrial cameras with image algorithms greatly improves the efficiency and accuracy of image analysis, resulting in improved product quality, increased safety, and reduced costs.