Baumer工业相机堡盟万兆网相机如何在SDK中使用ColorProcessing颜色处理功能(C#)

简介: Baumer工业相机堡盟万兆网相机如何在SDK中使用ColorProcessing颜色处理功能(C#)

项目场景

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


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


Baumer工业相机的颜色处理功能可以在BGAPI SDK中通过Baumer提供的API函数完成。


技术背景

Baumer工业相机具有先进的色彩处理能力,使其能够捕获具有准确和生动色彩的图像。这是通过各种色彩处理技术实现的,如色彩插值、白平衡调整、色差校正和色彩增强。


颜色插值涉及在图像中创建缺失的颜色信息,根据周围的像素来估计应该有哪些颜色。白平衡调整对场景的整体色彩平衡进行调整,以确保白色表面在图像中呈现白色。


色差校正用于纠正镜头或图像传感器可能带来的色彩失真,而色彩增强可用于提高图像的色彩饱和度或对比度。


总的来说,工业相机能够产生高质量的图像,具有准确和一致的色彩,使它们成为广泛的工业和科学应用的理想选择。


代码分析

Baumer工业相机堡盟相机SDK示例中015_ColorProcessing.cpp详细介绍了如何配置在相机内部配置颜色处理功能。


软件SDK示例地址如下所示:Baumer_GAPI_SDK_2.12.0_win_x86_64_cpp\examples\src\0_Common\015_ColorProcessing\015_ColorProcessing.cpp

1.png

如下为使用Baumer BGAPI SDK进行相机颜色处理矩阵的核心代码:


SystemList 
Open a System 
Get the InterfaceList and fill it Open an Interface 
Get the DeviceList and fill it 
Open a Device
//获取颜色转换处理功能
BGAPI2.Node colorTransformationFactoryListSelector = GetFeature(deviceRemoteMap, "ColorTransformationFactoryListSelector");
if (colorTransformationFactoryListSelector != null)
{
    BGAPI2.NodeMap colorTransformationMap = colorTransformationFactoryListSelector.EnumNodeList;
    ulong iMatrixCount = colorTransformationMap.Count;
    List<string> colorMatrixSet = new List<string>();
    for (ulong iMatrixIndex = 0; iMatrixIndex < iMatrixCount; iMatrixIndex++) {
        BGAPI2.Node colorMatrix = colorTransformationMap[iMatrixIndex];
        if (colorMatrix.IsAvailable && colorMatrix.IsImplemented)
        {
            colorMatrixSet.Add(colorMatrix.Value);          
        }
    }
    BGAPI2.Node colorTransformationResetToFactoryList = GetFeature(deviceRemoteMap, "ColorTransformationResetToFactoryList");
    if (colorTransformationResetToFactoryList != null)
    {       
        int iMatrixIndex = 0;
        Int32.TryParse(Console.ReadLine(), out iMatrixIndex);
        iMatrixIndex--;    
        if ((iMatrixIndex >= 0) && (iMatrixIndex < colorMatrixSet.Count))
        {
            colorTransformationFactoryListSelector.Value = colorMatrixSet[iMatrixIndex];
            colorTransformationResetToFactoryList.Execute();
        }
    }
}
double[] dColorMatrix = new double[9];
string sPixelFormatSrc = "";
string sPixelFormatDst = "";
BGAPI2.Node devicePixelFormat = null;
BGAPI2.ImageProcessor imageProcessor = null;
//显示相机颜色矩阵
if (GetDeviceColorMatrix(mDevice, dColorMatrix))
{
    try
    {
        devicePixelFormat = mDevice.RemoteNodeList["PixelFormat"];
        BGAPI2.NodeMap nodeMap = devicePixelFormat.EnumNodeList;
        ulong count = nodeMap.Count;
        for (ulong i = 0; i < count; i++) {
            BGAPI2.Node node = nodeMap[i];
            if (node.IsImplemented && node.IsAvailable) {
                string sPixelFormat = node.Value;               
                if (sPixelFormatSrc == "")
                {
                    if (sPixelFormat.IndexOf("Bayer") >= 0)
                    {
                        sPixelFormatSrc = sPixelFormat;
                        sPixelFormatDst = "BGR8";
                    }
                }
            }
        }
    }
    catch (BGAPI2.Exceptions.IException ex)
    {
        returncode = 0 == returncode ? 1 : returncode;       
    }
}
//确认相机是否具有颜色处理功能
if ((sPixelFormatSrc == "") || (sPixelFormatDst == ""))
{
    System.Console.Write("NO COLOR MATRIX SUPPORT\r\n\r\n");
    return;
}
if ((sPixelFormatSrc != "") & (sPixelFormatDst != ""))
{
     datastreamList = mDevice.DataStreams;
     datastreamList.Refresh();
     foreach (KeyValuePair<string, BGAPI2.DataStream> dst_pair in datastreamList)
     {                    
         dst_pair.Value.Open();
         DataStreamID = dst_pair.Key;
         break;
    }
}
mDataStream = datastreamList[sDataStreamID];
//BufferList
bufferList = mDataStream.BufferList;
// 4 buffers using internal buffer mode
BGAPI2.Buffer buffer = null;
for (int i = 0; i < 4; i++)
{
     buffer = new BGAPI2.Buffer();
     bufferList.Add(buffer);
}
foreach (KeyValuePair<string, BGAPI2.Buffer> buf_pair in bufferList)
{
    buf_pair.Value.QueueBuffer();
}
//开始使用相机的颜色处理矩阵功能
imageProcessor = new BGAPI2.ImageProcessor();
if (imageProcessor != null) {
   // SET COLOR MATRIX TO IMAGE PROCESSOR
   System.Console.Write(" Set color matrix to image processor\r\n");
   SetImageProcessorColorMatrix(imageProcessor, dColorMatrix);
}

上面部分获取相机属性代码的函数如下所示:

//------------------------------------------------------------------------------
static BGAPI2.Node GetFeature(BGAPI2.NodeMap nodeMap, string feature)
{
    if (nodeMap != null)
    {
        try
        {
            if (nodeMap.GetNodePresent(feature))
            {
                BGAPI2.Node node = nodeMap[feature];
                if ((node != null) && node.IsImplemented && node.IsAvailable)
                {
                    return node;
                }
            }
        }
        catch (BGAPI2.Exceptions.IException ex)
        {
            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());
        }
    }
    return null;
}
//------------------------------------------------------------------------------
// Readout device color matrix
static bool GetDeviceColorMatrix(BGAPI2.Device device, double[] dColorMatrix)
{
    uint uMask = 0;
    try
    {
        BGAPI2.NodeMap nodeMap = device.RemoteNodeList;
        BGAPI2.Node colorTransformationValue         = GetFeature(nodeMap, "ColorTransformationValue");
        BGAPI2.Node colorTransformationValueSelector = GetFeature(nodeMap, "ColorTransformationValueSelector");
        if ((colorTransformationValueSelector != null) && (colorTransformationValue != null)) {
            BGAPI2.NodeMap colorTransformationNodeMap = colorTransformationValueSelector.EnumNodeList;
            ulong iSelectorCount = colorTransformationNodeMap.Count;
            string sOldSelector = colorTransformationValueSelector.Value;
            string sSelector = sOldSelector;
            for (ulong iSelectorIndex = 0; iSelectorIndex<iSelectorCount; iSelectorIndex++)
            {
                BGAPI2.Node node = colorTransformationNodeMap[iSelectorIndex];
                if (node.IsImplemented && node.IsAvailable)
                {
                    string sGainItemValue = node.Value;
                    int iIndex = -1;
                    if (sGainItemValue == "Gain00")
                    {
                        iIndex = 0;
                    }
                    else if (sGainItemValue == "Gain01")
                    {
                        iIndex = 1;
                    }
                    else if (sGainItemValue == "Gain02")
                    {
                        iIndex = 2;
                    }
                    else if (sGainItemValue == "Gain10")
                    {
                        iIndex = 3;
                    }
                    else if (sGainItemValue == "Gain11")
                    {
                        iIndex = 4;
                    }
                    else if (sGainItemValue == "Gain12")
                    {
                        iIndex = 5;
                    }
                    else if (sGainItemValue == "Gain20")
                    {
                        iIndex = 6;
                    }
                    else if (sGainItemValue == "Gain21")
                    {
                        iIndex = 7;
                    }
                    else if (sGainItemValue == "Gain22")
                    {
                        iIndex = 8;
                    }
                    if (iIndex >= 0)
                    {
                        sSelector = sGainItemValue;
                        colorTransformationValueSelector.Value = sSelector;
                        dColorMatrix[iIndex] = colorTransformationValue.Value;
                        uMask |= (uint)(1 << iIndex);
                    }
                }
            }
            if (sSelector != sOldSelector)
            {
                colorTransformationValueSelector.Value = sOldSelector;
            }
        }
    }
    catch (BGAPI2.Exceptions.IException ex)
    {
        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());
    }
    return (uMask == 0x1FF);
}
//------------------------------------------------------------------------------
static bool SetImageProcessorColorMatrix(BGAPI2.ImageProcessor imageProcessor, double[] dColorMatrix)
{
    uint uMask = 0;
    try
    {
        BGAPI2.NodeMap nodeMap = imageProcessor.NodeList;
        BGAPI2.Node colorTransformationValueSelector = nodeMap["ColorTransformationValueSelector"];
        BGAPI2.Node colorTransformationValue = nodeMap["ColorTransformationValue"];
        for (int iIndex = 0; iIndex < 9; iIndex++)
        {
            colorTransformationValueSelector.Value = iIndex;
            colorTransformationValue.Value = dColorMatrix[iIndex];
            uMask |= (uint)(1 << iIndex);
        }
    }
    catch (BGAPI2.Exceptions.IException ex)
    {
            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());
    }
    return (uMask == 0x1FF);
}

颜色处理功能优点

工业相机的色彩处理功能有几个优点,包括:


1. 提高准确性和一致性: 通过准确捕捉色彩信息,工业相机可以更准确地呈现被检查对象。这有助于提高产品质量和制造过程的一致性。


2. 更快的图像处理: 使用彩色图像可以使机器视觉应用的图像处理更快、更有效,这有助于提高制造业的生产力。


3. 加强图像分析: 彩色图像提供额外的信息,可用于更复杂的图像分析技术,如模式识别和机器学习。


4. 更好的质量控制: 通过监测产品的颜色变化,制造商可以更好地确保产品符合质量标准,并与既定规格一致。


总的来说,工业相机的色彩处理功能可以帮助改善生产效率,提高产品质量,并能对一系列工业应用的图像进行更精确的分析。


颜色处理行业应用

有不同的场景可以利用工业相机的色彩处理功能。


1. 质量控制和检查: 在制造和生产行业,工业相机的颜色处理功能可用于检查和评估产品的颜色质量。它可以用来检测可能影响最终产品的质量的颜色的不一致、缺陷或偏差。


2. 医学和生命科学: 在医学和生命科学的应用中,工业相机的色彩处理可以用来捕捉生物标本、染色或液体的图像,这些图像显示了关于样品的不同类型的信息,如细胞类型、结构和颜色。


3. 交通监控: 在交通监控应用中,工业相机可用于检测和识别基于颜色的交通标志或信号,如红色表示停止,绿色表示前进,黄色表示警告。


4.安全和监控: 工业相机的颜色处理功能可用于安全和监控系统,根据颜色来识别和确认个人或物体,如区分移动物体和背景颜色。


5. 农业和食品工业: 在农业和食品行业,工业相机的色彩处理功能可用于根据颜色对农产品进行分级和分类,如成熟度、成熟度和质量。

目录
相关文章
|
5月前
|
监控 API 开发工具
Baumer工业相机堡盟工业相机如何通过NEOAPI SDK获取每张图像的微秒时间和FrameID功能(C#)
Baumer工业相机堡盟工业相机如何通过NEOAPI SDK获取每张图像的微秒时间和FrameID功能(C#)
85 0
|
5月前
|
数据采集 API 开发工具
Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用Force IP强制修改网口IP功能(C++)
Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用Force IP强制修改网口IP功能(C++)
57 0
|
5月前
|
监控 API 开发工具
Baumer工业相机堡盟工业相机如何通过NEOAPI SDK获取每张图像的微秒时间和FrameID功能(C++)
Baumer工业相机堡盟工业相机如何通过NEOAPI SDK获取每张图像的微秒时间和FrameID功能(C++)
69 0
|
5月前
|
存储 传感器 监控
工业相机如何实现实时和本地Raw格式图像和Bitmap格式图像的保存和相互转换(C#代码,UI界面版)
工业相机如何实现实时和本地Raw格式图像和Bitmap格式图像的保存和相互转换(C#代码,UI界面版)
184 0
|
5月前
|
开发框架 前端开发 .NET
C#编程与Web开发
【4月更文挑战第21天】本文探讨了C#在Web开发中的应用,包括使用ASP.NET框架、MVC模式、Web API和Entity Framework。C#作为.NET框架的主要语言,结合这些工具,能创建动态、高效的Web应用。实际案例涉及企业级应用、电子商务和社交媒体平台。尽管面临竞争和挑战,但C#在Web开发领域的前景将持续拓展。
178 3
|
5月前
|
SQL 开发框架 安全
C#编程与多线程处理
【4月更文挑战第21天】探索C#多线程处理,提升程序性能与响应性。了解C#中的Thread、Task类及Async/Await关键字,掌握线程同步与安全,实践并发计算、网络服务及UI优化。跟随未来发展趋势,利用C#打造高效应用。
189 3
|
9天前
|
安全 C# 数据安全/隐私保护
实现C#编程文件夹加锁保护
【10月更文挑战第16天】本文介绍了两种用 C# 实现文件夹保护的方法:一是通过设置文件系统权限,阻止普通用户访问;二是使用加密技术,对文件夹中的文件进行加密,防止未授权访问。提供了示例代码和使用方法,适用于不同安全需求的场景。
|
1月前
|
API C#
C# 一分钟浅谈:文件系统编程
在软件开发中,文件系统操作至关重要。本文将带你快速掌握C#中文件系统编程的基础知识,涵盖基本概念、常见问题及解决方法。文章详细介绍了`System.IO`命名空间下的关键类库,并通过示例代码展示了路径处理、异常处理、并发访问等技巧,还提供了异步API和流压缩等高级技巧,帮助你写出更健壮的代码。
35 2
|
1月前
|
SQL 开发框架 安全
并发集合与任务并行库:C#中的高效编程实践
在现代软件开发中,多核处理器普及使多线程编程成为提升性能的关键。然而,传统同步模型在高并发下易引发死锁等问题。为此,.NET Framework引入了任务并行库(TPL)和并发集合,简化并发编程并增强代码可维护性。并发集合允许多线程安全访问,如`ConcurrentQueue&lt;T&gt;`和`ConcurrentDictionary&lt;TKey, TValue&gt;`,有效避免数据不一致。TPL则通过`Task`类实现异步操作,提高开发效率。正确使用这些工具可显著提升程序性能,但也需注意任务取消和异常处理等常见问题。
43 1
|
1月前
|
安全 程序员 编译器
C#一分钟浅谈:泛型编程基础
在现代软件开发中,泛型编程是一项关键技能,它使开发者能够编写类型安全且可重用的代码。C# 自 2.0 版本起支持泛型编程,本文将从基础概念入手,逐步深入探讨 C# 中的泛型,并通过具体实例帮助理解常见问题及其解决方法。泛型通过类型参数替代具体类型,提高了代码复用性和类型安全性,减少了运行时性能开销。文章详细介绍了如何定义泛型类和方法,并讨论了常见的易错点及解决方案,帮助读者更好地掌握这一技术。
55 11

热门文章

最新文章