Baumer工业相机堡盟相机是一种高性能、高质量的工业相机,可用于各种应用场景,如物体检测、计数和识别、运动分析和图像处理
Baumer的万兆网相机拥有出色的图像处理性能,可以实时传输高分辨率图像。此外,该相机还具有快速数据传输、低功耗、易于集成以及高度可扩展性等特点。
Baumer工业相机由于其性能和质量的优越和稳定,常用于高速同步采集领域,通常使用各种图像算法来提高其捕获的图像的质量。
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等。
Baumer工业相机通过SDK生成视频功能的技术背景主要涉及到图像处理和视频生成两个核心环节。
在图像处理方面,Baumer工业相机使用OpenCV库进行图像处理。OpenCV是一款开源的计算机视觉和机器学习软件库,包含了众多算法和函数,可以实现对图像的读取、预处理、特征提取、目标检测等功能。Baumer工业相机通过引用OpenCV库,实现了对图像的高效处理和解析。
在视频生成方面,Baumer工业相机通过GAPISDK(Baumer公司自主研发的软件开发套件)实现了对图像数据的进一步处理和生成视频。GAPISDK针对Baumer工业相机的特点和性能进行了优化,可以更好地利用相机的硬件资源,提高处理速度和效率。同时,GAPISDK还提供了丰富的API接口和函数库,可以方便地进行二次开发和定制,满足不同用户的需求。
通过引用OpenCV库和GAPISDK,Baumer工业相机实现了对图像的高效处理和生成视频的功能。这不仅提高了工业生产中的图像处理效率,也进一步推动了工业自动化和智能化的发展。
本文介绍的通过集成BGAPI SDK进行生成视频的功能。
下面介绍在C++里Baumer工业相机如何通过BGAPISDK循环查找相机序列功能方式
/* Copyright 2019-2020 Baumer Optronic */
#include
#include
#include
#include
#include
#include
#include
#include
#include
// 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
#else
# include
#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
如下为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 "\n======================= 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 "=====================================================================\n")
endif()
endif()
message(STATUS "## OpenCV is configured: ${PROJECT_NAME}! ##\n")
message(STATUS "=====================================================================\n")
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 "$<$:${OpenCV_DLL_DEBUG}>$<$:${OpenCV_DLL_RELEASE}>")
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OpenCV_WorldLib}" $
COMMENT "copy OpenCV library to output directory")
endif()
set(USER_FILE ${TARGET_NAME}.vcxproj.user)
configure_file(UserTemplate.user ${USER_FILE} @ONLY)
endif()
Baumer工业相机通过BGAPI SDK生成视频核心代码如下所示:
// ---------------------------------------------------------------------------------------------------------------------
// 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[] = {
{ &sImgDirectory, "p", "imgPath", false , argumentString, 0, "Pathname", "Image Path" },
{ &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", &fileList);
#else
readDirectory(imgDir, "*.jpg", &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() && (exampleDir == gc_sImageDirDefault)) {
// Create some images if the image directory identical with the default
std::cout << "Here were be some test images with changing colors created!" << std::endl;
createExampleImages(imgDir, cv::Size(1000, 500));
readDirectory(imgDir, ".*.jpg", &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());
// 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& 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;
}
工业相机使用GAPISDK生成视频功能的优势主要包括:
总之,工业相机使用GAPISDK生成视频功能具有高效率、高质量、实时性、可扩展性和灵活性等优势,可以更好地满足工业生产中对图像处理和视频生成的需求。
Baumer工业相机使用GAPISDK生成视频的行业应用非常广泛,主要包括:
总之,Baumer工业相机使用GAPISDK生成视频的行业应用非常广泛,涉及到制造业、物流业、医疗行业等多个领域。随着工业自动化和智能化的发展,其应用前景也将越来越广阔。