Baumer工业相机

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

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

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

Baumer工业相机BGAPISDK和图像放大缩小的技术背景

Baumer工业相机的BGAPI SDK是Baumer公司开发的针对其相机产品系列的一套软件开发工具包。该SDK提供了一组API,使开发人员可以编写专业应用程序,从而控制、捕获、处理和显示Baumer相机的图像和数据。BGAPI SDK支持多种编程语言,包括C++、C#、Visual Basic、LabVIEW、Matlab等,并提供了大量示例代码和文档,以帮助用户轻松上手,快速完成应用程序的开发。

BGAPI SDK提供了丰富的功能,可以控制Baumer相机的所有参数,包括曝光时间、增益、白平衡、触发模式等,以及支持各种数据格式,例如Raw、BMP、JPG等,同时还提供了实时显示、数据采集、图像处理等功能,为开发人员提供了高度定制化的解决方案。此外,BGAPI SDK还支持多相机系统的开发,并可支持各种计算机操作系统,如Windows、Linux、Mac OS等。

可以通过使用工业相机的软件开发工具包(SDK)来放大和缩小图像以及显示它们。这通常涉及使用SDK中的函数或方法来访问相机的图像帧,并将其传递给一个显示器控件或绘图区域。

本文介绍的使用BGAPI SDK将相机图像相机图像图像放大缩小的功能。

Baumer工业相机通过BGAPISDK将相机图像图像放大缩小功能

下面介绍在C#里Baumer工业相机如何通过BGAPISDK将相机图像图像放大缩小的方式

1.引用合适的类文件

代码如下(示例):

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.通过BGAPISDK将相机图像图像放大缩小功能

Baumer工业相机将相机图像图像放大缩小功能核心代码如下所示:

SystemList 
Open a System 
Get the InterfaceList and fill it Open an Interface 
private void mPictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    Bitmap bmptodraw = null;
    //Bitmap cdbmptodraw = null;
    //Bitmap chbmptodraw = null;
    Rectangle bitmap_complete = new Rectangle(); //rectangle over all bitmaps
    Rectangle src_complete = new Rectangle();
    Rectangle dest_complete = new Rectangle();
    double ratioW = 1.0f;
    double ratioH = 1.0f;
    Rectangle bitmap_image = new Rectangle();
    //Rectangle bitmap_dist = new Rectangle();
    //Rectangle bitmap_header = new Rectangle();
    Point pictureboxlocation = new Point();
    Rectangle src_image = new Rectangle();
    //Rectangle src_header = new Rectangle();
    //Rectangle src_dist = new Rectangle();
    Rectangle dest_image = new Rectangle();
    //Rectangle dest_header = new Rectangle();
    //Rectangle dest_dist = new Rectangle();


    //int ret = 0;
    //SizeF header_size = new SizeF();
    int idx = -1;
    Size destbmp = new Size(1, 1);



    if (mbNewImageReady == true)
    {
        mbDrawFirstBitmap = !mbDrawFirstBitmap;
        mbFlipDrawImage = true;
    }

    mbNewImageReady = false;
    if (mbDrawFirstBitmap)
    {
        idx = 0;
        if (mImageData[0].bgapiImage == null)
            return;
        bmptodraw = mImageData[0].bmp;
    }
    else
    {
        idx = 1;
        if (mImageData[1].bgapiImage == null)
            return;
        bmptodraw = mImageData[1].bmp;
    }

    if (!mShowImage)
        return;

    if (mShowImage)
    {
        //destbmp.Width += bmptodraw.Width;
        //destbmp.Height += bmptodraw.Height;
        bitmap_complete.Width += bmptodraw.Width;
        bitmap_complete.Height = Math.Max(bitmap_complete.Height, bmptodraw.Height);
    }
          
    //calculate the destination rectangle of the several data blocks
    int nwx = 0;
    if (mShowImage)
    {
        bitmap_image.X = nwx;
        bitmap_image.Y = 0;
        bitmap_image.Width = bmptodraw.Width;
        bitmap_image.Height = bmptodraw.Height;
        nwx += bmptodraw.Width;
    }
    else
    {
        if (!bitmap_image.IsEmpty)
            bitmap_image.X = bitmap_image.Y = bitmap_image.Width = bitmap_image.Height = 0;
    }
            
    //adjust pictureBox size 
    if (mSizeMode == PictureBoxSizeMode.Normal)
    {
        this.pictureBox1.Width = bitmap_complete.Width;
        this.pictureBox1.Height = bitmap_complete.Height;
        this.panel1.AutoScroll = true;
    }
    else if (mSizeMode == PictureBoxSizeMode.StretchImage)
    {
        if (mbFitToWindow)
        {
            ratioW = (double)bitmap_complete.Width / (double)panel1.Width;
            ratioH = (double)bitmap_complete.Height / (double)panel1.Height;
            if (ratioW > ratioH)
            {
                this.pictureBox1.Height = (int)((double)bitmap_complete.Height / ratioW);
                this.pictureBox1.Width = panel1.Width;
            }
            else
            {
                this.pictureBox1.Width = (int)((double)bitmap_complete.Width / ratioH);
                this.pictureBox1.Height = panel1.Height;
            }
            this.panel1.AutoScroll = false;
        }
        else
        {//--1
            this.pictureBox1.Width = Convert.ToInt32(bitmap_complete.Width * ZOOMFACTOR);
            this.pictureBox1.Height = Convert.ToInt32(bitmap_complete.Height * ZOOMFACTOR);
            this.panel1.AutoScroll = true;
        }
    }
    else
    {
        if (bitmap_complete.Width > panel1.Width)
            this.pictureBox1.Width = panel1.Width;
        else
            this.pictureBox1.Width = bitmap_complete.Width;

        if (bitmap_complete.Height > panel1.Height)
            this.pictureBox1.Height = panel1.Height;
        else
            this.pictureBox1.Height = bitmap_complete.Height;
        this.panel1.AutoScroll = false;
    }

    //adjust picture box location
    if (mSizeMode == PictureBoxSizeMode.Normal)
        pictureboxlocation = new Point(panel1.AutoScrollPosition.X, panel1.AutoScrollPosition.Y);
    else if (mSizeMode == PictureBoxSizeMode.StretchImage)
    {
        if (mbFitToWindow)
        {
            if (ratioW > ratioH)
            {
                pictureboxlocation.X = 0;
                pictureboxlocation.Y = (int)(panel1.Height / 2) - (int)(this.pictureBox1.Height / 2);
            }
            else
            {
                pictureboxlocation.X = (int)(panel1.Width / 2) - (int)(this.pictureBox1.Width / 2);
                pictureboxlocation.Y = 0;
            }
        }
        else
            //--1
            pictureboxlocation = new Point(panel1.AutoScrollPosition.X, panel1.AutoScrollPosition.Y);
    }
    else //center image
    {
        if (bitmap_complete.Width > panel1.Width)
            pictureboxlocation.X = 0;
        else
            pictureboxlocation.X = (int)(panel1.Width / 2) - (int)(bitmap_complete.Width / 2);

        if (bitmap_complete.Height > panel1.Height)
            pictureboxlocation.Y = 0;
        else
            pictureboxlocation.Y = (int)(panel1.Height / 2) - (int)(bitmap_complete.Height / 2);
    }

    //calculate source rectangles
    if (mSizeMode == PictureBoxSizeMode.Normal)
    {
        src_complete.X = 0;
        src_complete.Y = 0;
        src_complete.Width = bitmap_complete.Width;
        src_complete.Height = bitmap_complete.Height;
        src_image = new Rectangle(0, 0, bitmap_image.Width, bitmap_image.Height);
    }
    else if (mSizeMode == PictureBoxSizeMode.StretchImage)
    {
        if (mbFitToWindow)
        {
            src_complete.X = 0;
            src_complete.Y = 0;
            src_complete.Width = bitmap_complete.Width;
            src_complete.Height = bitmap_complete.Height;
            src_image = new Rectangle(0, 0, bitmap_image.Width, bitmap_image.Height);
        }
        else
        {
            src_complete.X = 0;
            src_complete.Y = 0;
            src_complete.Width = bitmap_complete.Width;
            src_complete.Height = bitmap_complete.Height;
            src_image = new Rectangle(0, 0, bitmap_image.Width, bitmap_image.Height);
        }
    }
    else
    {
        if (bitmap_complete.Width > panel1.Width)
            src_complete.X = (int)(bitmap_complete.Width / 2) - (int)(panel1.Width / 2);
        else
            src_complete.X = 0;
        src_complete.Width = this.panel1.Width;

        if (bitmap_complete.Height > panel1.Height)
            src_complete.Y = (int)(bitmap_complete.Height / 2) - (int)(panel1.Height / 2);
        else
            src_complete.Y = 0;
        src_complete.Height = this.pictureBox1.Height;
        src_image = src_complete;
        src_image.Intersect(bitmap_image);
        src_image.X -= bitmap_image.X;
        src_image.Y -= bitmap_image.Y;
    }

    //calculate destination rectangles
    if (mSizeMode == PictureBoxSizeMode.Normal)
    {
        dest_complete.X = 0;
        dest_complete.Y = 0;
        dest_complete.Width = bitmap_complete.Width;
        dest_complete.Height = bitmap_complete.Height;
        dest_image = bitmap_image;
    }
    else if (mSizeMode == PictureBoxSizeMode.StretchImage)
    {
        if (mbFitToWindow)
        {
            dest_complete.X = 0;
            dest_complete.Y = 0;
            dest_complete.Width = this.pictureBox1.Width;
            dest_complete.Height = this.pictureBox1.Height;

            dest_image.X = this.pictureBox1.Width * bitmap_image.Left / src_complete.Width;
            dest_image.Y = this.pictureBox1.Height * bitmap_image.Top / src_complete.Height;
            dest_image.Width = this.pictureBox1.Width * bitmap_image.Width / src_complete.Width;
            dest_image.Height = this.pictureBox1.Height * bitmap_image.Height / src_complete.Height;
        }
        else
        {
            dest_complete.X = 0;
            dest_complete.Y = 0;
            dest_complete.Width = this.pictureBox1.Width;
            dest_complete.Height = this.pictureBox1.Height;

            dest_image.X = (int)(bitmap_image.X * ZOOMFACTOR);
            dest_image.Y = (int)(bitmap_image.Y * ZOOMFACTOR);
            dest_image.Width = (int)(bitmap_image.Width * ZOOMFACTOR);
            dest_image.Height = (int)(bitmap_image.Height * ZOOMFACTOR);
        }
    }
    else
    {
        dest_complete.X = 0;
        dest_complete.Y = 0;
        dest_complete.Width = this.pictureBox1.Width;
        dest_complete.Height = this.pictureBox1.Height;
        dest_image = src_complete;
        dest_image.Intersect(bitmap_image);
        dest_image.Offset(src_complete.X * (-1), src_complete.Y * (-1));
    }

    this.pictureBox1.Location = pictureboxlocation;
    try
    {
        if (mShowImage)
        {
            e.Graphics.DrawImage(bmptodraw,
                        dest_image,
                        src_image.Left,
                        src_image.Top,
                        src_image.Width,
                        src_image.Height,
                        GraphicsUnit.Pixel);
        }
    }
    catch
    {
        System.Windows.Forms.MessageBox.Show("Exception while refresh image window");
    }
}
private void DrawingTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    lock (mImageData)
    {
        if (mbNewImageAvailable)//1
        {
            if (mbNewImageReady == false)//2
            {
                if (mbDrawFirstBitmap == true)//3
                {
                    if (mImageData[1].bgapiImage != null)//4
                    {
                        lock (mCamera.BackImagesColl)
                            mCamera.BackImagesColl.Add(mImageData[1].bgapiImage);
                    }
                    mImageData[1].bgapiImage = mNewBgapiImage;
                    CreateBitmap(ref mImageData[1].bgapiImage, ref mImageData[1].bmp, BGAPI.BGAPI_ChunkId.BGAPI_CHUNKID_IMAGE);
                          
                }
                else//3 --mbDrawFirstBitmap == false
                {
                    if (mImageData[0].bgapiImage != null)//--4
                    {
                        //transformation preset
                        lock (mCamera.BackImagesColl)
                            mCamera.BackImagesColl.Add(mImageData[0].bgapiImage);
                    }
                    mImageData[0].bgapiImage = mNewBgapiImage;
                    CreateBitmap(ref mImageData[0].bgapiImage, ref mImageData[0].bmp, BGAPI.BGAPI_ChunkId.BGAPI_CHUNKID_IMAGE);
                            
                }
                mbNewImageAvailable = false;
                mbNewImageReady = true;
                pictureBox1.Invalidate(pictureBox1.ClientRectangle, false);
            }
        }
    }
}
    

Baumer工业相机将相机图像放大缩小显示的优势

提高图像细节:通过放大的图像,您可以看到更多的细节,帮助您更好地分析和理解图像。

方便捕获处理:放大图像可以使需要测量或分析的目标更易于捕获并进行后续处理,提高了工作效率。

减少错误率:当需要进行目标定位或测量时,放大图像可以帮助您减少错误率,提高测量的精度。

对于设备来说更加灵活:随着工艺和设备的不断改进,相机调整成为会更加灵活,可以根据需要调整图像大小和显示比例。

更好的用户体验:放大缩小图像可以提供更好的用户体验,使用户更容易观察图像细节,并且更容易理解和分析图像。

Baumer工业相机将相机图像放大缩小显示的行业应用

制造业:在制造业中,工业相机通常用于检查和测量零件的尺寸、形状和表面质量。工业相机的放大缩小功能可以帮助操作员更好地观察图像,提高生产效率。

医疗行业:在医疗行业中,工业相机可以用于拍摄骨骼、血管或其他器官的图像。放大缩小功能可以使医生更好地观察和分析这些图像,并帮助他们作出更好的诊断。

. 食品行:在食品行业中,工业相机可以用于检查食品的质量和安全性。放大缩小功能可以使操作员更好地观察食品的细节并检查有无缺陷。

运输和安保:在运输和安保中,工业相机可以用于识别车辆和个人。放大缩小功能可以帮助识别和跟踪目标更加准确和快速。

环境监测:工业相机可以用于环境监测如气象、污染物。放大缩小功能可以帮助检测和分析图片中存在的环境问题,如污染物分布区域。

06-23 06:14