Baumer Industrial Camera How Baumer Industrial Camera uses BGAPISDK and OpenCV to generate video (C++)

Baumer Industrial Camera

Baumer Industrial Cameras Baumer cameras are high-performance, high-quality industrial cameras that can be used in a variety of applications such as object detection, counting and identification, motion analysis and image processing

Baumer’s 10GbE 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. Various image algorithms are usually used to improve the quality of the images they capture.

Technical background of video generated by Baumer industrial camera BGAPISDK

The BGAPI SDK of Baumer industrial cameras is a software development toolkit 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.

BGAPI SDK provides rich functions that can control all parameters of Baumer cameras, 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 collection, 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.

The technical background of the video function generated by Baumer industrial cameras through SDK mainly involves the two core links of image processing and video generation.

In terms of image processing, Baumer industrial cameras use the OpenCV library for image processing. OpenCV is an open source computer vision and machine learning software library that contains many algorithms and functions that can realize image reading, preprocessing, feature extraction, target detection and other functions. Baumer industrial cameras achieve efficient processing and analysis of images by referencing the OpenCV library.

In terms of video generation, Baumer industrial cameras use GAPISDK (a software development kit independently developed by Baumer) to further process image data and generate videos. GAPISDK is optimized for the characteristics and performance of Baumer industrial cameras, which can better utilize the camera’s hardware resources and improve processing speed and efficiency. At the same time, GAPISDK also provides a rich API interface and function library, which can be easily developed and customized to meet the needs of different users.

By referencing the OpenCV library and GAPISDK, Baumer industrial cameras implement efficient image processing and video generation functions. This not only improves the efficiency of image processing in industrial production, but also further promotes the development of industrial automation and intelligence.

This article introduces the function of generating videos by integrating BGAPI SDK.

Baumer industrial cameras cycle through BGAPISDK to find camera sequence functions

The following describes how Baumer industrial cameras loop through BGAPISDK to find camera sequence functions in C++

1. Reference appropriate class files
The code is as follows (example):

/* Copyright 2019-2020 Baumer Optronic */
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

// This example shows how to convert a set of images (in alphabetical order) into a video file using the openCV
// library. If no command line parameters are given the example will generate a set of images in the folder
// 'ExampleImages' (if not empty the images will be used) and create a video file 'ExampleVideo.avi' from this
// images

// openCV must be available!!!

//Command Line Parameters
//
// --imgDir: sets the directory where source images are located, if not set, the default 'ExampleImages' will be used
// Important: All image files need to have the same dimension for the video creation to be successful
// Tip: You can use the Baumer CameraExplorer Image Recorder functionality to record some example images
//
// --videoFile: sets the output file name for the created video, if not, the default 'ExampleVideo.avi' will be used

const std::string gc_sImageDirDefault = "ExampleImages";
const std::string gc_sVideoFileNameDefault = "ExampleVideo.avi";

#if defined(_WIN32)
# include <direct.h>
#else
# include <sys/stat.h>
#endif
#include "Arguments.h"
#include "HelperFunctions.h"

#define EXAMPLE_IMAGES 1

#if defined(_WIN32)
static const char c_cPathSeparator = '';
#else
static const char c_cPathSeparator = '/';
#endif

The following is the code in CMakeLists:

cmake_minimum_required(VERSION 3.10)

message(STATUS "## ${CMAKE_CURRENT_BINARY_DIR} ##")
get_filename_component(EXAMPLE_NAME "${CMAKE_CURRENT_BINARY_DIR}" NAME)
string(SUBSTRING ${EXAMPLE_NAME} 0 3 TARGET_NAME)
project(${EXAMPLE_NAME})

set(SOURCE_FILES
    ${EXAMPLE_NAME}.cpp
    ${SHARED_DIR}/Arguments.cpp
    ${SHARED_DIR}/Arguments.h
    ${SHARED_DIR}/HelperFunctions.cpp
    ${SHARED_DIR}/HelperFunctions.h
    UserTemplate.user
)
include_directories(${SHARED_DIR})

# =================== Add openCV support! ========================== ====
if(ENABLE_OPENCV)
    message(STATUS "\
======================== Configure OpenCV library ================== =====")
    set(BUILD_SHARED_LIBS OFF)
    find_package(OpenCV QUIET COMPONENTS core highgui imgproc) # some packages in OpenCV obsolete ?!?
    if(OpenCV_FOUND)
        message(STATUS "OpenCV Version: '${OpenCV_VERSION}'")
        message(STATUS "OpenCV LibDir: '${OpenCV_LIB_PATH}'")

        if(OpenCV_VERSION_MAJOR GREATER "2")
            add_definitions(-DUSE_OCL_COMPONENT=3)
            find_package(OpenCV COMPONENTS videoio imgcodecs)
            if(NOT OpenCV_FOUND)
                message(STATUS "OpenCV has no Video support!")
            endif()
        elseif (OpenCV_VERSION_MAJOR LESS "2")
            option(ENABLE_OPENCV "Enable OpenCV Support in SDK example" OFF)
            option(OpenCV_FOUND "OpenCV Found" OFF)
            message(STATUS "OpenCV with Version 1.x not supported!")
        else() # OpenCV Version 2.x
            find_package(OpenCV COMPONENTS ocl) # this package in OpenCV obsolete ?!?
        endif()
    else()
        message(STATUS "OpenCV not supported!")
    endif()

    if(OpenCV_FOUND AND ENABLE_OPENCV)
        add_definitions(-DUSE_OPENCV=1)
        list(APPEND INCLUDE_DIR ${OpenCV_INCLUDE_DIRS})
        message(STATUS "OpenCV Libs: '${OpenCV_LIBS}'")
    else()
        message(STATUS "This means program '${PROJECT_NAME}' couldn't run properly!")
        message(STATUS "Please set the correct search path for the OpenCV package and/or use OpenCV > 3.0!")
        message(STATUS "============================================== =======================\
")
    endif()
endif()

message(STATUS "## OpenCV is configured: ${PROJECT_NAME}! ##\
")
message(STATUS "============================================== =======================\
")

add_executable(${TARGET_NAME} ${SOURCE_FILES})
if(OpenCV_FOUND)
    target_link_libraries(${TARGET_NAME} "${OpenCV_LIBS}")
endif()

set_property(TARGET ${TARGET_NAME} PROPERTY PROJECT_LABEL ${PROJECT_NAME})
set_property(TARGET ${TARGET_NAME} PROPERTY OUTPUT_NAME ${PROJECT_NAME})

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    if(OpenCV_FOUND AND OpenCV_SHARED)
        get_target_property(OpenCV_DLL_DEBUG opencv_world IMPORTED_LOCATION_DEBUG)
        get_target_property(OpenCV_DLL_RELEASE opencv_world IMPORTED_LOCATION_RELEASE)
        set(OpenCV_WorldLib "$<$<CONFIG:debug>:${OpenCV_DLL_DEBUG}>$<$<CONFIG:release>:${OpenCV_DLL_RELEASE}>")
        add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OpenCV_WorldLib}" $<TARGET_FILE_DIR:${TARGET_NAME}>
            COMMENT "copy OpenCV library to output directory")
    endif()

    set(USER_FILE ${TARGET_NAME}.vcxproj.user)
    configure_file(UserTemplate.user ${USER_FILE} @ONLY)
endif()

2. The function of generating videos through BGAPISDK

The core code for the Baumer industrial camera to generate video through the BGAPI SDK is as follows:

//------------------------------------------------ -------------------------------------------------- -----------------------
// Here you can use argument parameters for sImgDirectory and sVideoFileName!
int main(int argc, char* argv[]) {
    std::string sImgDirectory;
    std::string sVideoFileName;
    static const Argument argumentList[] = {
        { & amp;sImgDirectory, "p", "imgPath", false , argumentString, 0, "Pathname", "Image Path" },
        { & amp;sVideoFileName, "v", "videoFile", false , argumentString, 0, "Filename", "Video File Name" },
    };
    parseArguments(argumentList, (sizeof(argumentList)/sizeof(argumentList[0])), argc, argv);

    int iReturnCode = 0;
    try {
        std::cout << std::endl;
        std::string sExampleName = __FILE__;
        sExampleName = sExampleName.substr(sExampleName.find_last_of(c_cPathSeparator) + 1);

        writeHeader1(sExampleName);
        writeHeader1("EXAMPLE VIDEO FROM IMAGE DIRECTORY");

// The flag USE_OPENCV is set by the CMake run, CMake tries to find OpenCV >= Version 2
#if USE_OPENCV // OpenCV

// The flag USE_OCL_COMPONENT is set by the CMake run if OpenCV can use OpenCL to speed up it's functionality
# if USE_OCL_COMPONENT
        if (cv::ocl::haveOpenCL()) {
            cv::ocl::Context context;
            if (!context.create(cv::ocl::Device::TYPE_GPU)) {
                // FAIL: no context
            } else {
                std::cout << "OpenCL available!" << std::endl;

                for (size_t i = 0; i < context.ndevices(); i + + ) {
                    cv::ocl::Device clDevice = context.device(i);
                    std::cout << clDevice.vendorName() << std::endl;
                    std::cout << clDevice.driverVersion() << std::endl << std::endl;
                }
            }
        }
# endif // USE_OCL_COMPONENT
        stringvec fileList;

        std::string imgDir;
        if (!sImgDirectory.empty()) {
            imgDir = sImgDirectory;
        } else {
            imgDir = gc_sImageDirDefault;
            std::cout << "Using default setting for 'imgPath': " << imgDir << std::endl;
            // Create the directory below the execution dir
#if defined(_WIN32)
            _mkdir(imgDir.c_str());
#else
            mkdir(imgDir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
#endif
        }
#ifdef WITH_REGEX
        readDirectory(imgDir, ".*.jpg", & amp;fileList);
#else
        readDirectory(imgDir, "*.jpg", & amp;fileList);
#endif
        size_t slashPos = imgDir.find_last_of("/");
        std::string exampleDir = imgDir;
        if (slashPos < std::string::npos)
            exampleDir = imgDir.substr(slashPos + 1);

        if (fileList.empty() & amp; & amp; (exampleDir == gc_sImageDirDefault)) {
            // Create some images if the image directory identical with the default
            std::cout << "Here were some test images with changing colors created!" << std::endl;
            createExampleImages(imgDir, cv::Size(1000, 500));
            readDirectory(imgDir, ".*.jpg", & amp;fileList);
        }

        // If the fileList is empty, exit the program:
        if (fileList.empty()) {
            std::cout << "No Image(s) found!" << std::endl;
            return 102;
        }
        std::sort(fileList.begin(), fileList.end(), std::less<std::string>());

        // Now there are some pictures in the list - and you can create a video file from this
        cv::Mat frame = cv::imread(imgDir + "/" + fileList.at(0));
        cv::Size frameSize = cv::Size(frame.cols, frame.rows);

        int frames_per_second = 10;
        // Create and initialize the VideoWriter object:
        // std::string sVideoFileName;
        if (sVideoFileName.empty()) {
            sVideoFileName = gc_sVideoFileNameDefault;
            std::cout << "Using default setting for 'videoFile': " << sVideoFileName << std::endl;
        }
#ifdef CV_FOURCC_MACRO
        cv::VideoWriter oVideoWriter(sVideoFileName,
            CV_FOURCC('M', 'J', 'P', 'G'), // cv::VideoWriter::fourcc
            frames_per_second, frameSize, true);
#else
        cv::VideoWriter oVideoWriter(sVideoFileName,
            cv::VideoWriter::fourcc('M', 'J', 'P', 'G'),
            frames_per_second, frameSize, true);
#endif

        // If the VideoWriter object is not initialized successfully, exit the program:
        if (oVideoWriter.isOpened() == false) {
            std::cout << "Cannot save the video to a file" << std::endl;
            return 103;
        }

        // ... and now write all pictures in the video file
        int iNumber = 0;
        for (std::string filename : fileList) {
            std::cout << "file" << ( + + iNumber) << ": " << filename << std::endl;
            cv::Mat frame2 = cv::imread(imgDir + "/" + filename);
            if (!frame2.empty()) // use valid picture only!
                oVideoWriter.write(frame2);
        }
        oVideoWriter.release();

#else // USE_OPENCV
        // If we could not find OpenCV this text will be displayed.
        std::cout << "Without OpenCV we cannot create the video in this example!" << std::endl;
        std::cout << "Availability is checked while CMake creates this project." << std::endl;
        std::cout << "Please install OpenCV (version 2.3 or later) or set 'OpenCV_DIR' to the" << std::endl;
        std::cout << "correct path in the CMakeTests.txt script or as a variable in your environment" << std::endl;
        std::cout << "and run CMake again. " << std::endl;
        std::cout << "#####################################" << std: :endl << std::endl;

#endif // USE_OPENCV

        std::cout << std::endl;
        std::cout << "End" << std::endl << std::endl;
    }
    catch (const std::exception & amp; e) {
        iReturnCode = (iReturnCode == 0) ? 1 : iReturnCode;
        std::cout << "unhandled std exception: '" << e.what() << "'" << std::endl;
    }
    catch (...) {
        iReturnCode = (iReturnCode == 0) ? 1 : iReturnCode;
        std::cout << "unhandled exception" << std::endl;
    }

    if (iReturnCode != 0)
        std::cout << "Example ends with error: " << iReturnCode << std::endl;

    std::cout << "Press ENTER to close the program!" << std::endl;
    int endKey = std::cin.get();
    endKey = endKey; // unused variable
    return iReturnCode;
}

Advantages of Baumer industrial cameras using GAPISDK to generate video functions

The advantages of industrial cameras using GAPISDK to generate video functions mainly include:

  1. High efficiency: Using GAPISDK to generate video functions can greatly improve the data transmission and processing efficiency of industrial cameras. Compared with traditional camera data transmission methods, using GAPISDK can better optimize the data transmission process, reduce data redundancy and transmission time, thereby improving overall processing efficiency.
  2. High quality: GAPISDK is deeply optimized for image processing, which can better process image data and improve image quality. Videos generated using GAPISDK can better maintain the clarity and color of the original image, thereby improving the quality of the video.
  3. Real-time: Using GAPISDK to generate video function can ensure the real-time of data. By optimizing the data transmission and processing process, GAPISDK can better ensure the real-time nature of data transmission and processing, thereby meeting the real-time requirements in industrial production.
  4. Scalability: GAPISDK is an open software development kit that can be easily integrated with other industrial cameras and control software. This makes industrial cameras more scalable when using GAPISDK to generate video functions, and can be customized and expanded according to actual needs.
  5. Flexibility: GAPISDK provides a rich API interface and function library, which can facilitate secondary development and customization. This allows industrial cameras to have higher flexibility when using GAPISDK to generate video functions, and can be flexibly customized and controlled according to actual needs.

In short, industrial cameras using GAPISDK to generate video functions have the advantages of high efficiency, high quality, real-time, scalability and flexibility, and can better meet the needs of image processing and video generation in industrial production.

Baumer industrial cameras use GAPISDK to generate video industry applications

Baumer industrial cameras use GAPISDK to generate videos for a wide range of industrial applications, including:

  1. Automobile manufacturing: During the automobile manufacturing process, Baumer industrial cameras can be used to take images of parts and convert the captured image data into videos through GAPISDK for further image processing, dimensional measurement, defect detection and other tasks. This improves production efficiency and quality.
  2. Electronic manufacturing: In the field of electronic manufacturing, Baumer industrial cameras can be used to identify and detect the appearance and position of electronic components, and convert the captured image data into video through GAPISDK for further image processing, quality inspection and classification tasks. . This improves the efficiency and quality of the production process.
  3. Food processing: In the food processing industry, Baumer industrial cameras can be used to take images of food and convert the captured image data into videos through GAPISDK for further image processing, quality inspection and classification tasks. This improves the efficiency and quality of the production process.
  4. Logistics and warehousing: In the field of logistics and warehousing, Baumer industrial cameras can be used to take images of goods and convert the captured image data into videos through GAPISDK for further image processing, identification and tracking tasks. This can achieve goals such as automated warehouse management and smart logistics distribution.
  5. Medical imaging: In the field of medical imaging, Baumer industrial cameras can be used to shoot medical images, such as X-rays, CT scans and MRI, etc., and convert the captured image data into video through GAPISDK for further image processing, analysis and Diagnosis and other tasks. This can improve the accuracy and efficiency of medical diagnosis.

In short, Baumer industrial cameras use GAPISDK to generate videos in a wide range of industries, involving many fields such as manufacturing, logistics, and medical industries. With the development of industrial automation and intelligence, its application prospects will become increasingly broad.

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. OpenCV skill tree Home page Overview 23593 people are learning the system