123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485 |
- 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;
- namespace PaintDotNet.Setting.LabelComponent
- {
- /// <summary>
- /// 相机设置,调节界面
- /// </summary>
- public class ShowCameraControl : UserControl
- {
- #region 控件
- /// <summary>
- /// 增益值下拉选
- /// </summary>
- string[] gainArray = new string[] { "高增益", "低增益"};
- /// <summary>
- /// 相机参数的Model
- /// </summary>
- private CameraParamModel m_cameraParamModel;
- private bool m_immediately;
- private TUCamera.TUCamera m_camera;
- public PictureBox pictureBox1;
- private CustomControl.SelectButton logButton;
- private CustomControl.SelectButton skipButton;
- private GroupBox groupBox5;
- private Button button2;
- private Button button3;
- private Button button4;
- private Button button5;
- private CheckBox xianshiColourCheckBox;
- private TrackBar redChannelTB;
- private Label label7;
- private TrackBar greenChannelTB;
- private Label label8;
- private Label label9;
- private TrackBar blueChannelTB;
- private Label label10;
- private Label label11;
- private Label label12;
- private PictureBox lanlvpictureBox;
- private PictureBox hongsepictureBox;
- private PictureBox yanghongsepictureBox;
- private PictureBox lvsepictureBox;
- private PictureBox huangsepictureBox;
- private PictureBox lansepictureBox;
- private GroupBox groupBox3;
- private TrackBar trbGain;
- private Label lblGainMax;
- private Label lblGainMin;
- private TextBox txtGain;
- private GroupBox groupBox2;
- private Label label6;
- private Label lblBaoGuangMinVal;
- private Label lblBaoGuangMaxVal;
- private Label label4;
- private Label label3;
- private TextBox baoGuangPertBox;
- private TextBox baoGuangTBox;
- private Label unitLabel;
- private Label unitPerLabel1;
- private CheckBox checkBoxAutoExposure;
- private GroupBox groupBox1;
- private Label label5;
- private TrackBar baoGuangPerTBar;
- private TrackBar baoGuangTBar;
- private TrackBar baoheduTBar;
- private Label lblSaturationMaxVal;
- private Label label13;
- private TextBox baoheduTBox;
- private Label lblSaturationMinVal;
- private GroupBox groupBox4;
- private System.Timers.Timer m_aeTimer;
- #endregion
- public ShowCameraControl(CameraParamModel model, bool immediately)
- {
- m_cameraParamModel = model;
- m_immediately = immediately;
- m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
- InitializeComponent();
- }
- public void ResetCameraParamModel(CameraParamModel model)
- {
- m_cameraParamModel = model;
- }
- int resolution_width = 2448;
- int resolution_height = 2048;
- TUCameraIFrameProcess m_process = null;
-
- //#17904
- private OpenCvSharp.Mat m_mat;
- /// <summary>
- /// 一个矩阵数组,用来接收直方图,记得全部初始化
- /// </summary>
- Mat[] oldHists = new Mat[] { new Mat(), new Mat(), new Mat() };
- /// <summary>
- /// 灰度图
- /// </summary>
- private bool isGray = true;
- /// <summary>
- /// BGR线条颜色
- /// </summary>
- private Scalar[] color = new Scalar[] { new Scalar(255, 0, 0, 255), new Scalar(0, 255, 0, 255), new Scalar(0, 0, 255, 255) };
- /// <summary>
- /// skip按钮
- /// 显示直方图时,忽略黑色的灰度或颜色值。
- /// 这使您可以为背景为黑色的图像实现有意义的直方图显示。
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void skipButton_Click(object sender, EventArgs e)
- {
- if (m_mat == null)
- {
- //MessageBox.Show("请打开图片");
- return;
- }
- //设置按钮的选中/非选择的状态
- skipButton.BtnSelect = !skipButton.BtnSelect;
- //this.AppWorkspace.ActiveDocumentWorkspace.HistogramSkipEnabled = skipButton.BtnSelect;
- updateHistImg(null);
- }
- /// <summary>
- /// log按钮
- /// 以对数比例显示直方图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void logButton_Click(object sender, EventArgs e)
- {
- if (m_mat == null)
- {
- //MessageBox.Show("请打开图片");
- return;
- }
- //设置按钮的选中/非选择的状态
- logButton.BtnSelect = !logButton.BtnSelect;
- //this.AppWorkspace.ActiveDocumentWorkspace.HistogramLogEnabled = logButton.BtnSelect;
- updateHistImg(null);
- }
- /// <summary>
- /// 绘制
- /// </summary>
- /// <param name="pBuf"></param>
- /// <param name="obj"></param>
- public void CallbackDraw(byte[] pBuf, object obj, int channel)
- {
- lock (obj)
- {
- //m_isWaiting = false;
- Console.WriteLine("接收全图buf");
- m_camera.m_drawAllHandler -= new DrawAllHandler(CallbackDraw);
- OpenCvSharp.Mat mat;
- if (channel == 1)
- {
- mat = new OpenCvSharp.Mat(resolution_height, resolution_width/*m_resolution.Height, m_resolution.Width*/, OpenCvSharp.MatType.CV_8UC1, pBuf);
- }
- else
- {
- mat = new OpenCvSharp.Mat(resolution_height, resolution_width/*m_resolution.Height, m_resolution.Width*/, OpenCvSharp.MatType.CV_8UC3, pBuf);
- }
- OpenCvSharp.Cv2.Flip(mat, mat, 0);
- if (m_mat != null)
- {
- m_mat.Dispose();
- }
- m_mat = mat.Clone();
- //this.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
- stopDrawing();
- if (mat != null)
- {
- mat.Dispose();
- }
- this.showHistImg(m_mat);
- }
- }
- private void showHistImg(Mat BoxMat)
- {
- Mat[] mats = Cv2.Split(BoxMat);//一张图片,将panda拆分成3个图片装进mat
- if (mats.Count() == 1)
- {
- isGray = true;
- }
- else
- {
- isGray = false;
- }
- if (isGray)
- {
- 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);//对被拆分的图片单独进行计算
- updateHistImgGray(oldHists);
- 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);//对被拆分的图片单独进行计算
- for (int h = 0; h < oldHists[0].Rows; h++)
- {
- for (int j = oldHists.Length - 1; j >= 1; j--)
- {
- if (oldHists[j].At<float>(h) != oldHists[0].At<float>(h))
- {
- isGray = false;
- break;
- }
- }
- if (!isGray)
- break;
- }
- updateHistImg(oldHists);
- }
- /// <summary>
- /// 绘制直方图-单通道
- /// </summary>
- /// <param name="hist"></param>
- /// <returns></returns>
- private unsafe void updateHistImgGray(Mat[] hists)
- {
- if (m_mat == null)
- {
- return;
- }
- Mat[] mats = Cv2.Split(m_mat);//一张图片,将panda拆分成3个图片装进mat
- //if (mats.Count() == 1)
- //{
- // isGray = true;
- //}
- //else
- //{
- // isGray = false;
- //}
- Mat[] mats0 = new Mat[] { mats[0] };//panda的第一个通道,也就是B
- //Mat[] mats1 = new Mat[] { mats[1] };//panda的第二个通道,也就是G
- //Mat[] mats2 = new Mat[] { mats[2] };//panda的第三个通道,也就是R
- if (hists == null)
- {
- hists = new Mat[] { new Mat()/*, new Mat(), new Mat()*/ };//一个矩阵数组,用来接收直方图,记得全部初始化
- 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, hists[0], 1, histsize, range);//对被拆分的图片单独进行计算
- //Cv2.CalcHist(mats1, channels1, mask, hists[1], 1, histsize, range);//对被拆分的图片单独进行计算
- //Cv2.CalcHist(mats2, channels2, mask, hists[2], 1, histsize, range);//对被拆分的图片单独进行计算
- if (logButton.BtnSelect)
- {
- //取对数
- for (int j = 0; j < hists.Length; j++)
- {
- List<float> ProbPixel = new List<float>();
- for (int i = 0; i < hists[j].Rows; i++)
- {
- if (((float*)hists[j].Ptr(0))[i] == 0)
- {
- ((float*)hists[j].Ptr(0))[i] = ((float*)hists[j].Ptr(0))[i];
- ProbPixel.Add(0);
- }
- else
- {
- ((float*)hists[j].Ptr(0))[i] = (float)Math.Log10(((float*)hists[j].Ptr(0))[i]/* + 9*/);
- ProbPixel.Add(1);
- }
- }
- double max1jVal = 0;
- double min1jVal = 0;
- //找到直方图中的最大值和最小值
- Cv2.MinMaxLoc(hists[j], out min1jVal, out max1jVal);
- if (min1jVal >= max1jVal)
- {
- continue;
- }
- //归一化到0~255,并根据AxioVision添加偏置值
- for (int i = 0; i < hists[j].Rows; i++)
- {
- ((float*)hists[j].Ptr(0))[i] = (float)((((float*)hists[j].Ptr(0))[i] - 0) * 255.0 / (max1jVal - 0)) + (float)(min1jVal > 0 ? (ProbPixel[i] * min1jVal * 255.0 / max1jVal) : ProbPixel[i] * 5);
- }
- }
- }
- if (skipButton.BtnSelect)
- {
- //去掉黑色部分 和 白色部分
- for (int j = 0; j < hists.Length; j++)
- {
- ((float*)hists[j].Ptr(0))[0] = 0;
- ((float*)hists[j].Ptr(0))[255] = 0;
- }
- }
- }
- //double max2Val = 0;
- //double max1Val = 0;
- double max0Val = 0;
- double minVal = 0;
- //为了更好显示直方图细节,使用4倍尺寸绘制直方图
- int histSize = hists[0].Rows * 4;
- Mat histImg = new Mat(histSize, histSize, MatType.CV_8UC3, new Scalar(255, 255, 255));
- //找到直方图中的最大值和最小值
- //Cv2.MinMaxLoc(hists[2], out minVal, out max2Val);
- //Cv2.MinMaxLoc(hists[1], out minVal, out max1Val);
- Cv2.MinMaxLoc(hists[0], out minVal, out max0Val);
- double maxVal = max0Val;// Math.Max(max2Val, Math.Max(max0Val, max1Val));
- if (maxVal < 1)
- return;
- // 设置最大峰值为图像高度的90%
- double hpt = 0.9 * histSize;
- //灰度图的显示直方图较为简单,显示一个通道即可
- if (isGray)
- {
- Mat hist = hists[0];
- int lastY2 = histSize - 1;
- for (int h = 0; h < hists[0].Rows; h++)
- {
- int intensity = (int)(hist.At<float>(h) * hpt / maxVal);
- int lastY1 = lastY2;
- lastY2 = histSize - intensity - 1 - (hist.At<float>(h) > 0 ? 4 : 0);
- if (lastY2 < lastY1)
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lastY1), new OpenCvSharp.Point(h * 4, Math.Min(lastY2, lastY1 - 2)), new Scalar(0, 0, 0, 255), 2, LineTypes.Link4);
- }
- else
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lastY1), new OpenCvSharp.Point(h * 4, Math.Max(lastY2, lastY1 + 2)), new Scalar(0, 0, 0, 255), 2, LineTypes.Link4);
- }
- }
- }
- //彩度图显示BGR三个通道的直方图
- else
- {
- int lineWidth = 2;
- for (int j = hists.Length - 1; j >= 0; j--)
- {
- Mat hist = hists[j];
- int lastY2 = histSize - 1;
- for (int h = 0; h < hists[0].Rows; h++)
- {
- int intensity = (int)(hist.At<float>(h) * hpt / maxVal);
- int lastY1 = lastY2;
- lastY2 = histSize - intensity - 1 - (hist.At<float>(h) > 0 ? 4 : 0);
- if (h > 0)
- {
- //显示0.5位置的直方图,这样与AxioVision效果更加近似
- int lasty12 = (lastY1 + lastY2) / 2;
- if (lasty12 < lastY1)
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4 - 2, lastY1), new OpenCvSharp.Point(h * 4 - 2, Math.Min(lasty12, lastY1 - 2)), color[j], lineWidth, LineTypes.Link4);
- }
- else
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4 - 2, lastY1), new OpenCvSharp.Point(h * 4 - 2, Math.Max(lasty12, lastY1 + 2)), color[j], lineWidth, LineTypes.Link4/*AntiAlias*/);
- }
- if (lastY2 < lasty12)
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lasty12), new OpenCvSharp.Point(h * 4, Math.Min(lastY2, lasty12 - 2)), color[j], lineWidth, LineTypes.Link4);
- }
- else
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lasty12), new OpenCvSharp.Point(h * 4, Math.Max(lastY2, lasty12 + 2)), color[j], lineWidth, LineTypes.Link4/*AntiAlias*/);
- }
- }
- else
- {
- //灰度值为0的线的绘制
- if (lastY2 < lastY1)
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lastY1), new OpenCvSharp.Point(h * 4, Math.Min(lastY2, lastY1 - 2)), color[j], lineWidth, LineTypes.Link4);
- }
- else
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lastY1), new OpenCvSharp.Point(h * 4, Math.Max(lastY2, lastY1 + 2)), color[j], lineWidth, LineTypes.Link4/*AntiAlias*/);
- }
- }
- }
- }
- }
- this.pictureBox1.BackgroundImage/*Image*/ = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(histImg);
- }
- /// <summary>
- /// 绘制直方图
- /// </summary>
- /// <param name="hist"></param>
- /// <returns></returns>
- private unsafe void updateHistImg(Mat[] hists)
- {
- if (m_mat == null)
- {
- return;
- }
- Mat[] mats = Cv2.Split(m_mat);//一张图片,将panda拆分成3个图片装进mat
- if (mats.Count() == 1)
- {
- isGray = true;
- }
- else
- {
- isGray = false;
- }
- if (isGray)
- {
- updateHistImgGray(hists);
- 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
- if (hists == null)
- {
- hists = new Mat[] { new Mat(), new Mat(), new Mat() };//一个矩阵数组,用来接收直方图,记得全部初始化
- 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, hists[0], 1, histsize, range);//对被拆分的图片单独进行计算
- Cv2.CalcHist(mats1, channels1, mask, hists[1], 1, histsize, range);//对被拆分的图片单独进行计算
- Cv2.CalcHist(mats2, channels2, mask, hists[2], 1, histsize, range);//对被拆分的图片单独进行计算
- if (logButton.BtnSelect)
- {
- //取对数
- for (int j = 0; j < hists.Length; j++)
- {
- List<float> ProbPixel = new List<float>();
- for (int i = 0; i < hists[j].Rows; i++)
- {
- if (((float*)hists[j].Ptr(0))[i] == 0)
- {
- ((float*)hists[j].Ptr(0))[i] = ((float*)hists[j].Ptr(0))[i];
- ProbPixel.Add(0);
- }
- else
- {
- ((float*)hists[j].Ptr(0))[i] = (float)Math.Log10(((float*)hists[j].Ptr(0))[i]/* + 9*/);
- ProbPixel.Add(1);
- }
- }
- double max1jVal = 0;
- double min1jVal = 0;
- //找到直方图中的最大值和最小值
- Cv2.MinMaxLoc(hists[j], out min1jVal, out max1jVal);
- if (min1jVal >= max1jVal)
- {
- continue;
- }
- //归一化到0~255,并根据AxioVision添加偏置值
- for (int i = 0; i < hists[j].Rows; i++)
- {
- ((float*)hists[j].Ptr(0))[i] = (float)((((float*)hists[j].Ptr(0))[i] - 0) * 255.0 / (max1jVal - 0)) + (float)(min1jVal > 0 ? (ProbPixel[i] * min1jVal * 255.0 / max1jVal) : ProbPixel[i] * 5);
- }
- }
- }
- if (skipButton.BtnSelect)
- {
- //去掉黑色部分 和 白色部分
- for (int j = 0; j < hists.Length; j++)
- {
- ((float*)hists[j].Ptr(0))[0] = 0;
- ((float*)hists[j].Ptr(0))[255] = 0;
- }
- }
- }
- double max2Val = 0;
- double max1Val = 0;
- double max0Val = 0;
- double minVal = 0;
- //为了更好显示直方图细节,使用4倍尺寸绘制直方图
- int histSize = hists[0].Rows * 4;
- Mat histImg = new Mat(histSize, histSize, MatType.CV_8UC3, new Scalar(255, 255, 255));
- //找到直方图中的最大值和最小值
- Cv2.MinMaxLoc(hists[2], out minVal, out max2Val);
- Cv2.MinMaxLoc(hists[1], out minVal, out max1Val);
- Cv2.MinMaxLoc(hists[0], out minVal, out max0Val);
- double maxVal = Math.Max(max2Val, Math.Max(max0Val, max1Val));
- if (maxVal < 1)
- return;
- // 设置最大峰值为图像高度的90%
- double hpt = 0.9 * histSize;
- //灰度图的显示直方图较为简单,显示一个通道即可
- if (isGray)
- {
- Mat hist = hists[0];
- int lastY2 = histSize - 1;
- for (int h = 0; h < hists[0].Rows; h++)
- {
- int intensity = (int)(hist.At<float>(h) * hpt / maxVal);
- int lastY1 = lastY2;
- lastY2 = histSize - intensity - 1 - (hist.At<float>(h) > 0 ? 4 : 0);
- if (lastY2 < lastY1)
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lastY1), new OpenCvSharp.Point(h * 4, Math.Min(lastY2, lastY1 - 2)), new Scalar(0, 0, 0, 255), 2, LineTypes.Link4);
- }
- else
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lastY1), new OpenCvSharp.Point(h * 4, Math.Max(lastY2, lastY1 + 2)), new Scalar(0, 0, 0, 255), 2, LineTypes.Link4);
- }
- }
- }
- //彩度图显示BGR三个通道的直方图
- else
- {
- int lineWidth = 2;
- for (int j = hists.Length - 1; j >= 0; j--)
- {
- Mat hist = hists[j];
- int lastY2 = histSize - 1;
- for (int h = 0; h < hists[0].Rows; h++)
- {
- int intensity = (int)(hist.At<float>(h) * hpt / maxVal);
- int lastY1 = lastY2;
- lastY2 = histSize - intensity - 1 - (hist.At<float>(h) > 0 ? 4 : 0);
- if (h > 0)
- {
- //显示0.5位置的直方图,这样与AxioVision效果更加近似
- int lasty12 = (lastY1 + lastY2) / 2;
- if (lasty12 < lastY1)
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4 - 2, lastY1), new OpenCvSharp.Point(h * 4 - 2, Math.Min(lasty12, lastY1 - 2)), color[j], lineWidth, LineTypes.Link4);
- }
- else
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4 - 2, lastY1), new OpenCvSharp.Point(h * 4 - 2, Math.Max(lasty12, lastY1 + 2)), color[j], lineWidth, LineTypes.Link4/*AntiAlias*/);
- }
- if (lastY2 < lasty12)
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lasty12), new OpenCvSharp.Point(h * 4, Math.Min(lastY2, lasty12 - 2)), color[j], lineWidth, LineTypes.Link4);
- }
- else
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lasty12), new OpenCvSharp.Point(h * 4, Math.Max(lastY2, lasty12 + 2)), color[j], lineWidth, LineTypes.Link4/*AntiAlias*/);
- }
- }
- else
- {
- //灰度值为0的线的绘制
- if (lastY2 < lastY1)
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lastY1), new OpenCvSharp.Point(h * 4, Math.Min(lastY2, lastY1 - 2)), color[j], lineWidth, LineTypes.Link4);
- }
- else
- {
- Cv2.Line(histImg, new OpenCvSharp.Point(h * 4, lastY1), new OpenCvSharp.Point(h * 4, Math.Max(lastY2, lastY1 + 2)), color[j], lineWidth, LineTypes.Link4/*AntiAlias*/);
- }
- }
- }
- }
- }
- this.pictureBox1.BackgroundImage/*Image*/ = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(histImg);
- }
- private void stopDrawing()
- {
- //创建一个委托,用于封装一个方法,在这里是封装了 控制更新控件 的方法
- Action invokeAction = new Action(stopDrawing);
- //判断操作控件的线程是否创建控件的线程
- //调用方调用方位于创建控件所在的线程以外的线程中,如果在其他线程则对控件进行方法调用时必须调用 Invoke 方法
- if (this.InvokeRequired)
- {
- //与调用线程不同的线程上创建(说明您必须通过 Invoke 方法对控件进行调用)
- this.Invoke(invokeAction);
- }
- else
- {
- m_camera.StopDrawing(m_process);
- m_camera.StopWaitForFrame();
- ////窗体线程,即主线程
- //shuaxinButton.Enabled = true;
- }
- }
- 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)
- {
-
- }
- private void InitializeComponent()
- {
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- this.logButton = new PaintDotNet.CustomControl.SelectButton();
- this.skipButton = new PaintDotNet.CustomControl.SelectButton();
- this.groupBox5 = new System.Windows.Forms.GroupBox();
- this.button2 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.button4 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.xianshiColourCheckBox = new System.Windows.Forms.CheckBox();
- this.redChannelTB = new System.Windows.Forms.TrackBar();
- this.label7 = new System.Windows.Forms.Label();
- this.greenChannelTB = new System.Windows.Forms.TrackBar();
- this.label8 = new System.Windows.Forms.Label();
- this.label9 = new System.Windows.Forms.Label();
- this.blueChannelTB = new System.Windows.Forms.TrackBar();
- this.label10 = new System.Windows.Forms.Label();
- this.label11 = new System.Windows.Forms.Label();
- this.label12 = new System.Windows.Forms.Label();
- this.lanlvpictureBox = new System.Windows.Forms.PictureBox();
- this.hongsepictureBox = new System.Windows.Forms.PictureBox();
- this.yanghongsepictureBox = new System.Windows.Forms.PictureBox();
- this.lvsepictureBox = new System.Windows.Forms.PictureBox();
- this.huangsepictureBox = new System.Windows.Forms.PictureBox();
- this.lansepictureBox = new System.Windows.Forms.PictureBox();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.trbGain = new System.Windows.Forms.TrackBar();
- this.lblGainMax = new System.Windows.Forms.Label();
- this.lblGainMin = new System.Windows.Forms.Label();
- this.txtGain = new System.Windows.Forms.TextBox();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.label6 = new System.Windows.Forms.Label();
- this.lblBaoGuangMinVal = new System.Windows.Forms.Label();
- this.lblBaoGuangMaxVal = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.baoGuangPertBox = new System.Windows.Forms.TextBox();
- this.baoGuangTBox = new System.Windows.Forms.TextBox();
- this.unitLabel = new System.Windows.Forms.Label();
- this.unitPerLabel1 = new System.Windows.Forms.Label();
- this.checkBoxAutoExposure = new System.Windows.Forms.CheckBox();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.baoGuangTBar = new System.Windows.Forms.TrackBar();
- this.baoGuangPerTBar = new System.Windows.Forms.TrackBar();
- this.label5 = new System.Windows.Forms.Label();
- this.baoheduTBar = new System.Windows.Forms.TrackBar();
- this.lblSaturationMaxVal = new System.Windows.Forms.Label();
- this.label13 = new System.Windows.Forms.Label();
- this.baoheduTBox = new System.Windows.Forms.TextBox();
- this.lblSaturationMinVal = new System.Windows.Forms.Label();
- this.groupBox4 = new System.Windows.Forms.GroupBox();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
- this.groupBox5.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.redChannelTB)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.greenChannelTB)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.blueChannelTB)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.lanlvpictureBox)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.hongsepictureBox)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.yanghongsepictureBox)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.lvsepictureBox)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.huangsepictureBox)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.lansepictureBox)).BeginInit();
- this.groupBox3.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trbGain)).BeginInit();
- this.groupBox2.SuspendLayout();
- this.groupBox1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.baoGuangTBar)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.baoGuangPerTBar)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.baoheduTBar)).BeginInit();
- this.groupBox4.SuspendLayout();
- this.SuspendLayout();
- //
- // pictureBox1
- //
- this.pictureBox1.BackColor = System.Drawing.Color.White;
- this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.pictureBox1.Location = new System.Drawing.Point(9, 20);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(348, 168);
- this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
- this.pictureBox1.TabIndex = 0;
- this.pictureBox1.TabStop = false;
- //
- // logButton
- //
- this.logButton.BackColor = System.Drawing.SystemColors.ControlDark;
- this.logButton.BtnSelect = false;
- this.logButton.BtnText = "log";
- this.logButton.Location = new System.Drawing.Point(363, 63);
- this.logButton.Name = "logButton";
- this.logButton.Size = new System.Drawing.Size(75, 23);
- this.logButton.TabIndex = 31;
- this.logButton.Click += new System.EventHandler(this.logButton_Click);
- //
- // skipButton
- //
- this.skipButton.BackColor = System.Drawing.SystemColors.ControlDark;
- this.skipButton.BtnSelect = false;
- this.skipButton.BtnText = "skip";
- this.skipButton.Location = new System.Drawing.Point(363, 110);
- this.skipButton.Name = "skipButton";
- this.skipButton.Size = new System.Drawing.Size(75, 23);
- this.skipButton.TabIndex = 32;
- this.skipButton.Click += new System.EventHandler(this.skipButton_Click);
- //
- // groupBox5
- //
- this.groupBox5.Controls.Add(this.skipButton);
- this.groupBox5.Controls.Add(this.logButton);
- this.groupBox5.Controls.Add(this.pictureBox1);
- this.groupBox5.Location = new System.Drawing.Point(13, 586);
- this.groupBox5.Name = "groupBox5";
- this.groupBox5.Size = new System.Drawing.Size(464, 194);
- this.groupBox5.TabIndex = 19;
- this.groupBox5.TabStop = false;
- this.groupBox5.Text = "直方图";
- //
- // 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);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(134, 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);
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(248, 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);
- //
- // 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);
- //
- // 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, 67);
- 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);
- //
- // redChannelTB
- //
- this.redChannelTB.Location = new System.Drawing.Point(104, 96);
- 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);
- //
- // label7
- //
- this.label7.AutoSize = true;
- this.label7.Location = new System.Drawing.Point(58, 96);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(41, 12);
- this.label7.TabIndex = 23;
- this.label7.Text = "蓝绿色";
- //
- // greenChannelTB
- //
- this.greenChannelTB.Location = new System.Drawing.Point(104, 125);
- 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);
- //
- // label8
- //
- this.label8.AutoSize = true;
- this.label8.Location = new System.Drawing.Point(58, 125);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(41, 12);
- this.label8.TabIndex = 25;
- this.label8.Text = "洋红色";
- //
- // label9
- //
- this.label9.AutoSize = true;
- this.label9.Location = new System.Drawing.Point(58, 155);
- this.label9.Name = "label9";
- this.label9.Size = new System.Drawing.Size(29, 12);
- this.label9.TabIndex = 26;
- this.label9.Text = "黄色";
- //
- // blueChannelTB
- //
- this.blueChannelTB.Location = new System.Drawing.Point(104, 155);
- 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);
- //
- // label10
- //
- this.label10.AutoSize = true;
- this.label10.Location = new System.Drawing.Point(368, 96);
- this.label10.Name = "label10";
- this.label10.Size = new System.Drawing.Size(29, 12);
- this.label10.TabIndex = 28;
- this.label10.Text = "红色";
- //
- // label11
- //
- this.label11.AutoSize = true;
- this.label11.Location = new System.Drawing.Point(368, 125);
- this.label11.Name = "label11";
- this.label11.Size = new System.Drawing.Size(29, 12);
- this.label11.TabIndex = 29;
- this.label11.Text = "绿色";
- //
- // label12
- //
- this.label12.AutoSize = true;
- this.label12.Location = new System.Drawing.Point(368, 155);
- this.label12.Name = "label12";
- this.label12.Size = new System.Drawing.Size(29, 12);
- this.label12.TabIndex = 30;
- this.label12.Text = "蓝色";
- //
- // 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, 96);
- 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;
- //
- // hongsepictureBox
- //
- this.hongsepictureBox.BackColor = System.Drawing.Color.Red;
- this.hongsepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.hongsepictureBox.Location = new System.Drawing.Point(412, 96);
- 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;
- //
- // yanghongsepictureBox
- //
- this.yanghongsepictureBox.BackColor = System.Drawing.Color.Fuchsia;
- this.yanghongsepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.yanghongsepictureBox.Location = new System.Drawing.Point(33, 125);
- 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;
- //
- // lvsepictureBox
- //
- this.lvsepictureBox.BackColor = System.Drawing.Color.Lime;
- this.lvsepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.lvsepictureBox.Location = new System.Drawing.Point(412, 125);
- 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;
- //
- // huangsepictureBox
- //
- this.huangsepictureBox.BackColor = System.Drawing.Color.Yellow;
- this.huangsepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.huangsepictureBox.Location = new System.Drawing.Point(33, 155);
- 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;
- //
- // lansepictureBox
- //
- this.lansepictureBox.BackColor = System.Drawing.Color.Blue;
- this.lansepictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.lansepictureBox.Location = new System.Drawing.Point(412, 155);
- 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;
- //
- // groupBox3
- //
- 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, 191);
- this.groupBox3.TabIndex = 17;
- this.groupBox3.TabStop = false;
- this.groupBox3.Text = "白平衡";
- //
- // 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.ValueChanged += new System.EventHandler(this.trbGain_ValueChanged);
- //
- // 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";
- //
- // 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";
- //
- // 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);
- //
- // 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 = "增益值调整";
- //
- // 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(71, 12);
- this.label6.TabIndex = 15;
- this.label6.Text = "曝光百分比:";
- //
- // 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";
- //
- // 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";
- //
- // 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(17, 12);
- this.label4.TabIndex = 21;
- this.label4.Text = "5%";
- //
- // 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(29, 12);
- this.label3.TabIndex = 22;
- this.label3.Text = "200%";
- //
- // baoGuangPertBox
- //
- this.baoGuangPertBox.Location = new System.Drawing.Point(369, 66);
- this.baoGuangPertBox.Name = "baoGuangPertBox";
- this.baoGuangPertBox.Size = new System.Drawing.Size(55, 21);
- this.baoGuangPertBox.TabIndex = 30;
- this.baoGuangPertBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.baoGuangPertBox_KeyPress);
- //
- // baoGuangTBox
- //
- this.baoGuangTBox.Location = new System.Drawing.Point(370, 31);
- this.baoGuangTBox.Name = "baoGuangTBox";
- this.baoGuangTBox.Size = new System.Drawing.Size(55, 21);
- this.baoGuangTBox.TabIndex = 31;
- this.baoGuangTBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.baoGuangTBox_KeyPress);
- //
- // unitLabel
- //
- this.unitLabel.AutoSize = true;
- this.unitLabel.Location = new System.Drawing.Point(431, 34);
- this.unitLabel.Name = "unitLabel";
- this.unitLabel.Size = new System.Drawing.Size(17, 12);
- this.unitLabel.TabIndex = 32;
- this.unitLabel.Text = "us";
- //
- // unitPerLabel1
- //
- this.unitPerLabel1.AutoSize = true;
- this.unitPerLabel1.Location = new System.Drawing.Point(431, 69);
- this.unitPerLabel1.Name = "unitPerLabel1";
- this.unitPerLabel1.Size = new System.Drawing.Size(11, 12);
- this.unitPerLabel1.TabIndex = 33;
- this.unitPerLabel1.Text = "%";
- //
- // 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.CheckedChanged += new System.EventHandler(this.checkBoxAutoExposure_CheckedChanged);
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.checkBoxAutoExposure);
- this.groupBox1.Controls.Add(this.unitPerLabel1);
- this.groupBox1.Controls.Add(this.unitLabel);
- this.groupBox1.Controls.Add(this.baoGuangTBox);
- this.groupBox1.Controls.Add(this.baoGuangPertBox);
- 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.baoGuangPerTBar);
- this.groupBox1.Controls.Add(this.baoGuangTBar);
- 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 = "曝光时间";
- //
- // baoGuangTBar
- //
- this.baoGuangTBar.Location = new System.Drawing.Point(89, 31);
- this.baoGuangTBar.Maximum = 2998;
- this.baoGuangTBar.Minimum = 250;
- this.baoGuangTBar.Name = "baoGuangTBar";
- this.baoGuangTBar.Size = new System.Drawing.Size(274, 45);
- this.baoGuangTBar.TabIndex = 14;
- this.baoGuangTBar.TickStyle = System.Windows.Forms.TickStyle.None;
- this.baoGuangTBar.Value = 250;
- this.baoGuangTBar.ValueChanged += new System.EventHandler(this.baoguangTrackBar_ValueChanged);
- //
- // baoGuangPerTBar
- //
- this.baoGuangPerTBar.Location = new System.Drawing.Point(89, 66);
- this.baoGuangPerTBar.Maximum = 200;
- this.baoGuangPerTBar.Minimum = 5;
- this.baoGuangPerTBar.Name = "baoGuangPerTBar";
- this.baoGuangPerTBar.Size = new System.Drawing.Size(274, 45);
- this.baoGuangPerTBar.TabIndex = 13;
- this.baoGuangPerTBar.TickStyle = System.Windows.Forms.TickStyle.None;
- this.baoGuangPerTBar.Value = 100;
- this.baoGuangPerTBar.ValueChanged += new System.EventHandler(this.baoguangPerTrackBar_ValueChanged);
- //
- // 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(65, 12);
- this.label5.TabIndex = 12;
- this.label5.Text = "曝光时间:";
- //
- // 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);
- //
- // 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;
- //
- // 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 = "饱和度:";
- //
- // 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;
- //
- // 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";
- //
- // 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, 490);
- this.groupBox4.Name = "groupBox4";
- this.groupBox4.Size = new System.Drawing.Size(464, 81);
- this.groupBox4.TabIndex = 18;
- this.groupBox4.TabStop = false;
- this.groupBox4.Text = "色彩和饱和度";
- //
- // ShowCameraControl
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.Controls.Add(this.groupBox5);
- this.Controls.Add(this.groupBox4);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.Name = "ShowCameraControl";
- this.Size = new System.Drawing.Size(490, 801);
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
- this.groupBox5.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.redChannelTB)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.greenChannelTB)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.blueChannelTB)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.lanlvpictureBox)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.hongsepictureBox)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.yanghongsepictureBox)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.lvsepictureBox)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.huangsepictureBox)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.lansepictureBox)).EndInit();
- this.groupBox3.ResumeLayout(false);
- this.groupBox3.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trbGain)).EndInit();
- this.groupBox2.ResumeLayout(false);
- this.groupBox2.PerformLayout();
- this.groupBox1.ResumeLayout(false);
- this.groupBox1.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.baoGuangTBar)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.baoGuangPerTBar)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.baoheduTBar)).EndInit();
- this.groupBox4.ResumeLayout(false);
- this.groupBox4.PerformLayout();
- this.ResumeLayout(false);
- }
- public void OnTimerAutoExposure(object source, System.Timers.ElapsedEventArgs e)
- {
- double paramValue = m_camera.GetExposureTime() ;
- int expValue = (int)(paramValue * 1000);
- if (expValue < 137)
- {
- expValue = 130;
- }
- if (expValue > 15000000)
- {
- expValue = 15000000;
- }
- decimal txtVale = 0;
- int sec = 0;
- int msec = 0;
- int usec = 0;
- m_camera.UpdateExposureTime(ref sec, ref msec, ref usec, (UInt64)(paramValue * 1000));
-
- //UpdateExposureTime((UInt64)paramValue * 1000);
- }
- /// <summary>
- /// 手动白平衡
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.FMExposure = 0;
- AutoWhiteBalance(false);
- }
- /// <summary>
- /// 自动白平衡按钮点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- AutoWhiteBalance(true);
- }
- /// <summary>
- /// 色温3200K
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.FMExposure = 1;
- m_camera.SetColorTemperatureByString("3200K");
- AutoWhiteBalance(false);
- }
- /// <summary>
- /// 色温5500K
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.FMExposure = 2;
- m_camera.SetColorTemperatureByString("5500K");
- AutoWhiteBalance(false);
- }
- private void UpdateColorTemperature()
- {
-
- }
- /// <summary>
- /// 是否自动白平衡 修改显示样式
- /// </summary>
- /// <param name="s"></param>
- private void AutoWhiteBalance(Boolean isWhiteBalance)
- {
- if (isWhiteBalance)
- {
- 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();
- }
- private void xianshiColourCheckBox_CheckedChanged(object sender, EventArgs e)
- {
- }
- private void redChannelTB_ValueChanged(object sender, EventArgs e)
- {
- }
- private void greenChannelTB_Scroll(object sender, EventArgs e)
- {
- }
- private void blueChannelTB_ValueChanged(object sender, EventArgs e)
- {
- }
- private void trbGain_ValueChanged(object sender, EventArgs e)
- {
- }
- private void txtGain_KeyPress(object sender, KeyPressEventArgs e)
- {
- }
- private void baoGuangPertBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- }
- private void baoGuangTBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- }
- private void checkBoxAutoExposure_CheckedChanged(object sender, EventArgs e)
- {
- }
- private void baoguangTrackBar_ValueChanged(object sender, EventArgs e)
- {
- }
- private void baoguangPerTrackBar_ValueChanged(object sender, EventArgs e)
- {
- }
- private void baoheduTBar_ValueChanged(object sender, EventArgs e)
- {
- }
- }
- }
|