编程实战:相机连接与参数设置指南

联合编程之连接相机


一,连接相机(1)

1,相关重点

【1】,//OwnedExposureParams 获取曝光参数
textBox1.Text = acq.Operator.OwnedExposureParams.ToString();

【2】,//OwnedBrightnessParams //设置亮度的参数
textBox2.Text = acq.Operator.OwnedBrightnessParams.ToString();

【3】,//设置对比度
textBox3.Text = acq.Operator.OwnedContrastParams.Contrast.ToString();

【4】,CogAcqFifoTool acq = new CogAcqFifoTool();

//acq 相机工具
//acq.Operator 相机本机
//acq.Operator.FrameGrabber 相机采集图像时的对象

【5】, cogRecordDisplay1.StartLiveDisplay(acq.Operator);// 开启实时显示
// cogRecordDisplay1.StopLiveDisplay(); // 关闭实时显示


操作如下:

1,先在Winform界面添加以下相关控件:

然后代码编写如下:

CogAcqFifoTool acq = new CogAcqFifoTool();
1, //窗口加载按钮
private void Form1_Load(object sender, EventArgs e)
{
string path = @"C:\Users\Administrator\Desktop\acq.vpp";
acq = CogSerializer.LoadObjectFromFile(path) as CogAcqFifoTool;
cogAcqFifoEditV21.Subject = acq;

//读取ini相机配置文件
double e1 = IniAPI.GetPrivateProfileDouble("相机","曝光",0,"C:\\Users\\Administrator\\Desktop\\第45天\\02连接相机1\\bin\\Debug\\1.ini");
double e2 = IniAPI.GetPrivateProfileDouble("相机", "亮度", 0, "C:\\Users\\Administrator\\Desktop\\第45天\\02连接相机1\\bin\\Debug\\1.ini");
double e3 = IniAPI.GetPrivateProfileDouble("相机", "对比度", 0, "C:\\Users\\Administrator\\Desktop\\第45天\\02连接相机1\\bin\\Debug\\1.ini");

//设置相机参数
acq.Operator.OwnedExposureParams.Exposure = e1;
acq.Operator.OwnedBrightnessParams.Brightness = e2;

acq.Operator.OwnedContrastParams.Contrast = e3;

//显示输入框上面
//OwnedExposureParams 获取曝光参数
//Exposure 曝光
textBox1.Text = acq.Operator.OwnedExposureParams.Exposure.ToString();

//OwnedBrightnessParams 设置亮度的参数
//Brightness 亮度
textBox2.Text = acq.Operator.OwnedBrightnessParams.Brightness.ToString();

//设置对比度
//Contrast 对比度
textBox3.Text = acq.Operator.OwnedContrastParams.Contrast.ToString();

}

2,连接相机按钮

private void button1_Click(object sender, EventArgs e)
{

}
//实时显示
private void button2_Click(object sender, EventArgs e)
{
//acq CogAcqFifoTool类型
//acq.Operator ICogAcqFifo
cogRecordDisplay1.StartLiveDisplay(acq.Operator);// 开启实时显示
// cogRecordDisplay1.StopLiveDisplay(); // 关闭实时显示
}

3,拍照保存按钮

private void button3_Click(object sender, EventArgs e)
{

//设置相机参数
acq.Operator.OwnedExposureParams.Exposure = double.Parse(textBox1.Text);
acq.Operator.OwnedBrightnessParams.Brightness = double.Parse(textBox2.Text);
acq.Operator.OwnedContrastParams.Contrast = double.Parse(textBox3.Text);

//acq 加载vpp不成功了 acq为null
//acq.Operator=n=ull 连接相机失败
if (acq!=null && acq.Operator!=null)
{
acq.Run();
cogRecordDisplay1.Image = acq.OutputImage; // 运行工具 把相机输出图进行展示
cogRecordDisplay1.Fit();

}

4,保存相机设置

private void button4_Click(object sender, EventArgs e)
{
IniAPI.INIWriteValue("C:\\Users\\Administrator\\Desktop\\第45天\\02连接相机1\\bin\\Debug\\1.ini", "相机","曝光",textBox1.Text);
IniAPI.INIWriteValue("C:\\Users\\Administrator\\Desktop\\第45天\\02连接相机1\\bin\\Debug\\1.ini", "相机", "亮度", textBox2.Text);
IniAPI.INIWriteValue("C:\\Users\\Administrator\\Desktop\\第45天\\02连接相机1\\bin\\Debug\\1.ini", "相机", "对比度", textBox3.Text);

}

//窗体关闭时候 释放相机
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
cogRecordDisplay1.StopLiveDisplay();//关闭实时显示
if (acq!=null&&acq.Operator!=null)
{
//acq visionpro的相机工具
//acq.Operator 相机
// acq.Operator.FrameGrabber 相机的采集图像的对象
acq.Operator.FrameGrabber.Disconnect(false); // 释放相机

}
}
}

注意:如果报错,请在解决方案界面添加现有项浏览加入Ini即可。

相关推荐
取个名字太难了a11 分钟前
用户态异常处理:SEH 调用链分析(五)
windows
love530love43 分钟前
Duix-Avatar 去 Docker Desktop 本地化完整复盘
人工智能·pytorch·windows·python·docker·容器·数字人
张人玉1 小时前
C# 中的 MVC、MVP、MVVM 模式详解
开发语言·c#·mvc·mvvm·mvp
skywalk81631 小时前
iwr -useb https://openclaw.ai/install.ps1 | iex 这里的iwr怎么安装?
windows
晨曦_子画1 小时前
C# sql语句含有 like %name%如何提高查询效率
数据库·sql·c#
浩瀚之水_csdn1 小时前
++ Lambda 表达式详解
java·jvm·windows
ou.cs1 小时前
C# params 关键字详解:从入门到精通(保姆级教程)
开发语言·c#·.net
Anesthesia丶1 小时前
Windows WSL子系统设置独立IP访问
windows·网络协议·tcp/ip
weixin_531651812 小时前
Python 渐进式学习指南
开发语言·windows·python
夏日听雨眠2 小时前
文件学习终
windows·学习