需要导入这两个动态链接库

/// <summary>/// 大华相机SDK/// </summary>public class SDK_DaHua : SDK_Camera{/// <summary>/// 相机实例/// </summary>private IDevice device;/// <summary>/// 是否为彩色/// </summary>private bool IsColor = false;/// <summary>/// 相机名称/// </summary>private string Cam_Name;/// <summary>/// /// </summary>public override bool IsOpen {get {if (device!=null){return device.IsOpen;}return false;}   }/// <summary>/// 图像事件 相机名称图源/// </summary>public override event ImageDelegate Image_Delegate;/// <summary>/// /// </summary>~SDK_DaHua(){ }/// <summary>/// 关闭相机/// </summary>/// <returns></returns>public override void Close_Camera(){if (device == null) return;try{device.ShutdownGrab();device.StreamGrabber.ImageGrabbed -= OnImageGrabbed;device.Close();}catch {}}#region 曝光/// <summary>///  设置曝光/// </summary>public override double SetExposureTime(double Value){if (device == null) return 0; using (IFloatParameter p = device.ParameterCollection[new FloatName("ExposureTime")]){if (Value <= p.GetMaximum() && Value >= p.GetMinimum()){p.SetValue(Value);}return p.GetValue();}}/// <summary>/// 获取曝光/// </summary>public override double GetExposureTime(){if (device == null) return 0;using (IFloatParameter p = device.ParameterCollection[new FloatName("ExposureTime")]){return p.GetValue();}}#endregion/// <summary>/// 打开相机/// </summary>/// <param name="Cam_Name"></param>/// <returns></returns>public override bool Open_Camera(string Cam_Name){List<IDeviceInfo> li = Enumerator.EnumerateDevices();for (int i = 0; i < li.Count; i++){if (li[i].Name == Cam_Name.Trim()){//通过设备名称打开相机device = Enumerator.GetDeviceByUserID(Cam_Name);this.Cam_Name = Cam_Name;                    if (!device.Open()){//相机打开失败return false;}//设置 图像帧格式IStringParameter pa = device.ParameterCollection[new StringName("DeviceModelName")];if (pa.GetValue().Contains("C")){using (IEnumParameter p = device.ParameterCollection[ParametrizeNameSet.ImagePixelFormat]){p.SetValue("BayerRG8");IsColor = true;}}else{using (IEnumParameter p = device.ParameterCollection[ParametrizeNameSet.ImagePixelFormat]){p.SetValue("Mono8");IsColor = false;}}// 设置缓存个数为8(默认值为16) device.StreamGrabber.SetBufferCount(8);// 注册码流回调事件  使用内部线程捕获帧数据device.StreamGrabber.ImageGrabbed += OnImageGrabbed;//相机掉线回调device.ConnectionLost += OnConnectLoss;//设置默认的模式device.TriggerSet.Open(TriggerSourceEnum.Software);if (!device.GrabUsingGrabLoopThread()){//开始抓取失败return false;}return true;}}return false;}      /// <summary>/// 相机丢失回调      /// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void OnConnectLoss(object sender, EventArgs e){device.ShutdownGrab();device.Dispose();device = null;}/// <summary>/// 码流数据回调/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void OnImageGrabbed(Object sender, GrabbedEventArgs e){if (IsColor){int nRGB = RGBFactory.EncodeLen(e.GrabResult.Width, e.GrabResult.Height, true);IntPtr pData = System.Runtime.InteropServices.Marshal.AllocHGlobal(nRGB);RGBFactory.ToRGB(e.GrabResult.Image, e.GrabResult.Width, e.GrabResult.Height, true, e.GrabResult.PixelFmt, pData, nRGB);HOperatorSet.GenImageInterleaved(out HObject ho_image, (HTuple)pData, "bgr", e.GrabResult.Width, e.GrabResult.Height, 0, "byte",e.GrabResult.Width, e.GrabResult.Height, 0, 0, 8, 0);Image_Delegate?.Invoke(Cam_Name, ho_image?.Clone());System.Runtime.InteropServices.Marshal.FreeHGlobal(pData);ho_image?.Dispose();GC.Collect();}else{int nRGB = RGBFactory.EncodeLen(e.GrabResult.Width, e.GrabResult.Height, false);IntPtr pData = System.Runtime.InteropServices.Marshal.AllocHGlobal(nRGB);System.Runtime.InteropServices.Marshal.Copy(e.GrabResult.Image, 0, pData, e.GrabResult.ImageSize);HOperatorSet.GenEmptyObj(out HObject ho_image);ho_image.Dispose();HOperatorSet.GenImage1Extern(out ho_image, "byte", e.GrabResult.Width, e.GrabResult.Height, pData, 0);Image_Delegate?.Invoke(Cam_Name, ho_image?.Clone());System.Runtime.InteropServices.Marshal.FreeHGlobal(pData);ho_image?.Dispose();GC.Collect();}}#region 软触发模式/// <summary>/// 软触发模式,开启/关闭 软触发/// </summary>public override TriggerMode GetTriggerMode(){if (device == null) return TriggerMode.On;using (IEnumParameter p = device.ParameterCollection[ParametrizeNameSet.TriggerMode]){return (TriggerMode)Enum.Parse(typeof(TriggerMode), p.GetValue());}}/// <summary>/// 设置触发模式/// </summary>/// <param name="mode"></param>public override void SetTriggerMode(TriggerMode mode){if (device == null) return;using (IEnumParameter p = device.ParameterCollection[ParametrizeNameSet.TriggerMode]){p.SetValue(mode.ToString());if (mode==TriggerMode.On){SetTriggerSource(TriggerSource.Software);device.TriggerSet.Open(TriggerSourceEnum.Software);}}}#endregion#region 软触发触发源/// <summary>/// 获取软触发触发源/// </summary>/// <returns></returns>public override TriggerSource GetTriggerSource(){if (device!=null) return TriggerSource.Software;using (IEnumParameter p = device.ParameterCollection[ParametrizeNameSet.TriggerSource]){return (TriggerSource)Enum.Parse(typeof(TriggerSource), p.GetValue());}}/// <summary>/// 设置软触发触发源/// </summary>/// <param name="source"></param>public override void SetTriggerSource(TriggerSource source){if (device == null) return;using (IEnumParameter p = device.ParameterCollection[ParametrizeNameSet.TriggerSource]){p.SetValue(source.ToString());}}#endregion#region 增益/// <summary>/// 设置增益/// </summary>/// <param name="Value"></param>/// <returns></returns>public override double SetGainRaw(double Value){if (device == null) return 0;// 设置增益            using (IFloatParameter p = device.ParameterCollection[ParametrizeNameSet.GainRaw]){if (Value <= p.GetMaximum() && Value >= p.GetMinimum()){p.SetValue(Value);}return p.GetValue();}}/// <summary>/// 获取增益/// </summary>/// <returns></returns>public override double GetGainRaw(){if (device == null) return 0;using (IFloatParameter p = device.ParameterCollection[ParametrizeNameSet.GainRaw]){return p.GetValue();}}#endregion/// <summary>/// 执行软触发,单帧触发/// </summary>public override bool TriggerSoftware(){if (device==null){return false;}TriggerMode p= GetTriggerMode();if (device.IsGrabbing==false){device.GrabUsingGrabLoopThread();}if (device.IsTriggerOn==true&& TriggerMode.Off== GetTriggerMode()){SetTriggerMode(TriggerMode.On);SetTriggerSource(TriggerSource.Software);device.TriggerSet.Open(TriggerSourceEnum.Software);}return device.ExecuteSoftwareTrigger();}/// <summary>///关闭流通道/// </summary>public override void CloseConsecutive(){if (device == null) return;           if (device.IsGrabbing){device.StreamGrabber.Stop();}}/// <summary>/// 实时采集/// </summary>public override void Acquisition(){if (device == null) return;if (!device.IsGrabbing){device.GrabUsingGrabLoopThread();}//获取采集模式using (IEnumParameter p = device.ParameterCollection[ParametrizeNameSet.AcquisitionMode]){//不等于连续模式if (p.GetValue() != AcquisitionModeEnum.Continuous){//先停止流CloseConsecutive();//设置连续模式p.SetValue(AcquisitionModeEnum.Continuous);}}if (GetTriggerMode() == TriggerMode.On){SetTriggerMode(TriggerMode.Off);}//开启流device.GrabUsingGrabLoopThread();}}

C# 连接大华工业相机相关推荐

  1. 通过连接大华dss平台来实现查看摄像头画面和实现云台控制功能Extjs

    上个版本的大华摄像头监控的查看虽然可以达到初步效果,但是后续实现云台的控制等就无法实现了,所以后来采取了通过连接大华的dss平台来实现监控画面的查看和云台控制,实际的实现其实就是调用大华dss平台的接 ...

  2. 大华工业相机使用说明_大华C900系列SSD | 极速传输,不负美名

    对于游戏玩家和内容创作者这类对于电脑有高性能要求的人群来说,即使电脑一年一换,也还是会存在卡顿.死机.闪退一系列的问题. 这个时候就会感慨有没有一款固态硬盘,同在传输速度,容量方面可以满足日常使用,并 ...

  3. 大华 / 海康威视(HIKVISION) 网络视像头的连接及使用

    大华 / 海康威视(HIKVISION) 网络视像头连接方法完全一致,换个搜索摄像头ip的软件而已 总结: 1.用 软件/路由器 搜索摄像头ip(同一局域网下,用软件可以扫描到摄像头进行配置) 2.修 ...

  4. 大华摄像头DH-IPC-HFW1230M-I1-V2通过VLC连接查看实时视频流

    默认情况下,大华网络摄像机的IP地址是192.168.1.108,用户名是admin,密码是admin. 通过浏览器登陆后,能够对摄像头进行参数设置. 如果通过VLC连接摄像头时,需要知道摄像头的RT ...

  5. 来自iSpy整理的最全海康大华IPC的RTSP连接地址

    先贴出处: 海康:http://www.ispyconnect.com/man.aspx?n=Hikvision 大华:http://www.ispyconnect.com/man.aspx?n=Da ...

  6. 超阿里、大华,澎思科技行人再识别(ReID)技术刷新三大数据集记录

    整理 | Jane 出品 | AI科技大本营(ID:rgznai100) [导读]不久前,江苏省某市公安通过 AI 技术分析监控摄像头中的信息,抓获了一个偷盗电动车的嫌疑人员.监控摄像头在现场拍到的是 ...

  7. 海康大华RTSP格式

    海康实时流:rtsp://admin:12345@192.2.82.50:554/h264/ch4/main/av_stream 海康回放流(模拟通道):rtsp://admin:12345@192. ...

  8. 上海大华条码称代码_银豹收银之大华条码秤传称设置

    今天将和大家分享一下银豹收银PC大华条码秤传秤设置,银豹收银目前只支持PC端条码秤传秤. 准备工作 大华秤上位机安装 打开上海大华电子秤厂网:http://www.dahuascale.com,点击[ ...

  9. 大华管理平台用户名_大华HOC智慧物流可视化联网追溯解决方案,助力物流行业更高效...

    点击上方蓝字关注"大华行业" 随着电商产业的高速发展,物流已经成为人们生活中必不可少的一环.同时,作为国民经济的重要组成部分,物流行业所涉及到的领域也越来越广. 问题凸显 对监管部 ...

  10. 大华webplugin控件无法安装_大华监控平台SmartPSS如何上电视墙,一文包你学会

    弱电安防这块,监控系统在弱电中绝对占合同金额比非常高的系统,在国产监控厂家海康.大华.宇视,这三家在国内做非常大的,工程施工调试中最多的要么海康,要么大华,哪如何把监控摄像头在监控电视墙上显示.今天我 ...

最新文章

  1. ASP.NET MVC编程——视图
  2. 图解Numpy的tile函数
  3. Spring Boot和数据库初始化
  4. win7中输入文件夹首字母跳到相应的文件或者文件夹,却在搜索栏出现输入的字母...
  5. 8月23日亮相?三星Galaxy Note10+ 5G版渲染图曝光
  6. Windows域控设置IE主页 默认打开百度 【全域策略生效】
  7. 开源人脸106关键点
  8. 计算机页面排版的笔记,爱记笔记却懒得排版?这款笔记 App 为你准备了最实用的经典模板:格子笔记...
  9. ubuntu软件默认安装位置
  10. 解决contenteditable内自动生成font标签问题
  11. 批量将一个 PDF 文件按固定页数拆分成多个小的 PDF 文件
  12. oracle怎么看今天星期几,oracle 判断今天是星期几
  13. 艾永亮:从小公司到行业龙头,一路披荆斩棘,最后输给了电商
  14. 入门须知:次世代3D建模软件有哪些?
  15. macbook系统占用硬盘大_Sketch占满MacBook200G硬盘的解决方法
  16. 企业FAQ页面案例展示及FAQ站点搭建技巧
  17. huggingface中Bert模型的简单使用
  18. Linux复制文件时出现权限不够的问题
  19. Git——功能分支工作流
  20. jdbcTemplate.queryForList 返回值 大小写敏感的问题

热门文章

  1. MAX422与422转USB及485以及232接线方法
  2. 声音鉴定-趣味测试-源码
  3. Addressable 增量包
  4. DOTween 使用方法
  5. postman 生成html测试报告
  6. ads2020卸载 ads软件怎么卸载干净ads2016 ads2019卸载不干净无法重新安装 ads2017彻底卸载 ads2017卸载时删不尽
  7. java中将Excel转图片
  8. java EXCEL或WORD转PDF转图片(base64)
  9. 【OR】YALMIP 行列式最大化
  10. java请假系统毕业设计_基于java员工请假销假系统的设计与实现.doc