Baumer工业相机堡盟相机是一种高性能、高质量的工业相机,可用于各种应用场景,如物体检测、计数和识别、运动分析和图像处理。
Baumer的万兆网相机拥有出色的图像处理性能,可以实时传输高分辨率图像。此外,该相机还具有快速数据传输、低功耗、易于集成以及高度可扩展性等特点。
Baumer万兆网相机中LXT.JP图像压缩系列相机是一种预处理相机,在相机内部对图像进行JPEG算法压缩然后再传输到处理器中。
Baumer工业相机的JPEG图像压缩功能有助于减少图像文件的大小,同时保持图像质量,同时它是一种有损压缩。这种压缩功能是基于JPEG(联合摄影专家组)压缩标准,该标准被广泛用于数字摄影和图像编辑。
具有JPEG压缩功能的工业相机可以捕捉高分辨率的图像,并将其压缩成较小的文件,从而使图像的存储、传输和处理更加容易。压缩水平和质量可以根据用户的具体需求进行调整。
在工业相机中使用JPEG压缩的一个优点是,它可以帮助减少数据传输时间,这在需要高速图像处理的机器视觉应用中特别重要。此外,较小的文件大小允许更有效地存储和检索图像,这在工业环境中可以节省时间和金钱。
总的来说,JPEG图像压缩功能是工业相机的一个重要功能,有助于提高高分辨率图像的效率、存储和处理。
Baumer工业相机堡盟相机SDK示例中022_JPEGCapture.cs详细介绍了如何配置相机偏振功能。
软件SDK示例地址如下所示:Baumer_GAPI_SDK_2.12.0_win_x86_64_cs\examples\src\0_Common\022_JPEGCapture\022_JPEGCapture.cs
本例描述了对堡盟JPEG相机的处理。给出的源代码适用于处理一个系统、一台相机和十幅图像。
代码整体结构相对简单,在相机初始化后进行工业相机的JPEG图像压缩功能使用,部分核心代码如下:
/*
This example describes the the handling of Baumer JPEG cameras.
The given source code applies to handling one system, one camera and ten images.
Please see "Baumer-GAPI SDK Programmer's Guide" chapter 5.1 and chapter 5.2
*/
// ###############################
// Baumer JPEG Capture Example
// -------------------------------
// - the following description includes these tags: JPEGTAGxx, which are makers for the relevant code snippets
// -------------------------------
// - the example shows the work flow for Baumer JPEG cameras --> JPEGTAG01
// - How does the camera work?
// o the camera is capable to stream compressed image when setting 'ImageCompressionMode' to 'JPEG'
// o JPEG compression is only possible for Mono8 and YCbCr pixel formats
// o the size of the image buffer is set to the uncompressed payload size of the full frame image
// (same like a camera without image compression support), because the size of compressed image data
// are always smaller
// - How to implement?
// o set the feature 'PixelFormat' of the camera to 'Mono8' or 'YCbCr' --> JPEGTAG02
// o set the feature 'ImageCompressionMode' to the value 'JPEG' to switch on image compression --> JPEGTAG03
// o this example use internal allocated image buffers that use the maximum payload size of the camera --> JPEGTAG04
// o use function Buffer::GetImageLength to directly save the buffer
// as JPEG into the current working directory --> JPEGTAG05
// o restore JPEG setting --> JPEGTAG06
// ###############################
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace _022_JPEGCapture
{
class Program
{
const string kImageCompressionMode = "ImageCompressionMode";
const string kImageCompressionModeJPEG = "JPEG";
static int Main(string[] args)
{
//DECLARATIONS OF VARIABLES
BGAPI2.SystemList systemList = null;
BGAPI2.System mSystem = null;
string sSystemID = "";
BGAPI2.InterfaceList interfaceList = null;
BGAPI2.Interface mInterface = null;
string sInterfaceID = "";
BGAPI2.DeviceList deviceList = null;
BGAPI2.Device mDevice = null;
string sDeviceID = "";
BGAPI2.DataStreamList datastreamList = null;
BGAPI2.DataStream mDataStream = null;
string sDataStreamID = "";
BGAPI2.BufferList bufferList = null;
BGAPI2.Buffer mBuffer = null;
int returnCode = 0;
bool jpeg_streaming_capable = false;
bool unsafe_code_allowed = true;
System.Console.Write("\r\n");
System.Console.Write("#################################################\r\n");
System.Console.Write("# PROGRAMMER'S GUIDE Example 022_JPEGCapture.cs #\r\n");
System.Console.Write("#################################################\r\n");
System.Console.Write("\r\n\r\n");
System.Console.Write("SYSTEM LIST\r\n");
System.Console.Write("###########\r\n\r\n");
//COUNTING AVAILABLE SYSTEMS (TL producers)
try
{
systemList = BGAPI2.SystemList.Instance;
systemList.Refresh();
System.Console.Write("5.1.2 Detected systems: {0}\r\n", systemList.Count);
//SYSTEM DEVICE INFORMATION
foreach (KeyValuePair sys_pair in BGAPI2.SystemList.Instance)
{
System.Console.Write(" 5.2.1 System Name: {0}\r\n", sys_pair.Value.FileName);
System.Console.Write(" System Type: {0}\r\n", sys_pair.Value.TLType);
System.Console.Write(" System Version: {0}\r\n", sys_pair.Value.Version);
System.Console.Write(" System PathName: {0}\r\n\r\n", sys_pair.Value.PathName);
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
//OPEN THE FIRST SYSTEM IN THE LIST WITH A CAMERA CONNECTED
try
{
foreach (KeyValuePair sys_pair in BGAPI2.SystemList.Instance)
{
System.Console.Write("SYSTEM\r\n");
System.Console.Write("######\r\n\r\n");
try
{
sys_pair.Value.Open();
System.Console.Write("5.1.3 Open next system \r\n");
System.Console.Write(" 5.2.1 System Name: {0}\r\n", sys_pair.Value.FileName);
System.Console.Write(" System Type: {0}\r\n", sys_pair.Value.TLType);
System.Console.Write(" System Version: {0}\r\n", sys_pair.Value.Version);
System.Console.Write(" System PathName: {0}\r\n\r\n", sys_pair.Value.PathName);
sSystemID = sys_pair.Key;
System.Console.Write(" Opened system - NodeList Information \r\n");
System.Console.Write(" GenTL Version: {0}.{1}\r\n\r\n", (long)sys_pair.Value.NodeList["GenTLVersionMajor"].Value, (long)sys_pair.Value.NodeList["GenTLVersionMinor"].Value);
System.Console.Write("INTERFACE LIST\r\n");
System.Console.Write("##############\r\n\r\n");
try
{
interfaceList = sys_pair.Value.Interfaces;
//COUNT AVAILABLE INTERFACES
interfaceList.Refresh(100); // timeout of 100 msec
System.Console.Write("5.1.4 Detected interfaces: {0}\r\n", interfaceList.Count);
//INTERFACE INFORMATION
foreach (KeyValuePair ifc_pair in interfaceList)
{
System.Console.Write(" 5.2.2 Interface ID: {0}\r\n", ifc_pair.Value.Id);
System.Console.Write(" Interface Type: {0}\r\n", ifc_pair.Value.TLType);
System.Console.Write(" Interface Name: {0}\r\n\r\n", ifc_pair.Value.DisplayName);
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
System.Console.Write("INTERFACE\r\n");
System.Console.Write("#########\r\n\r\n");
//OPEN THE NEXT INTERFACE IN THE LIST
try
{
foreach (KeyValuePair ifc_pair in interfaceList)
{
try
{
System.Console.Write("5.1.5 Open interface \r\n");
System.Console.Write(" 5.2.2 Interface ID: {0}\r\n", ifc_pair.Key);
System.Console.Write(" Interface Type: {0}\r\n", ifc_pair.Value.TLType);
System.Console.Write(" Interface Name: {0}\r\n", ifc_pair.Value.DisplayName);
ifc_pair.Value.Open();
//search for any camera is connected to this interface
deviceList = ifc_pair.Value.Devices;
deviceList.Refresh(100);
if (deviceList.Count == 0)
{
System.Console.Write("5.1.13 Close interface ({0} cameras found) \r\n\r\n", deviceList.Count);
ifc_pair.Value.Close();
}
else
{
sInterfaceID = ifc_pair.Key;
System.Console.Write(" \r\n");
System.Console.Write(" Opened interface - NodeList Information \r\n");
if (ifc_pair.Value.TLType == "GEV")
{
long iIPAddress = (long)ifc_pair.Value.NodeList["GevInterfaceSubnetIPAddress"].Value;
System.Console.Write(" GevInterfaceSubnetIPAddress: {0}.{1}.{2}.{3}\r\n", (iIPAddress & 0xff000000) >> 24,
(iIPAddress & 0x00ff0000) >> 16,
(iIPAddress & 0x0000ff00) >> 8,
(iIPAddress & 0x000000ff));
long iSubnetMask = (long)ifc_pair.Value.NodeList["GevInterfaceSubnetMask"].Value;
System.Console.Write(" GevInterfaceSubnetMask: {0}.{1}.{2}.{3}\r\n", (iSubnetMask & 0xff000000) >> 24,
(iSubnetMask & 0x00ff0000) >> 16,
(iSubnetMask & 0x0000ff00) >> 8,
(iSubnetMask & 0x000000ff));
}
System.Console.Write(" \r\n");
break;
}
}
catch (BGAPI2.Exceptions.ResourceInUseException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write(" Interface {0} already opened \r\n", ifc_pair.Key);
System.Console.Write(" ResourceInUseException {0} \r\n", ex.GetErrorDescription());
}
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
//if a camera is connected to the system interface then leave the system loop
if (sInterfaceID != "")
{
break;
}
}
catch (BGAPI2.Exceptions.ResourceInUseException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write(" System {0} already opened \r\n", sys_pair.Key);
System.Console.Write(" ResourceInUseException {0} \r\n", ex.GetErrorDescription());
}
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
if (sSystemID == "")
{
System.Console.Write(" No System found \r\n");
System.Console.Write(" Input any number to close the program:\r\n");
Console.Read();
return returnCode;
}
else
{
mSystem = systemList[sSystemID];
}
if (sInterfaceID == "")
{
System.Console.Write(" No Interface of TLType 'GEV' found \r\n");
System.Console.Write("\r\nEnd\r\nInput any number to close the program:\r\n");
Console.Read();
mSystem.Close();
return returnCode;
}
else
{
mInterface = interfaceList[sInterfaceID];
}
System.Console.Write("DEVICE LIST\r\n");
System.Console.Write("###########\r\n\r\n");
try
{
//COUNTING AVAILABLE CAMERAS
deviceList = mInterface.Devices;
deviceList.Refresh(100);
System.Console.Write("5.1.6 Detected devices: {0}\r\n", deviceList.Count);
//DEVICE INFORMATION BEFORE OPENING
foreach (KeyValuePair dev_pair in deviceList)
{
System.Console.Write(" 5.2.3 Device DeviceID: {0}\r\n", dev_pair.Key);
System.Console.Write(" Device Model: {0}\r\n", dev_pair.Value.Model);
System.Console.Write(" Device SerialNumber: {0}\r\n", dev_pair.Value.SerialNumber);
System.Console.Write(" Device Vendor: {0}\r\n", dev_pair.Value.Vendor);
System.Console.Write(" Device TLType: {0}\r\n", dev_pair.Value.TLType);
System.Console.Write(" Device AccessStatus: {0}\r\n", dev_pair.Value.AccessStatus);
System.Console.Write(" Device UserID: {0}\r\n\r\n", dev_pair.Value.DisplayName);
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
System.Console.Write("DEVICE\r\n");
System.Console.Write("######\r\n\r\n");
//OPEN THE FIRST CAMERA IN THE LIST
try
{
foreach (KeyValuePair dev_pair in deviceList)
{
try
{
System.Console.Write("5.1.7 Open first device \r\n");
System.Console.Write(" Device DeviceID: {0}\r\n", dev_pair.Value.Id);
System.Console.Write(" Device Model: {0}\r\n", dev_pair.Value.Model);
System.Console.Write(" Device SerialNumber: {0}\r\n", dev_pair.Value.SerialNumber);
System.Console.Write(" Device Vendor: {0}\r\n", dev_pair.Value.Vendor);
System.Console.Write(" Device TLType: {0}\r\n", dev_pair.Value.TLType);
System.Console.Write(" Device AccessStatus: {0}\r\n", dev_pair.Value.AccessStatus);
System.Console.Write(" Device UserID: {0}\r\n\r\n", dev_pair.Value.DisplayName);
dev_pair.Value.Open();
sDeviceID = dev_pair.Key;
System.Console.Write(" Opened device - RemoteNodeList Information \r\n");
System.Console.Write(" Device AccessStatus: {0}\r\n", dev_pair.Value.AccessStatus);
//SERIAL NUMBER
if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceSerialNumber") == true)
System.Console.Write(" DeviceSerialNumber: {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceSerialNumber"].Value);
else if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceID") == true)
System.Console.Write(" DeviceID (SN): {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceID"].Value);
else
System.Console.Write(" SerialNumber: Not Available.\r\n");
//DISPLAY DEVICEMANUFACTURERINFO
if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceManufacturerInfo") == true)
System.Console.Write(" DeviceManufacturerInfo: {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceManufacturerInfo"].Value);
//DISPLAY DEVICEFIRMWAREVERSION OR DEVICEVERSION
if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceFirmwareVersion") == true)
System.Console.Write(" DeviceFirmwareVersion: {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceFirmwareVersion"].Value);
else if (dev_pair.Value.RemoteNodeList.GetNodePresent("DeviceVersion") == true)
System.Console.Write(" DeviceVersion: {0}\r\n", (string)dev_pair.Value.RemoteNodeList["DeviceVersion"].Value);
else
System.Console.Write(" DeviceVersion: Not Available.\r\n");
if (dev_pair.Value.TLType == "GEV")
{
System.Console.Write(" GevCCP: {0}\r\n", (string)dev_pair.Value.RemoteNodeList["GevCCP"].Value);
System.Console.Write(" GevCurrentIPAddress: {0}.{1}.{2}.{3}\r\n", ((long)dev_pair.Value.RemoteNodeList["GevCurrentIPAddress"].Value & 0xff000000) >> 24, ((long)dev_pair.Value.RemoteNodeList["GevCurrentIPAddress"].Value & 0x00ff0000) >> 16, ((long)dev_pair.Value.RemoteNodeList["GevCurrentIPAddress"].Value & 0x0000ff00) >> 8, ((long)dev_pair.Value.RemoteNodeList["GevCurrentIPAddress"].Value & 0x000000ff));
System.Console.Write(" GevCurrentSubnetMask: {0}.{1}.{2}.{3}\r\n", ((long)dev_pair.Value.RemoteNodeList["GevCurrentSubnetMask"].Value & 0xff000000) >> 24, ((long)dev_pair.Value.RemoteNodeList["GevCurrentSubnetMask"].Value & 0x00ff0000) >> 16, ((long)dev_pair.Value.RemoteNodeList["GevCurrentSubnetMask"].Value & 0x0000ff00) >> 8, ((long)dev_pair.Value.RemoteNodeList["GevCurrentSubnetMask"].Value & 0x000000ff));
}
System.Console.Write(" \r\n");
break;
}
catch (BGAPI2.Exceptions.ResourceInUseException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write(" Device {0} already opened \r\n", dev_pair.Key);
System.Console.Write(" ResourceInUseException {0} \r\n", ex.GetErrorDescription());
}
catch (BGAPI2.Exceptions.AccessDeniedException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write(" Device {0} already opened \r\n", dev_pair.Key);
System.Console.Write(" AccessDeniedException {0} \r\n", ex.GetErrorDescription());
}
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
if (sDeviceID == "")
{
System.Console.Write(" No Device found \r\n");
System.Console.Write("\r\nEnd\r\nInput any number to close the program:\r\n");
Console.Read();
mInterface.Close();
mSystem.Close();
return returnCode;
}
else
{
mDevice = deviceList[sDeviceID];
}
System.Console.Write("DEVICE PARAMETER SETUP\r\n");
System.Console.Write("######################\r\n\r\n");
try
{
//SET TRIGGER MODE OFF (FreeRun)
mDevice.RemoteNodeList["TriggerMode"].Value = "Off";
System.Console.Write(" TriggerMode: {0}\r\n", (string)mDevice.RemoteNodeList["TriggerMode"].Value);
System.Console.Write(" \r\n");
// JPEGTAG01 (see description on top)
// check for JPEG capable camera
if (mDevice.RemoteNodeList.GetNodePresent(kImageCompressionMode))
{
BGAPI2.NodeMap image_compression_map = mDevice.RemoteNodeList[kImageCompressionMode].EnumNodeList;
if (image_compression_map.GetNodePresent(kImageCompressionModeJPEG))
{
jpeg_streaming_capable = true;
System.Console.Write(" JPEG Supported: Yes\r\n");
}
else
{
System.Console.Write(" JPEG Supported: No, Feature '{0}' has no element {1}\r\n",
kImageCompressionMode, kImageCompressionModeJPEG);
}
}
else
{
System.Console.Write(" JPEG Supported: Feature '{0}' not found.\r\n", kImageCompressionMode);
}
if (jpeg_streaming_capable) {
// JPEGTAG02 (see description on top)
// AND SET PIXELFORMAT (Mono8, YCbCr) IF AVAILABLE
BGAPI2.NodeMap pixel_format_enum_map = mDevice.RemoteNodeList["PixelFormat"].EnumNodeList;
string pixel_format = "YCbCr422_8";
if (!pixel_format_enum_map.GetNodePresent(pixel_format) ||
(pixel_format_enum_map.GetNodePresent(pixel_format) && !pixel_format_enum_map[pixel_format].IsReadable)) {
pixel_format = "Mono8";
if (!pixel_format_enum_map.GetNodePresent(pixel_format) ||
(pixel_format_enum_map.GetNodePresent(pixel_format) && !pixel_format_enum_map[pixel_format].IsReadable)) {
pixel_format = "";
}
}
if ((pixel_format != "") && mDevice.RemoteNodeList["PixelFormat"].IsWriteable) {
mDevice.RemoteNodeList["PixelFormat"].Value = pixel_format;
System.Console.Write(" PixelFormat: {0}\r\n",
mDevice.RemoteNodeList["PixelFormat"].Value);
// JPEGTAG03 (see description on top)
// set the compression mode to JPEG
mDevice.RemoteNodeList[kImageCompressionMode].Value = "JPEG";
} else {
System.Console.Write(" PixelFormat: {0} (set to Mono8/YCbCr failed, not supported or no write accees)\r\n",
mDevice.RemoteNodeList["PixelFormat"].Value);
}
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
System.Console.Write("DATA STREAM LIST\r\n");
System.Console.Write("################\r\n\r\n");
try
{
//COUNTING AVAILABLE DATASTREAMS
datastreamList = mDevice.DataStreams;
datastreamList.Refresh();
System.Console.Write("5.1.8 Detected datastreams: {0}\r\n", datastreamList.Count);
//DATASTREAM INFORMATION BEFORE OPENING
foreach (KeyValuePair dst_pair in datastreamList)
{
System.Console.Write(" 5.2.4 DataStream ID: {0}\r\n\r\n", dst_pair.Key);
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
System.Console.Write("DATA STREAM\r\n");
System.Console.Write("###########\r\n\r\n");
//OPEN THE FIRST DATASTREAM IN THE LIST
try
{
foreach (KeyValuePair dst_pair in datastreamList)
{
System.Console.Write("5.1.9 Open first datastream\r\n");
System.Console.Write(" DataStream ID: {0}\r\n\r\n", dst_pair.Key);
dst_pair.Value.Open();
sDataStreamID = dst_pair.Key;
System.Console.Write(" Opened datastream - NodeList Information \r\n");
System.Console.Write(" StreamAnnounceBufferMinimum: {0}\r\n", dst_pair.Value.NodeList["StreamAnnounceBufferMinimum"].Value);
if (dst_pair.Value.TLType == "GEV")
{
System.Console.Write(" StreamDriverModel: {0}\r\n", dst_pair.Value.NodeList["StreamDriverModel"].Value);
}
System.Console.Write(" \r\n");
break;
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
if (sDataStreamID == "")
{
System.Console.Write(" No DataStream found \r\n");
System.Console.Write("\r\nEnd\r\nInput any number to close the program:\r\n");
Console.Read();
mDevice.Close();
mInterface.Close();
mSystem.Close();
return returnCode;
}
else
{
mDataStream = datastreamList[sDataStreamID];
}
System.Console.Write("BUFFER LIST\r\n");
System.Console.Write("###########\r\n\r\n");
try
{
//BufferList
bufferList = mDataStream.BufferList;
// 4 buffers using internal buffer mode
for (int i = 0; i < 4; i++)
{
// JPEGTAG04 (see description on top)
// create image buffers with the maximum payload size
mBuffer = new BGAPI2.Buffer();
bufferList.Add(mBuffer);
}
System.Console.Write("5.1.10 Announced buffers: {0} using {1} [bytes]\r\n", bufferList.AnnouncedCount, mBuffer.MemSize * bufferList.AnnouncedCount);
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
try
{
foreach (KeyValuePair buf_pair in bufferList)
{
buf_pair.Value.QueueBuffer();
}
System.Console.Write("5.1.11 Queued buffers: {0}\r\n", bufferList.QueuedCount);
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
System.Console.Write("\r\n");
System.Console.Write("CAMERA START\r\n");
System.Console.Write("############\r\n\r\n");
//START DATASTREAM ACQUISITION
try
{
mDataStream.StartAcquisition();
System.Console.Write("5.1.12 DataStream started \r\n");
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
//START CAMERA
try
{
mDevice.RemoteNodeList["AcquisitionStart"].Execute();
System.Console.Write("5.1.12 {0} started \r\n", mDevice.Model);
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
//CAPTURE 12 IMAGES
System.Console.Write("\r\n");
System.Console.Write("CAPTURE 12 IMAGES BY IMAGE POLLING\r\n");
System.Console.Write("##################################\r\n\r\n");
BGAPI2.Buffer mBufferFilled = null;
try
{
for (int i = 0; i < 12; i++)
{
mBufferFilled = mDataStream.GetFilledBuffer(1000); // image polling timeout 1000 msec
if (mBufferFilled == null)
{
System.Console.Write("Error: Buffer Timeout after 1000 msec\r\n");
}
else if (mBufferFilled.IsIncomplete == true)
{
System.Console.Write("Error: Image is incomplete\r\n");
// queue buffer again
mBufferFilled.QueueBuffer();
}
else
{
System.Console.Write(" Image {0, 5:d} received in memory address {1:X16}\r\n",
mBufferFilled.FrameID, (ulong)mBufferFilled.MemPtr);
// JPEGTAG05 (see description on top)
// save the compressed images to disk if supported
if (jpeg_streaming_capable)
{
ulong jpeg_size = mBufferFilled.ImageLength;
if (jpeg_size > 0)
{
// Save jpeg data to file
System.IO.FileStream outfile = new System.IO.FileStream(String.Format("022_JPEGCapture_{0:D6}.jpg", mBufferFilled.FrameID),
System.IO.FileMode.Create, System.IO.FileAccess.Write);
if (unsafe_code_allowed)
{
// Use UnmanagedMemoryStream to avoid copy form unmanaged to managed
System.IO.UnmanagedMemoryStream unmanaged_stream;
unsafe
{
unmanaged_stream = new System.IO.UnmanagedMemoryStream((byte*)mBufferFilled.MemPtr.ToPointer() + mBufferFilled.ImageOffset,
(long)jpeg_size);
}
unmanaged_stream.CopyTo(outfile);
unmanaged_stream.Close();
}
else
{
byte[] jpeg_data = new byte[jpeg_size];
Marshal.Copy(mBufferFilled.MemPtr, jpeg_data, (int)mBufferFilled.ImageOffset, (int)jpeg_data.Length);
outfile.Write(jpeg_data, 0, jpeg_data.Length);
}
outfile.Close();
System.Console.Write("JPEG Data found. Image saved as JPEG file.\r\n");
}
else
{
System.Console.Write("JPEG Data not found in image buffer. No JPEG Saved.\r\n");
}
}
// queue buffer again
mBufferFilled.QueueBuffer();
}
}
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
System.Console.Write("\r\n");
System.Console.Write("CAMERA STOP\r\n");
System.Console.Write("###########\r\n\r\n");
//STOP CAMERA
try
{
if (mDevice.RemoteNodeList.GetNodePresent("AcquisitionAbort") == true)
{
mDevice.RemoteNodeList["AcquisitionAbort"].Execute();
System.Console.Write("5.1.12 {0} aborted\r\n", mDevice.Model);
}
mDevice.RemoteNodeList["AcquisitionStop"].Execute();
System.Console.Write("5.1.12 {0} stopped \r\n", mDevice.Model);
System.Console.Write("\r\n");
String sExposureNodeName = "";
if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTime"))
{
sExposureNodeName = "ExposureTime";
}
else if (mDevice.GetRemoteNodeList().GetNodePresent("ExposureTimeAbs"))
{
sExposureNodeName = "ExposureTimeAbs";
}
System.Console.Write(" ExposureTime: {0} [{1}]\r\n", (double)mDevice.RemoteNodeList[sExposureNodeName].Value, (string)mDevice.RemoteNodeList[sExposureNodeName].Unit);
if (mDevice.TLType == "GEV")
{
if (mDevice.RemoteNodeList.GetNodePresent("DeviceStreamChannelPacketSize") == true)
System.Console.Write(" DeviceStreamChannelPacketSize: {0} [bytes]\r\n", (long)mDevice.RemoteNodeList["DeviceStreamChannelPacketSize"].Value);
else
System.Console.Write(" GevSCPSPacketSize: {0} [bytes]\r\n", (long)mDevice.RemoteNodeList["GevSCPSPacketSize"].Value);
System.Console.Write(" GevSCPD (PacketDelay): {0} [tics]\r\n", (long)mDevice.RemoteNodeList["GevSCPD"].Value);
}
System.Console.Write("\r\n");
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
//STOP DataStream acquisition & release buffers
try
{
if (mDataStream.TLType == "GEV")
{
//DataStream Statistics
System.Console.Write(" DataStream Statistics \r\n");
System.Console.Write(" DataBlockComplete: {0}\r\n", (long)mDataStream.NodeList["DataBlockComplete"].Value);
System.Console.Write(" DataBlockInComplete: {0}\r\n", (long)mDataStream.NodeList["DataBlockInComplete"].Value);
System.Console.Write(" DataBlockMissing: {0}\r\n", (long)mDataStream.NodeList["DataBlockMissing"].Value);
System.Console.Write(" PacketResendRequestSingle: {0}\r\n", (long)mDataStream.NodeList["PacketResendRequestSingle"].Value);
System.Console.Write(" PacketResendRequestRange: {0}\r\n", (long)mDataStream.NodeList["PacketResendRequestRange"].Value);
System.Console.Write(" PacketResendReceive: {0}\r\n", (long)mDataStream.NodeList["PacketResendReceive"].Value);
System.Console.Write(" DataBlockDroppedBufferUnderrun: {0}\r\n", (long)mDataStream.NodeList["DataBlockDroppedBufferUnderrun"].Value);
System.Console.Write(" Bitrate: {0}\r\n", (double)mDataStream.NodeList["Bitrate"].Value);
System.Console.Write(" Throughput: {0}\r\n", (double)mDataStream.NodeList["Throughput"].Value);
System.Console.Write("\r\n");
}
if (mDataStream.TLType == "U3V")
{
//DataStream Statistics
System.Console.Write(" DataStream Statistics \r\n");
System.Console.Write(" GoodFrames: {0}\r\n", (long)mDataStream.NodeList["GoodFrames"].Value);
System.Console.Write(" CorruptedFrames: {0}\r\n", (long)mDataStream.NodeList["CorruptedFrames"].Value);
System.Console.Write(" LostFrames: {0}\r\n", (long)mDataStream.NodeList["LostFrames"].Value);
System.Console.Write("\r\n");
}
//BufferList Information
System.Console.Write(" BufferList Information \r\n");
System.Console.Write(" DeliveredCount: {0}\r\n", (long)bufferList.DeliveredCount);
System.Console.Write(" UnderrunCount: {0}\r\n", (long)bufferList.UnderrunCount);
System.Console.Write("\r\n");
mDataStream.StopAcquisition();
System.Console.Write("5.1.12 DataStream stopped \r\n");
bufferList.DiscardAllBuffers();
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
System.Console.Write("\r\n");
// JPEGTAG06 (see description on top)
// revert th JPEG settings if they was enabled
if (jpeg_streaming_capable) {
// ENABLE IMAGECOMPRESSION MODE
mDevice.RemoteNodeList[kImageCompressionMode].Value = "Off";
}
System.Console.Write("RELEASE\r\n");
System.Console.Write("#######\r\n\r\n");
//Release buffers
System.Console.Write("5.1.13 Releasing the resources\r\n");
try
{
while (bufferList.Count > 0)
{
mBuffer = (BGAPI2.Buffer)bufferList.Values.First();
bufferList.RevokeBuffer(mBuffer);
}
System.Console.Write(" buffers after revoke: {0}\r\n", bufferList.Count);
mDataStream.Close();
mDevice.Close();
mInterface.Close();
mSystem.Close();
}
catch (BGAPI2.Exceptions.IException ex)
{
returnCode = (0 == returnCode) ? 1 : returnCode;
System.Console.Write("ExceptionType: {0} \r\n", ex.GetType());
System.Console.Write("ErrorDescription: {0} \r\n", ex.GetErrorDescription());
System.Console.Write("in function: {0} \r\n", ex.GetFunctionName());
}
System.Console.Write("\r\nEnd\r\n\r\n");
System.Console.Write("Input any number to close the program:\r\n");
Console.Read();
return returnCode;
}
}
}
1.JPEG功能
在好的压缩比下能够得到高质量的图片(例如 1:10)
被广泛接受的标准格式,通过MJPEG压缩得到AVI 视频成为可能
2.使处理过程变的简单
不PC软件压缩相比,降低了CPU的负载
在一台PC上可使用多台JPEG相机,有效降低成本
3.传输需要更低的带宽
在更低带宽接口上确保高分辨率和高速的数据传输
通过使用交换机支持远距离传输,有效降低成本
4.存档所需的存储空间更小
更长的存储时间,更低的存储介质成本
5.自由度更高,灵活性得以发挥
对应不同应用的需求更具有灵活性和自由度
JPEG图像压缩技术被广泛用于工业相机的各种应用中。以下是一些场景应用。
1. 质量控制。在高分辨率相机用于质量控制的行业中,JPEG图像压缩技术可以用来压缩大尺寸的图像而不影响图像质量。这样可以更好地存储和传输图像,同时减少数据传输时间。
2. 监视。在安全行业,JPEG图像压缩技术被用来减少摄像机实时捕获的图像的大小。这允许快速传输和存储数据,从而使反应时间更快。
3.自动化。在自动化领域使用的工业相机需要高速的图像捕捉和最小的数据传输时间。JPEG图像压缩技术可用于压缩图像,促进更快的传输时间。
4. 物体识别。在需要识别物体的行业中,例如在机器人或自动驾驶汽车中,JPEG压缩技术可以用来将大的图像文件转换为较小的文件,而不会有明显的质量损失。这允许有效地处理和识别物体。
总的来说,JPEG图像压缩技术在工业相机的应用中提供了显著的好处,包括改善存储和传输时间,更快的处理,以及减少数据的使用。