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

#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");
}

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

Vpro 相机操作类相关推荐

  1. VisionPro相机操作类

    Halcon/Visionpro视频教程和资料,请访问 重码网,网址: http://www.211code.com 在网站上看到这个,保存下来,以后用到了,再看一下.谢谢原创的分享! #region ...

  2. QT调用大恒相机的开发教程

    Qt(5.12.10) 调用大恒相机,实时显示图像,并保存bmp文件 文章导读:相机为大恒相机,接口是USB3.0,水星系列产品.本项目采用Qt5.12.10版本编码,编译器为MSVC2017,ope ...

  3. 自己搜集编写的Delphi 通用函数

    { ********************************************************************** } { Currency Common Functio ...

  4. ios中的视频采集及参数设置和相机操作

    概述 在直播应用中,视频的采集一般都是用AVFoundation框架,因为利用它我们能定制采集视频的参数:也能做切换手机摄像头.拍照.打开手电筒等一些列相机的操作:当然,更重要的一点是我们能获取到原始 ...

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

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

  6. 使用cognex的序列化类CogSerializer打包对象到自定义文件及读取文件到对象

    一.自定义类 [Serializable]//标记要序列化的内容 class TestClass {public string Str { get; set; }public Cognex.Visio ...

  7. 这可能是最精简的Android6.0运行时权限处理,百行代码的工具类,支持Rationale,附:各种权限详细处理

    0x00:前言 对于Android6.0运行时权限的处理方式网上有很多,包括注解,RxJava等等.一直没有正面提到我关心的问题–如果我不在Activity或者Fragment里面,需要运行时权限该怎 ...

  8. easytouch 之 相机操作-移动端

    我们可能会经常遇到一个这样的需求, 再3d场景里实现运行时的 相机移动,旋转,缩放拉近等.game下模拟scene里的效果. 对于pc端,或者是unity编辑器,我们可以手写几行代码实现  左键,右键 ...

  9. 继承WebMvcConfigurer 和 WebMvcConfigurerAdapter类依然CORS报错? springboot 两种方式稳定解决跨域问题

    继承WebMvcConfigurer 和 WebMvcConfigurerAdapter类依然CORS报错???springboot 两种方式稳定解决跨域问题! 之前我写了一篇文章,来解决CORS报错 ...

  10. MybatisPlus忽略实体类中的非数据库字段、JPA忽略实体类中的非数据库字段、HeHibernate忽略实体类中的非数据库字段

    mybatis plus忽略映射字段时可以在实体类属性上使用以下注解: @TableField(exist = false):表示该属性不为数据库表字段,但又是必须使用的. @TableField(e ...

最新文章

  1. linq to sql初步
  2. C语言中extern的用法--转
  3. 孔雀东南飞用mysql存储_PowerDesigner使用建议(完整版) 用实体关系图进行数据库建模...
  4. BOI 2003 Problem. Spaceship
  5. JSP中获取HTML中的中文内容是乱码的解决方法---开发中遇到的问题
  6. 面试官是怎样高效面试的(面试官的“套路”
  7. 加载文件流_未关闭的文件流会引起内存泄露么?
  8. 平面向量坐标加法c语言,PTA-C语言 习题9-3 平面向量加法 (15分)
  9. Unity shader入门之数据类型
  10. 电脑主页面上的计算机没了,电脑界面上的internet explorer 没有了
  11. composer 下载包慢的解决方法
  12. MySQL必知必会(一)
  13. poj 3678 Katu Puzzle 2-SAT
  14. 关于文献汇报与撰写论文模板,我有话要讲!
  15. spring boot actuator 如何显示详细信息
  16. 2017全国省市区县 json数据
  17. java计算机毕业设计足球队管理系统源码+数据库+系统+lw文档+mybatis+运行部署
  18. 客户画像中的聚类分析
  19. 计算机基础——Excel 2010
  20. 悲剧的购物经历(附:最好不要买响尾蛇3G)

热门文章

  1. sumifs 汇总_空标准单元格的SUMIFS公式
  2. C语言程序设计(2020)编程题答案——第14章结构体、共用体和用户定义类型
  3. Ajax关于readyState和status
  4. 监控摄像头进行网页直播和微信直播的技术方案
  5. 防火墙iptables和firewall相关操作
  6. 2021年高处安装、维护、拆除考试试卷及高处安装、维护、拆除操作证考试
  7. 智能证件录入系统——电子护照阅读器
  8. 项目踩坑随记 —— getTime() is not a function
  9. C语言课程设计小孩吃梨,IQ题
  10. HiveSql常用的时间维度计算方法(月初、月末、周几)及时间维度 表生成