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

联合编程之连接相机


一,连接相机(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即可。

相关推荐
小羊没烦恼!3 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
rockmelodies3 天前
# Windows Server2008 R2 Standard(SP1镜像U盘)重置本地管理员密码【完整详细步骤】
windows·密码破解
神仙别闹3 天前
基于C#+MySQL实现(WinForm)个人聊天室软件
c#
liufeiyu19763 天前
VS 2026 升级后出现错误: 找不到指定的 SDK“Microsoft.NET.Sdk”
visual studio·vs 2026
霍霍的袁3 天前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio
kybs19913 天前
全球灾害数据分析可视化 毕业设计-附源码66794
vue.js·spring boot·mysql·安全·django·c#·asp.net
kakakahahahaha3 天前
Windows C盘空间不足的安全清理与迁移流程
windows·电脑·笔记本电脑·软件需求·c盘清理
做咩啊~3 天前
远程连接提示:身份验证错误,要求的函数不受支持
windows
Polevne3 天前
C# SFTP客户端实现文件传输
c#·ssh
samble3 天前
从零搭建灌装监控系统(四):深色主题与样式系统,ResourceDictionary 统一管理
c#·wpf·mvvm·样式·工业控制