在网站上看到这个,保存下来,以后用到了,再看一下。谢谢原创的分享!

#region 获得相机信息方法

/// <summary>
/// 公有静态方法,查找单个相机。例如“Basler”
/// </summary>
public static ICogFrameGrabber FindFrameGrabber(string CameraType)
{
    CogFrameGrabberGigEs frameGrabbers = new CogFrameGrabberGigEs();
    foreach (ICogFrameGrabber fg in frameGrabbers)
    {
        if (fg.Name.Contains(CameraType))
        {
            return (fg);
        }
    }
    return null;
}
/// <summary>
/// 公有静态方法,查找相机列表。
/// </summary>
public static void FindFrameGrabber(List<ICogFrameGrabber> List)
{
    CogFrameGrabberGigEs frameGrabbers = new CogFrameGrabberGigEs();
    foreach (ICogFrameGrabber fg in frameGrabbers)
    {
        if (fg.Name.Contains("Basler"))
        {
            List.Add(fg);
        }
    }
}
/// <summary>
/// 公有静态方法,创建相机初始化工具获取信息。
/// </summary>
public static ICogAcqFifo GetCogAcqFifo(int index)
{
    List<ICogFrameGrabber> list = new List<ICogFrameGrabber>();
    FindFrameGrabber(list);
    ICogFrameGrabber frameGrabbers = list[index];
    ICogAcqFifo mCogAcqFifo = null; ;
 
    if (frameGrabbers == null)
    {
        mCogAcqFifo = null;
        return mCogAcqFifo;
    }
    if (frameGrabbers.Name.Contains("gm"))
    {
        mCogAcqFifo = frameGrabbers.CreateAcqFifo("Generic GigEVision (Mono)", CogAcqFifoPixelFormatConstants.Format8Grey, 0, false);
    }
    else if (frameGrabbers.Name.Contains("gc"))
    {
        mCogAcqFifo = frameGrabbers.CreateAcqFifo("Generic GigEVision (Bayer Color)", CogAcqFifoPixelFormatConstants.Format32RGB, 0, false);
    }
    return mCogAcqFifo;
}
/// <summary>
/// 公有静态方法,查找相机数量。
/// </summary>
public static int GetAllCCDCount()
{
    CogFrameGrabberGigEs frameGrabbers = new CogFrameGrabberGigEs();
 
    int count = frameGrabbers.Count;
 
    return count;
}
/// <summary>
/// 公有静态方法,获得CCD曝光exposure。
/// </summary>
public static double GetCurCCDExposure(ICogAcqFifo acqFifo)
{
    ICogAcqExposure exposureParams = acqFifo.OwnedExposureParams;
    double exposure;
    if (exposureParams == null)
    {
        exposure = 0;
    }
    else
    {
        exposure = exposureParams.Exposure;
    }
    return exposure;
}
/// <summary>
/// 公有静态方法,获得CCD亮度light。
/// </summary>
public static double GetCurCCDLight(ICogAcqFifo acqFifo)
{
    ICogAcqLight lightParams = acqFifo.OwnedLightParams;
    double light;
    if (lightParams == null)
    {
        light = 0;
    }
    else
    {
        light = lightParams.LightPower;
    }
    return light;
}
 
/// <summary>
/// 公有静态方法,获得CCD对比度Contrast。
/// </summary>
public static double GetCurCCDContrast(ICogAcqFifo acqFifo)
{
    ICogAcqContrast ContrastParams = acqFifo.OwnedContrastParams;
    double Contrast;
    if (ContrastParams == null)
    {
        Contrast = 0;
    }
    else
    {
        Contrast = ContrastParams.Contrast;
    }
    return Contrast;
}
/// <summary>
/// 公有静态方法,获得CCD序列号SN
/// </summary>
public static string GetCurCCDSN(ICogAcqFifo acqFifo)
{
    string SerialNumber;
    if (acqFifo == null)
    {
        SerialNumber = "";
    }
    else
    {
        SerialNumber = acqFifo.FrameGrabber.SerialNumber;
    }
    return SerialNumber;
}
/// <summary>
/// 公有静态方法,获得CCD名称Name
/// </summary>
public static string GetCurCCDName(ICogAcqFifo acqFifo)
{
    string CCDName;
    if (acqFifo == null)
    {
        CCDName = "";
    }
    else
    {
        CCDName = acqFifo.FrameGrabber.Name;
    }
    return CCDName;
}
/// <summary>
/// 公有静态方法,获得CCD名称IP
/// </summary>
public static string GetCurCCDIP(ICogAcqFifo acqFifo)
{
    string IP;
    if (acqFifo == null)
    {
        IP = "0.0.0.0";
    }
    else
    {
        IP = acqFifo.FrameGrabber.OwnedGigEAccess.CurrentIPAddress;
    }
    return IP;
}
/// <summary>
/// 公有静态方法,获得CCD名称HostIP
/// </summary>
public static string GetCurCCDHostIP(ICogAcqFifo acqFifo)
{
    string HostIP;
    if (acqFifo == null)
    {
        HostIP = "0.0.0.0";
    }
    else
    {
        HostIP = acqFifo.FrameGrabber.OwnedGigEAccess.HostIPAddress;
    }
    return HostIP;
}
/// <summary>
/// 公有静态方法,获得CCD信号反跳转时间参数。
/// </summary>
public static double GetCurCCDLineDebouncerTime(ICogGigEAccess gigEAccess)
{
    double LineDebouncerTimeAbs = 0;
    try
    {
        LineDebouncerTimeAbs = gigEAccess.GetDoubleFeature("LineDebouncerTimeAbs");
        return LineDebouncerTimeAbs;
    }
    catch { }
    return LineDebouncerTimeAbs;
}
/// <summary>
/// 公有静态方法,获得CCD帧率参数。
/// </summary>
public static double GetCurCCDAcquisitionLineRate(ICogGigEAccess gigEAccess)
{
    double AcquisitionLineRateAbs = 0;
    try
    {
        AcquisitionLineRateAbs = gigEAccess.GetDoubleFeature("AcquisitionLineRateAbs");
        return AcquisitionLineRateAbs;
    }
    catch { }
    return AcquisitionLineRateAbs;
}
#endregion 获得相机信息方法
 
#region 设置相机参数方法
/// <summary>
/// 公有静态方法,设置CCD曝光exposure
/// </summary>
public static void ConfigureExposure(ICogAcqFifo acqFifo, double exposure)
{
    ICogAcqExposure exposureParams = acqFifo.OwnedExposureParams;
    if (exposureParams != null)
    {
        exposureParams.Exposure = exposure;
        acqFifo.Prepare();
    }
}
 
/// <summary>
/// 公有静态方法,设置CCD亮度light。
/// </summary>
public static void ConfigureLight(ICogAcqFifo acqFifo, double light)
{
    ICogAcqLight lightParams = acqFifo.OwnedLightParams;
 
    if (lightParams != null)
    {
        if (light > 1 || light < 0)
        {
            System.Windows.Forms.MessageBox.Show("参数需要在0-1区间!""提示");
        }
        else
        {
            lightParams.LightPower = light;
            acqFifo.Prepare();
        }
    }
}
 
/// <summary>
/// 公有静态方法,设置CCD对比度Contrast。
/// </summary>
public static void ConfigureContrast(ICogAcqFifo acqFifo, double Contrast)
{
    ICogAcqContrast ContrastParams = acqFifo.OwnedContrastParams;
 
    if (ContrastParams != null)
    {
        if (Contrast > 1 || Contrast < 0)
        {
            System.Windows.Forms.MessageBox.Show("参数需要在0-1区间!""提示");
        }
        else
        {
            ContrastParams.Contrast = Contrast;
            acqFifo.Prepare();
        }
    }
}
 
/// <summary>
/// 公有静态方法,设置CCD外触发参数。
/// </summary>
public static void ConfigureTrigger(ICogGigEAccess gigEAccess, double lineDebouncerTime, double AcquisitionLineRateAbs)
{
    //gigEAccess.SetFeature("TriggerSelector", "LineStart");
    //gigEAccess.SetFeature("TriggerMode", "Off");
    gigEAccess.SetFeature("TriggerSelector""FrameStart");//帧
    gigEAccess.SetFeature("TriggerMode""On");
    gigEAccess.SetFeature("TriggerSource""Line3");
    // gigEAccess.SetFeature("TriggerActivation", "RisingEdge");
    // 或者可以触发激活到fallingedge。
    gigEAccess.SetFeature("TriggerActivation""FallingEdge");
    //gigEAccess.SetFeature("LineSelector", "Line3");
    gigEAccess.SetFeature("LineTermination""false");
    gigEAccess.SetDoubleFeature("LineDebouncerTimeAbs", lineDebouncerTime);
    gigEAccess.SetDoubleFeature("AcquisitionLineRateAbs", AcquisitionLineRateAbs);
}
public static void SetlineDebouncerTime(ICogGigEAccess gigEAccess, double time)
{
    gigEAccess.SetFeature("TriggerSelector""FrameStart");//帧
    gigEAccess.SetFeature("TriggerSource""Line1");
    gigEAccess.SetFeature("TriggerActivation""FallingEdge");
    //gigEAccess.SetFeature("TriggerActivation", "RisingEdge");
    gigEAccess.SetFeature("LineSelector""Line1");
    //gigEAccess.SetFeature("LineTermination", "false");
    gigEAccess.SetDoubleFeature("LineDebouncerTimeAbs", time);
}
/// <summary>
/// 公有静态方法,设置CCD旋转编码器触发。
/// </summary>
public static void ConfigureEncoder(ICogGigEAccess gigEAccess)
{
    gigEAccess.SetFeature("ShaftEncoderModuleLineSelector""PhaseA");
    gigEAccess.SetFeature("ShaftEncoderModuleLineSource""Line2");
    gigEAccess.SetFeature("ShaftEncoderModuleLineSelector""PhaseB");
    gigEAccess.SetFeature("ShaftEncoderModuleLineSource""Line3");
    // Enable line termination for the RS-422 encoder signals
    gigEAccess.SetFeature("LineSelector""Line2");
    gigEAccess.SetFeature("LineTermination""true");
    gigEAccess.SetFeature("LineSelector""Line3");
    gigEAccess.SetFeature("LineTermination""true");
    // Set the shaft encoder module counter mode
    gigEAccess.SetFeature("ShaftEncoderModuleCounterMode""IgnoreDirection");
    gigEAccess.SetFeature("TriggerSelector""LineStart");
    gigEAccess.SetFeature("TriggerMode""On");
    gigEAccess.SetFeature("TriggerSource""ShaftEncoderModuleOut");
    gigEAccess.SetFeature("TriggerActivation""FallingEdge");
    //gigEAccess.SetFeature("TriggerActivation", "RisingEdge");
}
 
public static void ConfigureAcquisitionLineRateAbs(ICogGigEAccess gigEAccess, double _AcquisitionLineRateAbs)
{
    gigEAccess.SetDoubleFeature("AcquisitionLineRateAbs", _AcquisitionLineRateAbs);
}
public static void ConfigurelineDebouncerTime(ICogGigEAccess gigEAccess, double _lineDebouncerTime)
{
    gigEAccess.SetDoubleFeature("LineDebouncerTimeAbs", _lineDebouncerTime);
}
 
 
/// <summary>
/// 公有静态方法,设置位宽。
/// </summary>
public static void SetBandwidth(ICogGigEAccess gigEAccess,
    double percentageOfBandwidth)
{
    Double maxRate = 100 * 1024 * 1024;
    uint packetSize = gigEAccess.GetIntegerFeature("GevSCPSPacketSize");
    Double packetTime = packetSize / maxRate;
    Double desiredTime = packetTime / percentageOfBandwidth;
    Double delaySec = desiredTime - packetTime;
    ulong timeStampFreq = gigEAccess.TimeStampFrequency;
    uint delay = (uint)(delaySec * timeStampFreq);
    gigEAccess.SetIntegerFeature("GevSCPD", delay);
}
#endregion 设置相机参数方法
/// <summary>
/// 公有静态方法,保存用户设置参数。
/// </summary>
public static void SaveUserSet(ICogGigEAccess gigEAccess)
{
    gigEAccess.SetFeature("UserSetSelector""UserSet1");
    gigEAccess.ExecuteCommand("UserSetSave");
    gigEAccess.SetFeature("UserSetDefaultSelector""UserSet1");
}
 

------------------------Halcon,Visionpro高清视频教程,点击下载视频--------------------------

本文转载自  https://www.cnblogs.com/MachineVision/p/5775101.html

VisionPro相机操作类的更多相关文章

  1. Java类的继承与多态特性-入门笔记

    相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...

  2. VisionPro笔记:色彩区分

    VisionPro:色彩区分 来自:blog.sina.com.cn/yangchao168 利用色彩来区分物体这类的项目没做过,总觉得很难,尤其是涉及到RGB和HSI等.看到VisionPro中有这 ...

  3. qt Multimedia 模块类如何使用?

    qt 多媒体模块介绍 类名 英文描述 中文描述 QAudioBuffer Represents a collection of audio samples with a specific format ...

  4. Qt Multimedia 模块类如何使用?(表格)

    qt 多媒体模块介绍 类名 英文描述 中文描述 QAudioBuffer Represents a collection of audio samples with a specific format ...

  5. 探索未知种族之osg类生物---器官初始化一

    我们把ViewerBase::frame()比作osg这类生物的肺,首先我们先来大概的看一下‘肺’长什么样子,有哪几部分组成.在这之前得对一些固定的零件进行说明,例如_done代表osg的viewer ...

  6. C++ 可配置的类工厂

    项目中常用到工厂模式,工厂模式可以把创建对象的具体细节封装到Create函数中,减少重复代码,增强可读和可维护性.传统的工厂实现如下: class Widget { public: virtual i ...

  7. Android请求网络共通类——Hi_博客 Android App 开发笔记

    今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...

  8. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库

    在这一章中,我们将直接进入项目,并且为产品和分类添加一些基本的模型类.我们将在Entity Framework的代码优先模式下,利用这些模型类创建一个数据库.我们还将学习如何在代码中创建数据库上下文类 ...

  9. ASP.NET Core 折腾笔记二:自己写个完整的Cache缓存类来支持.NET Core

    背景: 1:.NET Core 已经没System.Web,也木有了HttpRuntime.Cache,因此,该空间下Cache也木有了. 2:.NET Core 有新的Memory Cache提供, ...

随机推荐

  1. Hive学习之路 (三)Hive元数据信息对应MySQL数据库表

    概述 Hive 的元数据信息通常存储在关系型数据库中,常用MySQL数据库作为元数据库管理.上一篇hive的安装也是将元数据信息存放在MySQL数据库中. Hive的元数据信息在MySQL数据中有57 ...

  2. k8s1.8 ingress 配置

    kubectl create secret tls ingress-secret-fengjian --key /data/sslkey/cinyi.key --cert /data/sslkey/c ...

  3. 使用vue.js实现checkbox的全选和多个的删除功能

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  4. kaggle _Titanic: Machine Learning from Disaster

    A Data Science Framework: To Achieve 99% Accuracy https://www.kaggle.com/ldfreeman3/a-data-science-f ...

  5. HDU 2955 变形较大的01背包(有意思,新思路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 Robberies Time Limit: 2000/1000 MS (Java/Others) ...

  6. python中安装第三方模块

    Python有两个封装了setuptools的包管理工具:easy_install和pip.目前官方推荐使用pip. 现在,让我们来安装一个第三方库——Python Imaging Library,这 ...

  7. elasticserach 索引删除 源码分析

    索引的构成 在看IndicesService服务中移除索引的前提,先了解一个Index类的构成,也就是索引的一些基本信息,代码贴图如下:   主要的信息就两个:一个是name,表示索引名称,一个是uu ...

  8. 小白第一次使用Git随笔

    想研究Git很久了,一直没有找到很好的博客或论坛,近几天工作项目任务没有那么重,就想着找几篇文章把这玩意儿给解决掉,本博客是记录读廖雪峰老师所写的<Git教程>的随笔,以便巩固学习,若想学 ...

  9. block本质探寻四之copy

    说明: <1>阅读本文,最好阅读之前的block文章加以理解: <2>本文内容:三种block类型的copy情况(MRC).是否深拷贝.错误copy: 一.MRC模式下,三种b ...

  10. Go语言相对于C++的优点

    Go语言是Google公司在2009年开源的一门高级编程语言,它为解决大型系统开发过程中的实际问题而设计,支持并发.规范统一.简单优雅,被很多Go语言传道者誉为“互联网时代的C语言”.而C++语言诞生 ...