using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PaintDotNet.Base.SettingModel;
using System.Collections;
using PaintDotNet.ImageCollect.CameraManager;
using TUCAMAPI;
using TUCamera;
using OpenCvSharp;
using System.Threading;
using OpenCvSharp.Extensions;
namespace PaintDotNet.Setting.LabelComponent
{
///
/// 相机设置,调节界面
///
public class AdjustCameraControl : UserControl
{
#region 控件
private Label label5;
private TrackBar lightTBar;
private TrackBar ExposureTBar;
private GroupBox groupBox1;
private Label label6;
private GroupBox groupBox2;
private GroupBox groupBox3;
private CheckBox xianshiColourCheckBox;
private Button button5;
private Button button4;
private Button button3;
private Button button2;
private TrackBar blueChannelTB;
private Label label9;
private Label label8;
private TrackBar greenChannelTB;
private Label label7;
private TrackBar redChannelTB;
private Label label12;
private Label label11;
private Label label10;
private GroupBox groupBox4;
private Label label13;
private Label lblBaoGuangMaxVal;
private Label lblBaoGuangMinVal;
private Label label3;
private Label label4;
private TextBox ExposureBox;
private TextBox LightBox;
private PictureBox lanlvpictureBox;
private PictureBox lansepictureBox;
private PictureBox huangsepictureBox;
private PictureBox lvsepictureBox;
private PictureBox yanghongsepictureBox;
private PictureBox hongsepictureBox;
private Label lblSaturationMinVal;
private TextBox baoheduTBox;
private Label lblSaturationMaxVal;
private TrackBar baoheduTBar;
///
/// 增益值下拉选
///
string[] gainArray = new string[] { PdnResources.GetString("Menu.Highgai.Text"), PdnResources.GetString("Menu.Lowgain.Text") };
///
/// 相机参数的Model
///
private CameraParamModel m_cameraParamModel;
private CheckBox checkBoxAutoExposure;
private bool m_immediately;
private bool m_toAddExtraButtons = false;
private TUCamera.TUCamera m_camera;
private Label lblGainMin;
private Label lblGainMax;
private TrackBar trbGain;
private TextBox txtGain;
private Button button1;
private Button btnAutoExposureOnce;
private Button button6;
private Button button7;
private Label unitLabel;
private System.Timers.Timer m_Timer;
#endregion
public AdjustCameraControl(CameraParamModel model, bool immediately, bool toAddExtraButtons = false)
{
m_cameraParamModel = model;
m_immediately = immediately;
m_toAddExtraButtons = toAddExtraButtons;
m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
InitializeComponent();
InitializeLanguageText();
InitColorAdjustRange();
InitializeControlData();
}
public void ResetCameraParamModel(CameraParamModel model)
{
m_cameraParamModel = model;
InitColorAdjustRange();
InitializeControlData();
}
int resolution_width = 2448;
int resolution_height = 2048;
private void InitColorAdjustRange()
{
if (m_camera.IsOpen())
{
// 曝光时间
double aeMinVal = 0;
double aeMaxVal = 0;
double aeDftVal = 0;
m_camera.GetExposureTimeRange(ref aeMinVal, ref aeMaxVal, ref aeDftVal);
SetExposureBarRange(aeMinVal, aeMaxVal);
lblBaoGuangMinVal.Text = ((int)aeMinVal).ToString() + "μs";
lblBaoGuangMaxVal.Text = UpdateExposureTime((UInt64)aeMaxVal);
// Get red channel range
int minVal = 0;
int maxVal = 0;
m_camera.GetColorChannelRang(ColorChannel.RED, ref minVal, ref maxVal);
redChannelTB.SetRange(minVal, maxVal);
// Get green channel range
m_camera.GetColorChannelRang(ColorChannel.GREEN, ref minVal, ref maxVal);
greenChannelTB.SetRange(minVal, maxVal);
// Get blue channel range
m_camera.GetColorChannelRang(ColorChannel.BLUE, ref minVal, ref maxVal);
blueChannelTB.SetRange(minVal, maxVal);
// Get gain range
TUCAM_PROP_ATTR attrProp;
attrProp = m_camera.GetGlobalGainRange();
trbGain.SetRange((int)attrProp.dbValMin, (int)attrProp.dbValMax);
lblGainMin.Text = trbGain.Minimum.ToString();
lblGainMax.Text = trbGain.Maximum.ToString();
// 饱和度
minVal = 0;
maxVal = 0;
m_camera.GetSaturationRange(ref minVal, ref maxVal);
baoheduTBar.SetRange(minVal, maxVal);
lblSaturationMinVal.Text = ((int)minVal).ToString();
lblSaturationMaxVal.Text = ((int)maxVal).ToString();
var bitmap = m_camera.OneShoot();
if (bitmap == null) return;
showHistImg(BitmapConverter.ToMat(bitmap));
}
}
Mat[] oldHists = new Mat[] { new Mat(), new Mat(), new Mat() };
private void showHistImg(Mat BoxMat)
{
Mat[] mats = Cv2.Split(BoxMat);//一张图片,将panda拆分成3个图片装进mat
if (mats.Count() == 1)
{
Mat[] mats011 = new Mat[] { mats[0] };//panda的第一个通道,也就是B
int[] channels011 = new int[] { 0 };//一个通道,初始化为通道0,这些东西可以共用设置一个就行
int[] histsize11 = new int[] { 256 };//一个通道,初始化为256箱子
Rangef[] range11 = new Rangef[1];//一个通道,范围
range11[0].Start = 0.0F;//从0开始(含)
range11[0].End = 256.0F;//到256结束(不含)
Mat mask11 = new Mat();//不做掩码
Cv2.CalcHist(mats011, channels011, mask11, oldHists[0], 1, histsize11, range11);//对被拆分的图片单独进行计算
return;
}
Mat[] mats0 = new Mat[] { mats[0] };//panda的第一个通道,也就是B
Mat[] mats1 = new Mat[] { mats[1] };//panda的第二个通道,也就是G
Mat[] mats2 = new Mat[] { mats[2] };//panda的第三个通道,也就是R
int[] channels0 = new int[] { 0 };//一个通道,初始化为通道0,这些东西可以共用设置一个就行
int[] channels1 = new int[] { 0 };
int[] channels2 = new int[] { 0 };
int[] histsize = new int[] { 256 };//一个通道,初始化为256箱子
Rangef[] range = new Rangef[1];//一个通道,范围
range[0].Start = 0.0F;//从0开始(含)
range[0].End = 256.0F;//到256结束(不含)
Mat mask = new Mat();//不做掩码
Cv2.CalcHist(mats0, channels0, mask, oldHists[0], 1, histsize, range);//对被拆分的图片单独进行计算
Cv2.CalcHist(mats1, channels1, mask, oldHists[1], 1, histsize, range);//对被拆分的图片单独进行计算
Cv2.CalcHist(mats2, channels2, mask, oldHists[2], 1, histsize, range);//对被拆分的图片单独进行计算
}
private string UpdateExposureTime(UInt64 exposureTime)
{
string str = "";
int sec = 0;
int msec = 0;
int usec = 0;
m_camera.UpdateExposureTime(ref sec, ref msec, ref usec, exposureTime);
if (sec > 0)
{
str += sec + "s";
}
else if (msec > 0)
{
str += msec + "ms";
}
else if (usec > 0)
{
str += usec + "μs";
}
return str;
}
private void UpdateExposureUI(int autoExposure)
{
m_Timer.Enabled = autoExposure == 1;
if (autoExposure == 1)
{
checkBoxAutoExposure.Checked = true;
ExposureTBar.Enabled = false;
ExposureBox.Enabled = false;
trbGain.Enabled = false;
txtGain.Enabled = false;
m_camera.SetExposureMode(ExposureMode.AUTO);
}
else
{
checkBoxAutoExposure.Checked = false;
ExposureTBar.Enabled = true;
ExposureBox.Enabled = true;
trbGain.Enabled = true;
txtGain.Enabled = true;
m_camera.SetExposureMode(ExposureMode.MANUAL);
}
}
///
/// 设置下拉等数据源
///
private void InitializeControlData()
{
m_Timer = new System.Timers.Timer(1000);
m_Timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimerAutoExposure);
m_Timer.AutoReset = true;
m_Timer.SynchronizingObject = this;
// 曝光时间
int value = (int)(m_cameraParamModel.parame.LNExposure);
SetExposureBarValue(value);
DisplayExposureText(value);
// 曝光百分比
value = m_cameraParamModel.parame.Light;
value = value < 0 ? 0 : value > 255 ? 255 : value;
lightTBar.Value = value;
LightBox.Text = value.ToString();
UpdateExposureUI(m_cameraParamModel.parame.ATExposure);
// 增益值调整
int gainValue = m_cameraParamModel.parame.GlobalGain;
if (gainValue >= this.trbGain.Minimum && gainValue <= this.trbGain.Maximum)
{
this.trbGain.Value = gainValue;
txtGain.Text = gainValue.ToString();
}
// 颜色值
int redChannelValue = (int)m_cameraParamModel.parame.RedChannel;
if (redChannelValue >= this.redChannelTB.Minimum && redChannelValue <= this.redChannelTB.Maximum)
{
this.redChannelTB.Value = redChannelValue;
}
int greenChannelValue = (int)m_cameraParamModel.parame.GreenChannel;
if (greenChannelValue >= this.greenChannelTB.Minimum && greenChannelValue <= this.greenChannelTB.Maximum)
{
this.greenChannelTB.Value = greenChannelValue;
}
int blueChannelValue = (int)m_cameraParamModel.parame.BlueChannel;
if (blueChannelValue >= this.blueChannelTB.Minimum && blueChannelValue <= this.blueChannelTB.Maximum)
{
this.blueChannelTB.Value = blueChannelValue;
}
// 白平衡
if (m_cameraParamModel.parame.WhiteBalance == 1)
{
AutoWhiteBalance(true);
}
else
{
if (m_cameraParamModel.parame.FMExposure == 1)
{
m_camera.SetColorTemperatureByString("3200K");
}
else if (m_cameraParamModel.parame.FMExposure == 2)
{
m_camera.SetColorTemperatureByString("5500K");
}
AutoWhiteBalance(false);
}
// 显示颜色值通道
if (m_cameraParamModel.parame.ShowColorPBoxFlag == 1)
{
this.xianshiColourCheckBox.Checked = true;
}
else
{
this.xianshiColourCheckBox.Checked = false;
}
// 饱和度
int baoheduTBarValue = this.m_cameraParamModel.parame.Saturation;
if (baoheduTBarValue >= this.baoheduTBar.Minimum && baoheduTBarValue <= this.baoheduTBar.Maximum)
{
this.baoheduTBar.Value = this.m_cameraParamModel.parame.Saturation;
}
if (m_toAddExtraButtons)
{
this.button6.Visible = true;
this.button7.Visible = true;
}
}
private void InitializeLanguageText()
{
this.label5.Text = PdnResources.GetString("Menu.timeofexposure.text") + ":";
this.groupBox1.Text = PdnResources.GetString("Menu.timeofexposure.text");
this.btnAutoExposureOnce.Text = PdnResources.GetString("Menu.Oneautomaticexposure.Text");
this.checkBoxAutoExposure.Text = PdnResources.GetString("Menu.auto-exposure.text");
this.label6.Text = PdnResources.GetString("Menu.Exposurepercentage.text") + ":";
this.groupBox2.Text = PdnResources.GetString("Menu.Gainvalueadjustment.text");
this.groupBox3.Text = PdnResources.GetString("Menu.Image.WhiteBalance.Text");
this.button1.Text = PdnResources.GetString("Menu.Primarywhitebalance.Text");
this.label12.Text = PdnResources.GetString("Menu.Blue.text");
this.label11.Text = PdnResources.GetString("Menu.green.text");
this.label10.Text = PdnResources.GetString("Menu.red.text");
this.label9.Text = PdnResources.GetString("Menu.yellow.text");
this.label8.Text = PdnResources.GetString("Menu.Magenta.text");
this.label7.Text = PdnResources.GetString("Menu.aqua.text");
this.xianshiColourCheckBox.Text = PdnResources.GetString("Menu.Displaycolorvaluechannel.text");
this.button3.Text = PdnResources.GetString("Menu.auto.text");
this.button2.Text = PdnResources.GetString("Menu.Manual.text");
this.groupBox4.Text = PdnResources.GetString("Menu.Colorandsaturation.Text");
this.label13.Text = PdnResources.GetString("Menu.saturation.text") + ":";
}
private void InitializeComponent()
{
this.label5 = new System.Windows.Forms.Label();
this.lightTBar = new System.Windows.Forms.TrackBar();
this.ExposureTBar = new System.Windows.Forms.TrackBar();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.unitLabel = new System.Windows.Forms.Label();
this.btnAutoExposureOnce = new System.Windows.Forms.Button();
this.checkBoxAutoExposure = new System.Windows.Forms.CheckBox();
this.ExposureBox = new System.Windows.Forms.TextBox();
this.LightBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.lblBaoGuangMaxVal = new System.Windows.Forms.Label();
this.lblBaoGuangMinVal = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtGain = new System.Windows.Forms.TextBox();
this.lblGainMin = new System.Windows.Forms.Label();
this.lblGainMax = new System.Windows.Forms.Label();
this.trbGain = new System.Windows.Forms.TrackBar();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.lansepictureBox = new System.Windows.Forms.PictureBox();
this.huangsepictureBox = new System.Windows.Forms.PictureBox();
this.lvsepictureBox = new System.Windows.Forms.PictureBox();
this.yanghongsepictureBox = new System.Windows.Forms.PictureBox();
this.hongsepictureBox = new System.Windows.Forms.PictureBox();
this.lanlvpictureBox = new System.Windows.Forms.PictureBox();
this.label12 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.blueChannelTB = new System.Windows.Forms.TrackBar();
this.label9 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.greenChannelTB = new System.Windows.Forms.TrackBar();
this.label7 = new System.Windows.Forms.Label();
this.redChannelTB = new System.Windows.Forms.TrackBar();
this.xianshiColourCheckBox = new System.Windows.Forms.CheckBox();
this.button5 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.lblSaturationMinVal = new System.Windows.Forms.Label();
this.baoheduTBox = new System.Windows.Forms.TextBox();
this.label13 = new System.Windows.Forms.Label();
this.lblSaturationMaxVal = new System.Windows.Forms.Label();
this.baoheduTBar = new System.Windows.Forms.TrackBar();
((System.ComponentModel.ISupportInitialize)(this.lightTBar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ExposureTBar)).BeginInit();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trbGain)).BeginInit();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.lansepictureBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.huangsepictureBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.lvsepictureBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.yanghongsepictureBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.hongsepictureBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.lanlvpictureBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.blueChannelTB)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.greenChannelTB)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.redChannelTB)).BeginInit();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.baoheduTBar)).BeginInit();
this.SuspendLayout();
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(18, 31);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(59, 12);
this.label5.TabIndex = 12;
this.label5.Text = "曝光时间:";
//
// lightTBar
//
this.lightTBar.Location = new System.Drawing.Point(89, 66);
this.lightTBar.Maximum = 255;
this.lightTBar.Name = "lightTBar";
this.lightTBar.Size = new System.Drawing.Size(274, 45);
this.lightTBar.TabIndex = 13;
this.lightTBar.TickStyle = System.Windows.Forms.TickStyle.None;
this.lightTBar.Value = 64;
this.lightTBar.Scroll += new System.EventHandler(this.Light_ValueChanged);
//
// ExposureTBar
//
this.ExposureTBar.Location = new System.Drawing.Point(89, 31);
this.ExposureTBar.Maximum = 148;
this.ExposureTBar.Name = "ExposureTBar";
this.ExposureTBar.Size = new System.Drawing.Size(274, 45);
this.ExposureTBar.TabIndex = 14;
this.ExposureTBar.TickStyle = System.Windows.Forms.TickStyle.None;
this.ExposureTBar.Scroll += new System.EventHandler(this.Exposure_ValueChanged);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.unitLabel);
this.groupBox1.Controls.Add(this.btnAutoExposureOnce);
this.groupBox1.Controls.Add(this.checkBoxAutoExposure);
this.groupBox1.Controls.Add(this.ExposureBox);
this.groupBox1.Controls.Add(this.LightBox);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.lblBaoGuangMaxVal);
this.groupBox1.Controls.Add(this.lblBaoGuangMinVal);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.lightTBar);
this.groupBox1.Controls.Add(this.ExposureTBar);
this.groupBox1.Location = new System.Drawing.Point(13, 14);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(464, 154);
this.groupBox1.TabIndex = 15;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "曝光时间";
//
// unitLabel
//
this.unitLabel.AutoSize = true;
this.unitLabel.Location = new System.Drawing.Point(429, 37);
this.unitLabel.Name = "unitLabel";
this.unitLabel.Size = new System.Drawing.Size(41, 12);
this.unitLabel.TabIndex = 37;
this.unitLabel.Text = "label1";
//
// btnAutoExposureOnce
//
this.btnAutoExposureOnce.Location = new System.Drawing.Point(122, 111);
this.btnAutoExposureOnce.Margin = new System.Windows.Forms.Padding(2);
this.btnAutoExposureOnce.Name = "btnAutoExposureOnce";
this.btnAutoExposureOnce.Size = new System.Drawing.Size(102, 25);
this.btnAutoExposureOnce.TabIndex = 36;
this.btnAutoExposureOnce.Text = "一次自动曝光";
this.btnAutoExposureOnce.UseVisualStyleBackColor = true;
this.btnAutoExposureOnce.Click += new System.EventHandler(this.btnAutoExposureOnce_Click);
//
// checkBoxAutoExposure
//
this.checkBoxAutoExposure.AutoSize = true;
this.checkBoxAutoExposure.Location = new System.Drawing.Point(21, 117);
this.checkBoxAutoExposure.Margin = new System.Windows.Forms.Padding(2);
this.checkBoxAutoExposure.Name = "checkBoxAutoExposure";
this.checkBoxAutoExposure.Size = new System.Drawing.Size(72, 16);
this.checkBoxAutoExposure.TabIndex = 34;
this.checkBoxAutoExposure.Text = "自动曝光";
this.checkBoxAutoExposure.UseVisualStyleBackColor = true;
this.checkBoxAutoExposure.Click += new System.EventHandler(this.checkBoxAutoExposure_CheckedChanged);
//
// ExposureBox
//
this.ExposureBox.Location = new System.Drawing.Point(370, 31);
this.ExposureBox.Name = "ExposureBox";
this.ExposureBox.Size = new System.Drawing.Size(55, 21);
this.ExposureBox.TabIndex = 31;
this.ExposureBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.baoGuangTBox_KeyPress);
//
// LightBox
//
this.LightBox.Location = new System.Drawing.Point(371, 66);
this.LightBox.Name = "LightBox";
this.LightBox.Size = new System.Drawing.Size(55, 21);
this.LightBox.TabIndex = 30;
this.LightBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.baoGuangPertBox_KeyPress);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(327, 91);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(23, 12);
this.label3.TabIndex = 22;
this.label3.Text = "255";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(93, 91);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(11, 12);
this.label4.TabIndex = 21;
this.label4.Text = "0";
//
// lblBaoGuangMaxVal
//
this.lblBaoGuangMaxVal.AutoSize = true;
this.lblBaoGuangMaxVal.Location = new System.Drawing.Point(321, 53);
this.lblBaoGuangMaxVal.Name = "lblBaoGuangMaxVal";
this.lblBaoGuangMaxVal.Size = new System.Drawing.Size(35, 12);
this.lblBaoGuangMaxVal.TabIndex = 20;
this.lblBaoGuangMaxVal.Text = "1000s";
//
// lblBaoGuangMinVal
//
this.lblBaoGuangMinVal.AutoSize = true;
this.lblBaoGuangMinVal.Location = new System.Drawing.Point(93, 53);
this.lblBaoGuangMinVal.Name = "lblBaoGuangMinVal";
this.lblBaoGuangMinVal.Size = new System.Drawing.Size(41, 12);
this.lblBaoGuangMinVal.TabIndex = 19;
this.lblBaoGuangMinVal.Text = "250μs";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(18, 66);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(35, 12);
this.label6.TabIndex = 15;
this.label6.Text = "亮度:";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.txtGain);
this.groupBox2.Controls.Add(this.lblGainMin);
this.groupBox2.Controls.Add(this.lblGainMax);
this.groupBox2.Controls.Add(this.trbGain);
this.groupBox2.Location = new System.Drawing.Point(13, 182);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(464, 84);
this.groupBox2.TabIndex = 16;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "增益值调整";
//
// txtGain
//
this.txtGain.Location = new System.Drawing.Point(369, 21);
this.txtGain.Name = "txtGain";
this.txtGain.Size = new System.Drawing.Size(55, 21);
this.txtGain.TabIndex = 36;
this.txtGain.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtGain_KeyPress);
//
// lblGainMin
//
this.lblGainMin.AutoSize = true;
this.lblGainMin.Location = new System.Drawing.Point(97, 54);
this.lblGainMin.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblGainMin.Name = "lblGainMin";
this.lblGainMin.Size = new System.Drawing.Size(11, 12);
this.lblGainMin.TabIndex = 17;
this.lblGainMin.Text = "0";
//
// lblGainMax
//
this.lblGainMax.AutoSize = true;
this.lblGainMax.Location = new System.Drawing.Point(340, 54);
this.lblGainMax.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblGainMax.Name = "lblGainMax";
this.lblGainMax.Size = new System.Drawing.Size(23, 12);
this.lblGainMax.TabIndex = 16;
this.lblGainMax.Text = "255";
//
// trbGain
//
this.trbGain.Location = new System.Drawing.Point(89, 21);
this.trbGain.Maximum = 255;
this.trbGain.Name = "trbGain";
this.trbGain.Size = new System.Drawing.Size(280, 45);
this.trbGain.TabIndex = 15;
this.trbGain.TickStyle = System.Windows.Forms.TickStyle.None;
this.trbGain.Value = 10;
this.trbGain.Scroll += new System.EventHandler(this.trbGain_ValueChanged);
this.trbGain.ValueChanged += new System.EventHandler(this.trbGain_ValueChanged);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.button6);
this.groupBox3.Controls.Add(this.button7);
this.groupBox3.Controls.Add(this.button1);
this.groupBox3.Controls.Add(this.lansepictureBox);
this.groupBox3.Controls.Add(this.huangsepictureBox);
this.groupBox3.Controls.Add(this.lvsepictureBox);
this.groupBox3.Controls.Add(this.yanghongsepictureBox);
this.groupBox3.Controls.Add(this.hongsepictureBox);
this.groupBox3.Controls.Add(this.lanlvpictureBox);
this.groupBox3.Controls.Add(this.label12);
this.groupBox3.Controls.Add(this.label11);
this.groupBox3.Controls.Add(this.label10);
this.groupBox3.Controls.Add(this.blueChannelTB);
this.groupBox3.Controls.Add(this.label9);
this.groupBox3.Controls.Add(this.label8);
this.groupBox3.Controls.Add(this.greenChannelTB);
this.groupBox3.Controls.Add(this.label7);
this.groupBox3.Controls.Add(this.redChannelTB);
this.groupBox3.Controls.Add(this.xianshiColourCheckBox);
this.groupBox3.Controls.Add(this.button5);
this.groupBox3.Controls.Add(this.button4);
this.groupBox3.Controls.Add(this.button3);
this.groupBox3.Controls.Add(this.button2);
this.groupBox3.Location = new System.Drawing.Point(13, 283);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(464, 211);
this.groupBox3.TabIndex = 17;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "白平衡";
//
// button6
//
this.button6.Location = new System.Drawing.Point(105, 58);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(75, 23);
this.button6.TabIndex = 39;
this.button6.Text = "原图取色";
this.button6.UseVisualStyleBackColor = true;
this.button6.Visible = false;
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
this.button7.Location = new System.Drawing.Point(20, 58);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(75, 23);
this.button7.TabIndex = 38;
this.button7.Text = "区域选择";
this.button7.UseVisualStyleBackColor = true;
this.button7.Visible = false;
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(191, 29);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 37;
this.button1.Text = "一次白平衡";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// lansepictureBox
//
this.lansepictureBox.BackColor = System.Drawing.Color.Blue;
this.lansepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lansepictureBox.Location = new System.Drawing.Point(412, 175);
this.lansepictureBox.Name = "lansepictureBox";
this.lansepictureBox.Size = new System.Drawing.Size(12, 12);
this.lansepictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.lansepictureBox.TabIndex = 36;
this.lansepictureBox.TabStop = false;
//
// huangsepictureBox
//
this.huangsepictureBox.BackColor = System.Drawing.Color.Yellow;
this.huangsepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.huangsepictureBox.Location = new System.Drawing.Point(33, 175);
this.huangsepictureBox.Name = "huangsepictureBox";
this.huangsepictureBox.Size = new System.Drawing.Size(12, 12);
this.huangsepictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.huangsepictureBox.TabIndex = 35;
this.huangsepictureBox.TabStop = false;
//
// lvsepictureBox
//
this.lvsepictureBox.BackColor = System.Drawing.Color.Lime;
this.lvsepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lvsepictureBox.Location = new System.Drawing.Point(412, 145);
this.lvsepictureBox.Name = "lvsepictureBox";
this.lvsepictureBox.Size = new System.Drawing.Size(12, 12);
this.lvsepictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.lvsepictureBox.TabIndex = 34;
this.lvsepictureBox.TabStop = false;
//
// yanghongsepictureBox
//
this.yanghongsepictureBox.BackColor = System.Drawing.Color.Fuchsia;
this.yanghongsepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.yanghongsepictureBox.Location = new System.Drawing.Point(33, 145);
this.yanghongsepictureBox.Name = "yanghongsepictureBox";
this.yanghongsepictureBox.Size = new System.Drawing.Size(12, 12);
this.yanghongsepictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.yanghongsepictureBox.TabIndex = 33;
this.yanghongsepictureBox.TabStop = false;
//
// hongsepictureBox
//
this.hongsepictureBox.BackColor = System.Drawing.Color.Red;
this.hongsepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.hongsepictureBox.Location = new System.Drawing.Point(412, 116);
this.hongsepictureBox.Name = "hongsepictureBox";
this.hongsepictureBox.Size = new System.Drawing.Size(12, 12);
this.hongsepictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.hongsepictureBox.TabIndex = 32;
this.hongsepictureBox.TabStop = false;
//
// lanlvpictureBox
//
this.lanlvpictureBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.lanlvpictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lanlvpictureBox.Location = new System.Drawing.Point(33, 116);
this.lanlvpictureBox.Name = "lanlvpictureBox";
this.lanlvpictureBox.Size = new System.Drawing.Size(12, 12);
this.lanlvpictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.lanlvpictureBox.TabIndex = 31;
this.lanlvpictureBox.TabStop = false;
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(368, 175);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(29, 12);
this.label12.TabIndex = 30;
this.label12.Text = "蓝色";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(368, 145);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(29, 12);
this.label11.TabIndex = 29;
this.label11.Text = "绿色";
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(368, 116);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(29, 12);
this.label10.TabIndex = 28;
this.label10.Text = "红色";
//
// blueChannelTB
//
this.blueChannelTB.Location = new System.Drawing.Point(104, 175);
this.blueChannelTB.Maximum = 1366;
this.blueChannelTB.Name = "blueChannelTB";
this.blueChannelTB.Size = new System.Drawing.Size(246, 45);
this.blueChannelTB.TabIndex = 27;
this.blueChannelTB.TickStyle = System.Windows.Forms.TickStyle.None;
this.blueChannelTB.ValueChanged += new System.EventHandler(this.blueChannelTB_ValueChanged);
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(58, 175);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(29, 12);
this.label9.TabIndex = 26;
this.label9.Text = "黄色";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(58, 145);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(29, 12);
this.label8.TabIndex = 25;
this.label8.Text = "洋红";
//
// greenChannelTB
//
this.greenChannelTB.Location = new System.Drawing.Point(104, 145);
this.greenChannelTB.Maximum = 1366;
this.greenChannelTB.Name = "greenChannelTB";
this.greenChannelTB.Size = new System.Drawing.Size(246, 45);
this.greenChannelTB.TabIndex = 24;
this.greenChannelTB.TickStyle = System.Windows.Forms.TickStyle.None;
this.greenChannelTB.Scroll += new System.EventHandler(this.greenChannelTB_Scroll);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(58, 116);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(29, 12);
this.label7.TabIndex = 23;
this.label7.Text = "青色";
//
// redChannelTB
//
this.redChannelTB.Location = new System.Drawing.Point(104, 116);
this.redChannelTB.Maximum = 1366;
this.redChannelTB.Name = "redChannelTB";
this.redChannelTB.Size = new System.Drawing.Size(246, 45);
this.redChannelTB.TabIndex = 22;
this.redChannelTB.TickStyle = System.Windows.Forms.TickStyle.None;
this.redChannelTB.ValueChanged += new System.EventHandler(this.redChannelTB_ValueChanged);
//
// xianshiColourCheckBox
//
this.xianshiColourCheckBox.AutoSize = true;
this.xianshiColourCheckBox.Checked = true;
this.xianshiColourCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
this.xianshiColourCheckBox.Location = new System.Drawing.Point(20, 87);
this.xianshiColourCheckBox.Name = "xianshiColourCheckBox";
this.xianshiColourCheckBox.Size = new System.Drawing.Size(108, 16);
this.xianshiColourCheckBox.TabIndex = 21;
this.xianshiColourCheckBox.Text = "显示颜色值通道";
this.xianshiColourCheckBox.UseVisualStyleBackColor = true;
this.xianshiColourCheckBox.CheckedChanged += new System.EventHandler(this.xianshiColourCheckBox_CheckedChanged);
//
// button5
//
this.button5.Location = new System.Drawing.Point(362, 29);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(75, 23);
this.button5.TabIndex = 20;
this.button5.Text = "5500K";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(277, 29);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 23);
this.button4.TabIndex = 19;
this.button4.Text = "3200K";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(106, 29);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 18;
this.button3.Text = "自动";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(20, 29);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 17;
this.button2.Text = "手动";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// groupBox4
//
this.groupBox4.Controls.Add(this.lblSaturationMinVal);
this.groupBox4.Controls.Add(this.baoheduTBox);
this.groupBox4.Controls.Add(this.label13);
this.groupBox4.Controls.Add(this.lblSaturationMaxVal);
this.groupBox4.Controls.Add(this.baoheduTBar);
this.groupBox4.Location = new System.Drawing.Point(13, 510);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(464, 81);
this.groupBox4.TabIndex = 18;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "色彩和饱和度";
//
// lblSaturationMinVal
//
this.lblSaturationMinVal.AutoSize = true;
this.lblSaturationMinVal.Location = new System.Drawing.Point(99, 53);
this.lblSaturationMinVal.Name = "lblSaturationMinVal";
this.lblSaturationMinVal.Size = new System.Drawing.Size(29, 12);
this.lblSaturationMinVal.TabIndex = 33;
this.lblSaturationMinVal.Text = "-1.0";
//
// baoheduTBox
//
this.baoheduTBox.Location = new System.Drawing.Point(389, 28);
this.baoheduTBox.Name = "baoheduTBox";
this.baoheduTBox.Size = new System.Drawing.Size(55, 21);
this.baoheduTBox.TabIndex = 35;
this.baoheduTBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.baoheduTBox_KeyPress);
//
// label13
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(18, 28);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(53, 12);
this.label13.TabIndex = 24;
this.label13.Text = "饱和度:";
//
// lblSaturationMaxVal
//
this.lblSaturationMaxVal.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lblSaturationMaxVal.AutoSize = true;
this.lblSaturationMaxVal.Location = new System.Drawing.Point(333, 53);
this.lblSaturationMaxVal.Name = "lblSaturationMaxVal";
this.lblSaturationMaxVal.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.lblSaturationMaxVal.Size = new System.Drawing.Size(23, 12);
this.lblSaturationMaxVal.TabIndex = 34;
this.lblSaturationMaxVal.Text = "1.0";
this.lblSaturationMaxVal.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// baoheduTBar
//
this.baoheduTBar.Location = new System.Drawing.Point(95, 28);
this.baoheduTBar.Maximum = 20;
this.baoheduTBar.Name = "baoheduTBar";
this.baoheduTBar.Size = new System.Drawing.Size(274, 45);
this.baoheduTBar.TabIndex = 32;
this.baoheduTBar.TickStyle = System.Windows.Forms.TickStyle.None;
this.baoheduTBar.Value = 10;
this.baoheduTBar.ValueChanged += new System.EventHandler(this.baoheduTBar_ValueChanged);
this.baoheduTBar.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.TBar_MouseWheel);
//
// AdjustCameraControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "AdjustCameraControl";
this.Size = new System.Drawing.Size(490, 605);
((System.ComponentModel.ISupportInitialize)(this.lightTBar)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.ExposureTBar)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trbGain)).EndInit();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.lansepictureBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.huangsepictureBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.lvsepictureBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.yanghongsepictureBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.hongsepictureBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.lanlvpictureBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.blueChannelTB)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.greenChannelTB)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.redChannelTB)).EndInit();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.baoheduTBar)).EndInit();
this.ResumeLayout(false);
}
private void TBar_MouseWheel(object sender, MouseEventArgs e)
{
((HandledMouseEventArgs)e).Handled = true;
}
private bool m_autoExposureComplete;
private int m_exposureTimes = 0;
private double m_exposureValue;
protected override void Dispose(bool disposing = true)
{
m_Timer.Stop();
base.Dispose(disposing);
}
///
/// 手动白平衡
///
///
///
private void button2_Click(object sender, EventArgs e)
{
m_cameraParamModel.parame.FMExposure = 0;
AutoWhiteBalance(false);
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).m_use = false;
((ImageCollect.CameraPreviewDialog)form).o_use = false;
}
}
///
/// 自动白平衡按钮点击
///
///
///
private void button3_Click(object sender, EventArgs e)
{
AutoWhiteBalance(true);
Thread.Sleep(1500);
UpdateColorTemperature();
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).m_use = false;
((ImageCollect.CameraPreviewDialog)form).o_use = false;
}
}
///
/// 自动白平衡一次
///
///
///
private void button1_Click(object sender, EventArgs e)
{
AutoWhiteBalance(true);
new Task(() =>
{
Thread.Sleep(1500);
m_cameraParamModel.parame.FMExposure = 0;
AutoWhiteBalance(false);
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).m_use = false;
((ImageCollect.CameraPreviewDialog)form).o_use = false;
}
}).Start();
}
///
/// 色温3200K
///
///
///
private void button4_Click(object sender, EventArgs e)
{
m_cameraParamModel.parame.FMExposure = 1;
m_camera.SetColorTemperatureByString("3200K");
AutoWhiteBalance(false);
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).m_use = false;
((ImageCollect.CameraPreviewDialog)form).o_use = false;
}
}
///
/// 色温5500K
///
///
///
private void button5_Click(object sender, EventArgs e)
{
m_cameraParamModel.parame.FMExposure = 2;
m_camera.SetColorTemperatureByString("5500K");
AutoWhiteBalance(false);
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).m_use = false;
((ImageCollect.CameraPreviewDialog)form).o_use = false;
}
}
private void UpdateColorTemperature()
{
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
uint cct = 0;
double redChannel = 0;
double greenChannel = 0;
double blueChannel = 0;
m_camera.GetColorTemperature(ref redChannel, ref greenChannel, ref blueChannel, ref cct);
m_cameraParamModel.parame.RedChannel = redChannel;
m_cameraParamModel.parame.GreenChannel = greenChannel;
m_cameraParamModel.parame.BlueChannel = blueChannel;
// 颜色值
this.redChannelTB.Value = (int)m_cameraParamModel.parame.RedChannel;
this.greenChannelTB.Value = (int)m_cameraParamModel.parame.GreenChannel;
this.blueChannelTB.Value = (int)m_cameraParamModel.parame.BlueChannel;
//string colorTemperatureString = m_camera.GetColorTemperatureString(cct);
this.redChannelTB.Enabled = false;
this.greenChannelTB.Enabled = false;
this.blueChannelTB.Enabled = false;
if (m_cameraParamModel.parame.WhiteBalance == 1)
{
button3.Enabled = false;
}
else
{
switch (m_cameraParamModel.parame.FMExposure)
{
case 0:
button2.Enabled = false;
this.redChannelTB.Enabled = true;
this.greenChannelTB.Enabled = true;
this.blueChannelTB.Enabled = true;
break;
case 1:
button4.Enabled = false;
break;
case 2:
button5.Enabled = false;
break;
}
}
xianshiColourCheckBox.Focus();
}
///
/// 是否自动白平衡 修改显示样式
///
///
private void AutoWhiteBalance(Boolean isWhiteBalance)
{
if (isWhiteBalance)
{
this.redChannelTB.Enabled = false;
this.greenChannelTB.Enabled = false;
this.blueChannelTB.Enabled = false;
m_cameraParamModel.parame.WhiteBalance = 1;
if (m_immediately)
{
// 自动白平衡
m_camera.SetWhiteBalanceMode(WhiteBalanceMode.AUTO);
}
}
else
{
m_cameraParamModel.parame.WhiteBalance = 0;
if (m_immediately)
{
// 手动白平衡
m_camera.SetWhiteBalanceMode(WhiteBalanceMode.MANUAL);
}
}
UpdateColorTemperature();
}
#region 曝光
double _log = 1.1;
int _min;
int _max;
private int GetExposureBarValue()
{
var value = ExposureTBar.Value;
if (ExposureTBar.Value == ExposureTBar.Minimum) return _min;
if (ExposureTBar.Value == ExposureTBar.Maximum) return _max;
return (int)Math.Pow(_log, value);
}
private void SetExposureBarValue(double value)
{
var ival = (int)Math.Log(Math.Max(_min, value), _log);
ExposureTBar.Value = Math.Min(ival, ExposureTBar.Maximum);
}
private void SetExposureBarRange(double min, double max)
{
_min = (int)min;
ExposureTBar.Minimum = (int)Math.Log(min, _log);
_max = (int)max;
ExposureTBar.Maximum = (int)Math.Log(max, _log); ;
}
public void OnTimerAutoExposure(object source, System.Timers.ElapsedEventArgs e)
{
if (m_autoExposureOnce)
{
m_autoExposureComplete = true;
m_autoExposureOnce = false;
ExposureTBar.Enabled = true;
ExposureBox.Enabled = true;
trbGain.Enabled = true;
txtGain.Enabled = true;
m_camera.SetExposureMode(ExposureMode.MANUAL);
m_Timer.Stop();
}
else if (!checkBoxAutoExposure.Checked)
{
return;
}
double us = m_camera.GetExposureTime() * 1000;
SetExposureBarValue(us);
DisplayExposureText((int)us);
}
///
/// 曝光百分比滑块滑动事件
///
///
///
private void Light_ValueChanged(object sender, System.EventArgs e)
{
m_camera.Light = lightTBar.Value;
m_cameraParamModel.parame.Light = lightTBar.Value;
LightBox.Text = lightTBar.Value + "";
}
///
/// 曝光时间滑块滑动事件
///
///
///
private void Exposure_ValueChanged(object sender, System.EventArgs e)
{
int exposureTimeUSec = GetExposureBarValue();
this.m_cameraParamModel.parame.LNExposure = exposureTimeUSec;
DisplayExposureText(exposureTimeUSec);
m_camera.SetExposureTime((ulong)(exposureTimeUSec));
}
private void checkBoxAutoExposure_CheckedChanged(object sender, EventArgs e)
{
int autoExposure = checkBoxAutoExposure.Checked ? 1 : 0;
m_cameraParamModel.parame.ATExposure = autoExposure;
if (autoExposure == 0)
{
Light_ValueChanged(null, null);
}
else
{
m_autoExposureOnce = false;
}
UpdateExposureUI(autoExposure);
}
private bool m_autoExposureOnce;
///
/// 一次自动曝光
///
///
///
private void btnAutoExposureOnce_Click(object sender, EventArgs e)
{
if (m_autoExposureComplete && checkBoxAutoExposure.Checked)
{
checkBoxAutoExposure.Checked = false;
}
else
{
if (checkBoxAutoExposure.Checked)
{
checkBoxAutoExposure.Checked = false;
}
m_autoExposureOnce = true;
UpdateExposureOnceUI();
}
}
private void UpdateExposureOnceUI()
{
m_autoExposureComplete = false;
ExposureTBar.Enabled = false;
ExposureBox.Enabled = false;
trbGain.Enabled = false;
txtGain.Enabled = false;
//lightTBar.Value = 64;
//Light_ValueChanged(null, null);
// 设置到相机
if (m_immediately)
{
// 自动曝光
m_camera.SetExposureMode(ExposureMode.AUTO);
m_Timer.Start();
}
}
///
/// 曝光时间内容输入后校验
///
///
///
private void baoGuangTBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Enter) && (e.KeyChar != (char)Keys.Back)) // 非数字键, 放弃该输入
{
e.Handled = true;
return;
}
if (e.KeyChar == (char)Keys.Enter)
{
try
{
double value = Convert.ToDouble(ExposureBox.Text);
switch (unitLabel.Text)
{
case "s":
value = value * 1000 * 1000;
break;
case "ms":
value = value * 1000;
break;
}
SetExposureBarValue(value);
Exposure_ValueChanged(null, null);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void DisplayExposureText(int exposureTimeUSec)
{
decimal txtVale = 0;
int sec = 0;
int msec = 0;
int usec = 0;
m_camera.UpdateExposureTime(ref sec, ref msec, ref usec, (UInt64)exposureTimeUSec);
if (sec > 0)
{
this.unitLabel.Text = "s";
txtVale += sec;
}
if (msec > 0)
{
if (txtVale > 0)
{
txtVale += ((decimal)msec / 1000);
this.unitLabel.Text = "s";
usec = 0; // 微秒舍掉不显示了
}
else
{
this.unitLabel.Text = "ms";
txtVale += msec;
}
}
if (usec > 0)
{
if (txtVale > 0)
{
txtVale += ((decimal)usec / 1000);
}
else
{
this.unitLabel.Text = "μs";
txtVale = usec;
}
}
this.ExposureBox.Text = txtVale.ToString();
}
#endregion
///
/// 饱和度滑块滑动
///
///
///
private void baoheduTBar_ValueChanged(object sender, System.EventArgs e)
{
this.m_cameraParamModel.parame.Saturation = this.baoheduTBar.Value;
//this.baoheduTBox.Text = ((this.baoheduTBar.Value - 10) / 10.0).ToString("0.0");
this.baoheduTBox.Text = this.baoheduTBar.Value.ToString();
// 设置到相机
if (m_immediately)
{
m_camera.SetSaturation(this.m_cameraParamModel.parame.Saturation); //usec
}
}
///
/// 显示颜色通道值
///
///
///
private void xianshiColourCheckBox_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
this.yanghongsepictureBox.Visible = cb.Checked;
this.yanghongsepictureBox.Visible = cb.Checked; ;
this.lansepictureBox.Visible = cb.Checked;
this.hongsepictureBox.Visible = cb.Checked;
this.lansepictureBox.Visible = cb.Checked;
this.huangsepictureBox.Visible = cb.Checked;
this.lanlvpictureBox.Visible = cb.Checked;
this.lvsepictureBox.Visible = cb.Checked;
this.m_cameraParamModel.parame.ShowColorPBoxFlag = cb.Checked ? 1 : 0;
}
private void baoGuangPertBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Enter) && (e.KeyChar != (char)Keys.Back)) // 非数字键, 放弃该输入
{
e.Handled = true;
return;
}
if (e.KeyChar == (char)Keys.Enter)
{
try
{
int value = Convert.ToInt32(LightBox.Text);
value = Math.Max(lightTBar.Minimum, value);
value = Math.Min(lightTBar.Maximum, value);
lightTBar.Value = value;
Light_ValueChanged(null, null);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void txtGain_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Enter) && (e.KeyChar != (char)Keys.Back)) // 非数字键, 放弃该输入
{
e.Handled = true;
return;
}
if (e.KeyChar == (char)Keys.Enter)
{
try
{
int trbGainVal = Convert.ToInt32(txtGain.Text);
if (trbGainVal < trbGain.Minimum)
{
trbGainVal = trbGain.Minimum;
}
if (trbGainVal > trbGain.Maximum)
{
trbGainVal = trbGain.Maximum;
}
trbGain.Value = trbGainVal;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void redChannelTB_ValueChanged(object sender, EventArgs e)
{
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).m_use = false;
((ImageCollect.CameraPreviewDialog)form).o_use = false;
}
m_cameraParamModel.parame.RedChannel = ((TrackBar)sender).Value;
// 设置到相机
if (m_immediately)
{
m_camera.SetRedGain(m_cameraParamModel.parame.RedChannel); //usec
}
}
private void greenChannelTB_Scroll(object sender, EventArgs e)
{
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).m_use = false;
((ImageCollect.CameraPreviewDialog)form).o_use = false;
}
m_cameraParamModel.parame.GreenChannel = ((TrackBar)sender).Value;
// 设置到相机
if (m_immediately)
{
m_camera.SetGreeGain(m_cameraParamModel.parame.GreenChannel); //usec
}
}
private void blueChannelTB_ValueChanged(object sender, EventArgs e)
{
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).m_use = false;
((ImageCollect.CameraPreviewDialog)form).o_use = false;
}
m_cameraParamModel.parame.BlueChannel = ((TrackBar)sender).Value;
// 设置到相机
if (m_immediately)
{
m_camera.SetBlueGain(m_cameraParamModel.parame.BlueChannel); //usec
}
}
private void trbGain_ValueChanged(object sender, EventArgs e)
{
txtGain.Text = trbGain.Value.ToString();
m_cameraParamModel.parame.GlobalGain = trbGain.Value;
m_camera.SetGlobalGain(m_cameraParamModel.parame.GlobalGain);
}
///
/// 白平衡区域选择
///
///
///
private void button7_Click(object sender, EventArgs e)
{
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).o_use = false;
((ImageCollect.CameraPreviewDialog)form).m_use = !((ImageCollect.CameraPreviewDialog)form).m_use;
}
}
///
/// 白平衡原图取色
///
///
///
private void button6_Click(object sender, EventArgs e)
{
Form form = Application.OpenForms["CameraPreviewDialog"];
if (form != null)
{
((ImageCollect.CameraPreviewDialog)form).m_use = false;
((ImageCollect.CameraPreviewDialog)form).o_use = !((ImageCollect.CameraPreviewDialog)form).o_use;
((ImageCollect.CameraPreviewDialog)form).m_startP = new System.Drawing.Point(-1, -1);
}
}
private void baoheduTBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Enter) && (e.KeyChar != (char)Keys.Back)) // 非数字键, 放弃该输入
{
e.Handled = true;
return;
}
if (e.KeyChar == (char)Keys.Enter)
{
try
{
int value = Convert.ToInt32(baoheduTBox.Text);
baoheduTBar.Value = value;
}
catch
{
baoheduTBox.Text = baoheduTBar.Value + "";
}
}
}
}
}