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

联合编程之连接相机


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

相关推荐
波波0075 小时前
C# 15 重磅新特性: 带标签 break 与 continue:重新定义嵌套循环控制流
服务器·前端·c#
wujian83118 小时前
怎么用千问生成word文档:从「格式崩」到「一键过」,AI导出鸭打通最后半厘米
人工智能·ai·c#·word·豆包·deepseek·ai导出鸭
zlinear数据采集卡9 小时前
D223上位机C#开发实战:从帧解析到波形显示的完整实现
开发语言·arm开发·嵌入式硬件·fpga开发·开源·c#
唐青枫11 小时前
别把 ImmutableArray 当成只读 List:C#.NET 不可变数组深入详解
c#·.net
西安景驰电子11 小时前
《PTP精确时间协议系列》第一篇:从原理到应用,全面解读IEEE 1588
linux·运维·服务器·开发语言·网络·windows·php
WangY_ZQ12 小时前
【无标题】
windows·python
言乐613 小时前
Python游戏水平测试辅助系统2
开发语言·windows·python·游戏·django
zlinear数据采集卡13 小时前
D223 ADC数据处理流水线:从原始采样值到工程单位的完整转换链
开发语言·arm开发·嵌入式硬件·fpga开发·开源·c#
百事牛科技14 小时前
办公文档防护:如何限制 PDF 转换成其他格式文件
windows·pdf