使用VisionPro连接GIGE相机

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Cognex.VisionPro;
using Cognex.VisionPro.Comm;
using Cognex.VisionPro.FGGigE;
using Cognex.VisionPro.QuickBuild;
using Cognex.VisionPro.ResultsAnalysis;
using Cognex.VisionPro.ToolGroup;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace VPPDemo
{
    public partial class Form1 : Form
    {
        private const int INFO_OK = 0;
        private const int INFO_ERR = -1;
 
        ICogAcqFifo mAcqFifo2;//定义一个相机对象
        private ICogFrameGrabber mFrameGrabber = null;//
        List<String> videoFormat = new List<String>();//相机信息列表
        private CogFrameGrabberGigEs mfr2;//取得相机列表
        private ICogFrameGrabber gbm2;//取第一个相机,第二个相机依次增加
 
        public Form1()
        {
            InitializeComponent();
        }
 
        /// <summary>
        /// 打开相机
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
             mfr2 = new CogFrameGrabberGigEs ();//取得相机列表
             gbm2 = mfr2[0];//取第一个相机,第二个相机依次增加
             mAcqFifo2 = gbm2.CreateAcqFifo ( gbm2.AvailableVideoFormats[0],
             CogAcqFifoPixelFormatConstants.Format8Grey, 0, true );//初始化相机
             cogRecordDisplay1.StartLiveDisplay ( mAcqFifo2, false );//控件绑定相机并显示画面
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            FindeCam();
        }
 
        /// <summary>
        /// 遍历相机
        /// </summary>
        /// <returns></returns>
        public int FindeCam()
        {
            try
            {
                CogFrameGrabberGigEs mframe = new CogFrameGrabberGigEs();
                if (mframe.Count < 1)
                {
                    MessageBox.Show("没有找到相机设备!");
                }
                //遍历已连接相机信息,并添加进列表里(相机名,序列号,模式)
                for (int i = 0; i < mframe.Count; i++)
                {
                    mFrameGrabber = mframe[i];
                    MessageBox.Show(mFrameGrabber.Name + mFrameGrabber.SerialNumber + mFrameGrabber.AvailableVideoFormats[0]);
                    videoFormat.Add(mFrameGrabber.Name + mFrameGrabber.SerialNumber + mFrameGrabber.AvailableVideoFormats[0]);
                }
                return INFO_OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(),"提示!",MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
                return INFO_ERR;
            }
        }
 
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
      
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            gbm2.Disconnect(true);
        }
    }
}

  

posted @   金雨CHN  阅读(143)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
点击右上角即可分享
微信分享提示