Baumer industrial camera Baumer industrial camera how to use BGAPISDK and OpenCV to set the image for proportional display (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 OpenCV

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.

OpenCV is a popular and widely used computer vision library that provides a large number of image processing and computer vision algorithms, such as image filtering, feature extraction, object detection, etc. OpenCV can be integrated with the industrial camera SDK to process and analyze the images collected from the camera.

Using the Industrial Camera SDK in conjunction with OpenCV, developers can implement higher-level image processing and vision analysis applications. For example, they can use the industrial camera SDK for image acquisition and real-time display, and then use OpenCV for image processing and object detection. They can also use OpenCV's computer vision algorithms for specific applications, such as quality control, robot vision navigation, and automatic recognition.

This article describes how to use BGAPISDK and OpenCV to set the function of proportional display of images.

Baumer industrial camera uses BGAPISDK and OpenCV to set the image for proportional display function

The following describes how the Baumer industrial camera uses BGAPISDK and OpenCV to set the image for proportional display in C++

1. Reference the appropriate class file

The code is as follows (example):

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include "bgapi2_genicam/bgapi2_genicam.hpp"
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>

// OpenCV includes
#include <cv.h>
#include <highgui.h>

2. Set the image for proportional display function through BGAPISDK and OpenCV

Baumer industrial camera. The proportional display function of the image set by BGAPISDK and OpenCV will run in the image callback function. The core code is as follows:


SystemList 
Open a System 
Get the InterfaceList and fill it Open an Interface 

// OpenCV -> display scaled down image in MONO8 (width<800 1:1, 800<width<1500 1:2, width>1500 1:4)

// 4.1.9 Prepare the Camera Object for Image Handling
void BGAPI_CALLBACK imageCallback(void * callBackOwner, BGAPI::Image * pImage)
{
    
    
	BGAPI_RESULT res = BGAPI_RESULT_OK;
	unsigned char* imagebuffer = NULL;
	BGAPI_ImageHeader header;

	int width = 0;
	int height = 0;
	int transformbufferLen = 0;
	unsigned char* transformbuffer = NULL;

	int swc = 0;
	int hwc = 0;

	int timehigh;  //varaible for timestamp
	int timelow;   //variable for timestamp
	float timediff; //variable for frame rate
	float framerate; //variable for frame rate

	res = pImage->getNumber( &swc, &hwc );
	if( res != BGAPI_RESULT_OK )
	{
    
    
		printf("BGAPI::Image::getNumber Errorcode: %d", res);
	}

	res = pImage->getTimeStamp( &timehigh, &timelow ); //get timestamp
	if( res != BGAPI_RESULT_OK )
	{
    
    
		printf("BGAPI::Image::getTimeStamp Errorcode: %d", res);
	}
	timediff = timelow - timeold;    // calculate timestamp difference to last image
	timeold = timelow;				 // remember timelow for next image framerate calculation
	timediff = timediff*32,0;        // convert ticks to nsec (1 tick is 32 nsec, see TDS of the camera)
	framerate = 1000000000/timediff; //calculate framerate

	res = pImage->get( &imagebuffer );
	if( res != BGAPI_RESULT_OK )
	{
    
    
		printf( "pImage->get failed with %d\n", res );
		return;
	}
	else
	{
    
    
		res = pImage->getSize(&width, &height);
		if( res != BGAPI_RESULT_OK )
		{
    
    
			printf("BGAPI::Image::getSize Errorcode: %d", res);
		}
		//create two images (full image and scaled image)
		IplImage* im = 0;			// full image
		IplImage* tmpsize = 0;	    //scaled image

		//copy image of camera to an opencv image
		im = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U, 3); // color 8 bit * 3
		im->imageData = (char *)imagebuffer;
		
		//scale image if width > 800 pixels
		if(width > 800 && width < 1500)
		{
    
    
			CvSize size = cvSize(width/2,height/2);
			tmpsize=cvCreateImage(size,IPL_DEPTH_8U, 3);
			cvResize(im,tmpsize,CV_INTER_LINEAR);
		}
		else if (width > 1500)
		{
    
    

			CvSize size = cvSize(width/4,height/4);
			tmpsize=cvCreateImage(size,IPL_DEPTH_8U, 3);
			cvResize(im,tmpsize,CV_INTER_LINEAR);
		}
		else
		{
    
    
			CvSize size = cvSize(width,height);
			tmpsize=cvCreateImage(size,IPL_DEPTH_8U, 3);
			cvResize(im,tmpsize,CV_INTER_LINEAR);
		}

		//create display window for camera live image
		cvNamedWindow("Live", 1);

		//display live image with opencv
		//cvShowImage( "Live", im );	// full size
		cvShowImage( "Live", tmpsize ); // scaled down size

		//release opencv images
		cvReleaseImage(&tmpsize);
		cvReleaseImage( &im);
		cvWaitKey(1);	//?

		res = ((BGAPI::Camera*)callBackOwner)->setImage( pImage );
		if( res != BGAPI_RESULT_OK )
		{
    
    
			printf( "\nsetImage failed with %d\n", res );
		}
		printf("Image number %d. Frame Rate: %.2f \r", swc, framerate);
		fflush( stdout );
		return;
	}
}

    

Advantages of Baumer industrial cameras using BGAPISDK and OpenCV to set images for proportional display

Using BGAPI SDK and OpenCV to set the scale display of industrial camera images has the following advantages:

High-quality image processing: Using BGAPI SDK and OpenCV can achieve high-quality image processing, including zooming in and out of images, resizing images, and more. This can enhance the details of the image, revealing more image details.

Strong Customizability: Using BGAPI SDK and OpenCV, camera settings can be customized according to needs, which can help users better meet the needs and production requirements in different environments.

Less code writing: Using BGAPI SDK and OpenCV can reduce the amount of code that needs to be written, and can reduce the occurrence of code errors and improve development efficiency.

More beautiful display effect: BGAPI SDK and OpenCV support a variety of image processing and display operations, which can provide richer image display effects.

Support multiple platforms: BGAPI SDK and OpenCV can span multiple platforms (such as Windows, Linux, etc.), which makes it possible to work in the same application and make it more versatile.

Faster display speed: BGAPI SDK and OpenCV support hardware acceleration, which can improve the speed and smoothness of image processing, and is more suitable for processing large amounts of data and continuous streaming images.

Industrial application of Baumer industrial camera using BGAPISDK and OpenCV to set image for proportional display

Industrial cameras use the BGAPI SDK and OpenCV to set images for proportional display applications are very extensive, the following are examples of some major industries:

Manufacturing: Industrial cameras can be used to inspect and measure the size, shape and surface quality of parts in manufacturing. Using the BGAPI SDK and OpenCV enables users to perform precise, high-quality processing on images and increase productivity.

Logistics and Security: Industrial cameras can be used in logistics and security for vehicle or person recognition. Using BGAPI SDK and OpenCV enables operators to clearly identify and track objects in images.

Medical industry: Industrial cameras can be used to take images of different parts so that doctors can make better use of BGAPI SDK and OpenCV to show doctors high-quality images and help them diagnose and treat more accurately.

Automated production: Industrial cameras can be integrated in automated production processes, such as inspecting parts and product quality. Using the BGAPI SDK and OpenCV gives you greater control and improves productivity and quality.

Environmental monitoring: Industrial cameras would be useful for monitoring large environments such as cities due to their ability to take pictures quickly. Using BGAPI SDK and OpenCV, it is possible to accurately analyze the environmental problems in the picture, such as the concentration of pollutants, etc.

Agricultural industry: Industrial cameras can be used to detect crops and collect information to help farmers better manage their farmland. Using BGAPI SDK and OpenCV, different crops can be quickly analyzed and compared, and measurement accuracy can be improved, thereby improving agricultural production efficiency.

Guess you like

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