12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163 |
- using Resources;
- using SmartCoalApplication.Adjust;
- using SmartCoalApplication.Base;
- using SmartCoalApplication.Base.CommTool;
- using SmartCoalApplication.Core;
- using SmartCoalApplication.Core.CustomControl;
- using SmartCoalApplication.Core.Param;
- using SmartCoalApplication.Data.Action;
- using SmartCoalApplication.ParameterSet;
- using SmartCoalApplication.Resources;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using static SmartCoalApplication.ParameterSet.ImageMenu;
- namespace SmartCoalApplication.Processing
- {
- /// <summary>
- /// 图像处理窗口
- /// </summary>
- internal class BshTransferAdjustDialog : Form
- {
- /// <summary>
- /// 步长 初始值1,依次增加
- /// </summary>
- string stepLength = "00" + Program.instance.step_length;
- /// <summary>
- /// 主控件
- /// </summary>
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 当前处理的程序
- /// </summary>
- private ParamObject action;
- /// <summary>
- /// 如果是脚本执行,将参数带入
- /// </summary>
- private Boolean initScriptValues = false;
- // <summary>
- /// 如果有参数保存,将参数带入
- /// </summary>
- private Boolean initPamasValues = false;
- /// <summary>
- /// 当前活动的图像
- /// </summary>
- private Bitmap bitmap;
- /// <summary>
- /// 调用调色板的控件
- /// </summary>
- private Panel panel2;
- /// <summary>
- /// 调用原图取色 显示色板的控件
- /// </summary>
- private Panel panel3;
- /// <summary>
- /// 是否使用原图取色
- /// </summary>
- private bool item3Checked;
- /// <summary>
- /// 调色板
- /// </summary>
- private PluginAssemblys.ColorsForm colorsFormGrid;
- /// <summary>
- /// 像素格式
- /// </summary>
- private PixelFormat pixelFormat;
- /// <summary>
- /// 图像面板
- /// </summary>
- private DocumentWorkspaceWindow documentWorkspace;
- /// <summary>
- /// 公共按钮
- /// </summary>
- private CommonControlButtons commonControlButtons;
- /// <summary>
- /// 是否点击过应用按钮
- /// 如果没有点过,直接点确定还需要走一遍方法,
- /// 如果已经点过,直接拿当前图片
- /// </summary>
- private bool applyButtonClick = false;
- private PdnMenuItem MenuItem;
- private bool reset = false;
- /// <summary>
- /// 选中参数的索引
- /// </summary>
- private string index = "1";
- [Browsable(false)]
- public AppWorkspace AppWorkspace
- {
- get
- {
- return this.appWorkspace;
- }
- set
- {
- this.appWorkspace = value;
- }
- }
- ActionType menuIdOverall;
- /// <summary>
- /// dialog
- /// </summary>
- /// <param name="appWorkspace"></param>
- /// <param name="menuId">对应菜单的id</param>
- public BshTransferAdjustDialog(AppWorkspace appWorkspace, ActionType menuId, string dialogText, PdnMenuItem menuItem)
- {
- menuIdOverall = menuId;
- this.MenuItem = menuItem;
- InitializeComponent();
- InitializeLanguageText();
- //
- // 设置Dialog属性
- //
- this.AppWorkspace = appWorkspace;
- this.StartPosition = FormStartPosition.CenterScreen;
- this.Icon = PdnInfo.AppIcon;
- this.bitmap = this.AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
- this.pixelFormat = this.AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.PixelFormat;
- this.Text = dialogText;
- //
- //初始化色板
- //
- this.colorsFormGrid = new PluginAssemblys.ColorsForm();
- this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
- this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
- //
- //初始化图像控件
- //
- this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
- this.documentWorkspace.Dock = DockStyle.Fill;
- this.documentWorkspace.HookMouseEvents();
- this.documentWorkspace.Visible = false;
- this.groupBox1.Controls.Add(documentWorkspace);
- //
- //初始化操作按钮
- //
- this.commonControlButtons = new CommonControlButtons();
- this.commonControlButtons.Dock = DockStyle.Top;
- this.commonControlButtons.Height = 30;
- this.commonControlButtons.HideZoomToWindowAndActualSize();
- this.groupBox1.Controls.Add(commonControlButtons);
- switch (menuId)
- {
- //调节
- case ActionType.ActionRevertColor:
- action = new Data.Action.Action5010();
- break;
- case ActionType.ActionBgr2Gray:
- action = new Data.Action.Action5011();
- break;
- case ActionType.ActionWhiteBalance:
- action = new Data.Action.Action5012();
- //白平衡原图取点
- this.documentWorkspace.panel.MouseClick += PicturePreviewControl1_item3MouseDown;
- //picturePreviewControl1.item3MouseDown += PicturePreviewControl1_item3MouseDown;
- break;
- case ActionType.ActionColorBalance:
- action = new Data.Action.Action5013();
- break;
- case ActionType.ActionShadingCorrection:
- action = new Data.Action.Action5014();
- break;
- case ActionType.ActionHSB:
- action = new Data.Action.Action5015();
- break;
- case ActionType.ActionBCG:
- action = new Data.Action.Action5016();
- break;
- case ActionType.ActionImageRotate:
- action = new Data.Action.Action5017();
- break;
- //锐化
- case ActionType.ActionPortray:
- action = new Data.Action.Action5020();
- break;
- case ActionType.ActionEnhanceContour:
- action = new Data.Action.Action5021();
- break;
- case ActionType.ActionBlurMask:
- action = new Data.Action.Action5022();
- break;
- //平滑
- case ActionType.Sigma:
- action = new Data.Action.Action5030();
- break;
- case ActionType.GaussianFiltering:
- action = new Data.Action.Action5031();
- break;
- case ActionType.LowPassFiltering:
- action = new Data.Action.Action5032();
- break;
- case ActionType.MedianFiltering:
- action = new Data.Action.Action5033();
- break;
- case ActionType.GaussianBlur:
- action = new Data.Action.Action5034();
- break;
- case ActionType.BilateralFiltering:
- action = new Data.Action.Action5035();
- break;
- case ActionType.WaveletDenoising:
- action = new Data.Action.Action5036();
- break;
- default:
- action = new Data.Action.Action5010();
- break;
- }
- if (action.Lists == null || action.Lists.Count < 1)
- {
- Label label = new Label();
- label.Left = 7;
- label.Top = 31;
- label.Size = new Size(60, 12);
- label.TextAlign = ContentAlignment.TopLeft;
- label.Text = PdnResources.GetString("Menu.Noparams.text");
- groupBoxParam.Controls.Add(label);
- this.button5.Visible = false;
- GetParameters(Program.instance.imageMenuModel);
- }
- else
- {
- //如果是脚本执行,将参数带入(AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId);
- //if (AppWorkspace.ScriptRunning && AppWorkspace.ScriptCurrentParam != null && AppWorkspace.ScriptCurrentParam.MenuId == action.MenuId)
- //{
- // this.initScriptValues = true;
- // foreach (Args arg in action.Lists)
- // {
- // Args param1 = AppWorkspace.ScriptCurrentParam.Lists.Find(m => m.Key.Equals(arg.Key));
- // if (param1.value != null)
- // arg.Value = param1.value;
- // }
- // AppWorkspace.ScriptCurrentParam = null;//阻止第二次进入仍然被赋值参数
- //}
- //else
- //{
- // GetParameters(Startup.instance.imageMenuModel);
- // this.initScriptValues = false;
- //}
- GetParameters(Program.instance.imageMenuModel);
- int controlsTop = 0;
- //初始化手动控件
- for (int i = 0; i < action.Lists.Count; i++)
- {
- Args args = action.Lists[i];
- index = args.value.ToString();
- if (args is IntegerNumber || args is DecimalNumber || args is OddNumber)
- {
- NumberParamControl numberParam = new NumberParamControl();
- numberParam.Left = 78;
- numberParam.Top = 35 + controlsTop;
- //设置参数范围
- numberParam.paramIndex = 100 + i;
- if (args is DecimalNumber)
- {
- numberParam.DecimalPlaces = ((DecimalNumber)args).DecimalPlaces;
- numberParam.Minimum = (double)((DecimalNumber)args).Min;
- numberParam.Maximum = (double)((DecimalNumber)args).Max;
- }
- else if (args is OddNumber)
- {
- numberParam.Increment = 2;
- numberParam.Minimum = ((OddNumber)args).Min;
- numberParam.Maximum = ((OddNumber)args).Max;
- numberParam.IsOddNumber = true;
- }
- else
- {
- numberParam.DecimalPlaces = 0;
- numberParam.Minimum = ((IntegerNumber)args).Min;
- numberParam.Maximum = ((IntegerNumber)args).Max;
- }
- double fnum = 0;
- if (double.TryParse((initScriptValues || initPamasValues ? args.value : args.initialValue).ToString(), out fnum))
- {
- numberParam.Value = fnum;
- //args.Value = fnum;
- }
- groupBoxParam.Controls.Add(numberParam);
- groupBoxParam.Controls.SetChildIndex(numberParam, 100 + i);
- if (args is DecimalNumber)
- {
- numberParam.ValueChanged += new EventHandler(((DecimalNumber)args).numberParam_ValueChanged);
- }
- else if (args is OddNumber)
- {
- numberParam.ValueChanged += new EventHandler(((OddNumber)args).numberParam_ValueChanged);
- }
- else
- {
- numberParam.ValueChanged += new EventHandler(((IntegerNumber)args).numberParam_ValueChanged);
- }
- numberParam.ValueChanged += this.ParameterChangeEvent;
- Label label = new Label();
- label.Left = 19;
- label.Top = 40 + controlsTop;
- label.Size = new Size(65, 12);//55->65 调试值,提交备注:调试3-双边滤波-邻域直径。
- label.TextAlign = ContentAlignment.MiddleRight;
- label.Text = args.name + ":";
- groupBoxParam.Controls.Add(label);
- controlsTop += 45;
- }
- else if (args is ChoiseArray)
- {
- Label label = new Label();
- label.Left = 19;
- label.Top = 40 + controlsTop;
- label.Size = new Size(55, 12);
- label.TextAlign = ContentAlignment.MiddleRight;
- label.Text = args.name + ":";
- groupBoxParam.Controls.Add(label);
- //初始化选项列表
- for (int j = 0; j < args.choiseList.Count; j++)
- {
- BooleanObject argsChoise = args.choiseList[j] as BooleanObject;
- RadioButton radio = new RadioButton();
- if (argsChoise.key == args.value)
- {
- radio.Checked = true;
- }
- radio.AutoSize = true;
- radio.Location = new Point(88, 40 + controlsTop/*topMargin*/);
- radio.Text = argsChoise.name + "";
- radio.Tag = argsChoise.Key;
- radio.CheckedChanged += ((ChoiseArray)args).numberParam_ValueChanged;
- radio.CheckedChanged += Radio_CheckedChanged;
- groupBoxParam.Controls.Add(radio);
- if (argsChoise.Lists.Count > 0)
- {
- ColorNumber phaseColor = argsChoise.Lists[0] as ColorNumber;
- if (phaseColor.Key.Equals("phaseColor"))
- {
- Panel panel = new Panel();
- panel.BackColor = Color.FromArgb(int.Parse(phaseColor.Value.ToString()));
- panel.Size = new Size(53, 20);
- panel.Top = 37 + controlsTop;
- panel.Left = 178;
- groupBoxParam.Controls.Add(panel);
- panel.Click += new System.EventHandler(this.panel2_Click);
- panel.BackColorChanged += ((ColorNumber)phaseColor).numberParam_ValueChanged;
- panel.BackColorChanged += this.ParameterChangeEvent;
- this.panel2 = panel;
- }
- else if (phaseColor.Key.Equals("imageColor"))
- {
- Panel panel = new Panel();
- panel.BackColor = Color.FromArgb(int.Parse(phaseColor.Value.ToString()));
- panel.Size = new Size(53, 20);
- panel.Top = 37 + controlsTop;
- panel.Left = 178;
- groupBoxParam.Controls.Add(panel);
- panel.BackColorChanged += ((ColorNumber)phaseColor).numberParam_ValueChanged;
- panel.BackColorChanged += this.ParameterChangeEvent;
- this.panel3 = panel;
- }
- }
- controlsTop += 45;
- }
- }
- else if (args is ColorNumber)
- {
- Label label = new Label();
- label.Left = 19;
- label.Top = 40 + controlsTop;
- label.Size = new Size(65, 12);
- label.TextAlign = ContentAlignment.MiddleRight;
- label.Text = args.name + ":";
- //colorPanel.BackColorChanged += ((ColorNumber)arg).numberParam_ValueChanged;
- ////radio.CheckedChanged += ((ChoiseArray)args).numberParam_ValueChanged;
- groupBoxParam.Controls.Add(label);
- Panel panel = new Panel();
- panel.BackColor = Color.FromArgb(int.Parse(args.Value.ToString()));
- panel.Size = new Size(53, 20);
- panel.Top = 35 + controlsTop;
- panel.Left = 85;
- groupBoxParam.Controls.Add(panel);
- panel.Click += new System.EventHandler(this.panel2_Click);
- panel.BackColorChanged += ((ColorNumber)args).numberParam_ValueChanged;
- panel.BackColorChanged += this.ParameterChangeEvent;
- this.panel2 = panel;
- controlsTop += 45;
- }
- else if (args is StringArray)
- {
- Label label = new Label();
- label.Left = 19;
- label.Top = 40 + controlsTop;
- label.Size = new Size(55, 12);
- label.TextAlign = ContentAlignment.MiddleRight;
- label.Text = args.name + ":";
- groupBoxParam.Controls.Add(label);
- Panel panel = new Panel();
- panel.AutoSize = true;
- panel.Top = 40 + controlsTop;
- panel.Left = 78;
- int position = 1;
- int topMargin = 0;
- //循环字典,铺多个radio
- foreach (var item in (Dictionary<Enum, object>)((initScriptValues || initPamasValues ? args.value : args.initialValue)))
- {
- int xvalue = 0;
- if (position % 1 == 0) xvalue = 0;
- if (position % 2 == 0) xvalue = 1;
- if (position % 3 == 0) xvalue = 2;
- RadioButton radio = new RadioButton();
- if (position == 1)
- {
- radio.Checked = true;
- }
- radio.AutoSize = true;
- radio.Location = new Point(xvalue * 90, topMargin);
- radio.Text = item.Value.ToString();
- radio.Tag = item.Key;
- radio.CheckedChanged += ((StringArray)args).numberParam_ValueChanged;
- radio.CheckedChanged += this.ParameterChangeEvent;
- panel.Controls.Add(radio);
- if (position % 3 == 0) topMargin += 25;
- position++;
- }
- groupBoxParam.Controls.Add(panel);
- controlsTop += 45;
- }
- }
- }
- InitData();
- InitCommonButtonEvent();
- }
- private void startScriptAutomaticAction()
- {
- applyButtonImpl(null, null);
- sureButtonImpl(null, null);
- }
- private void ParameterChangeEvent(object sender, EventArgs e)
- {
- this.applyButtonClick = false;
- }
- private void InitCommonButtonEvent()
- {
- this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
- this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
- this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
- this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
- this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
- this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
- }
- private void zoomInButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomIn();
- }
- private void zoomOutButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomOut();
- }
- private void zoomToWindowButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- private void actualSizeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
- }
- private void pointerButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
- }
- private void mobileModeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
- }
- private void Radio_CheckedChanged(object sender, EventArgs e)
- {
- if (((RadioButton)sender).Tag.Equals("3"))//原图取色
- {
- this.item3Checked = ((RadioButton)sender).Checked;
- //picturePreviewControl1.selectColorMode(this.item3Checked);
- }
- OpenCvSharp.Mat mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- Document document = Document.FromMat(mat);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- //picturePreviewControl1.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
- }
- /// <summary>
- /// 相颜色点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel2_Click(object sender, EventArgs e)
- {
- this.panel2 = ((Panel)sender);
- this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(panel2.BackColor);
- this.colorsFormGrid.ShowDialog();
- }
- /// <summary>
- /// Panel2的调色板颜色改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gridColorChanged(object sender, EventArgs e)
- {
- Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
- //更改背景色,触发事件
- this.panel2.BackColor = color;
- ////改变配置文件里面的相颜色
- //this.binaryExtractionModel.PhaseColor = color.ToArgb();
- OpenCvSharp.Mat mat = new OpenCvSharp.Mat();
- if (menuIdOverall == ActionType.ActionImageRotate)
- {
- OpenCvSharp.Mat src = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- //GeometryIntent.ImageRotate(src, mat, float.Parse(action.lists[0].value.ToString()), OpenCvSharp.InterpolationFlags.Linear);
- mat = GeometryIntent.MatRotate(src, float.Parse(action.lists[0].value.ToString()), new OpenCvSharp.Scalar(panel2.BackColor.B, panel2.BackColor.G, panel2.BackColor.R, 255));
- }
- else
- {
- mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- }
- //mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- //OpenCvSharp.Mat mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- Document document = Document.FromMat(mat);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- //picturePreviewControl1.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
- //关闭色板
- this.colorsFormGrid.Close();
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
- public void InitData()
- {
- Document document = Document.FromImage(this.bitmap);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Visible = true;
- this.documentWorkspace.Refresh();
- //给picturebox赋值
- //picturePreviewControl1.pictureBox1.Image = this.bitmap;
- //初始化/重置参数
- resetNumber();
- //this.initScriptValues = false;//阻止第二次进入仍然被赋值参数
- }
- private void resetNumber()
- {
- if (action is Action5012)//白平衡
- {
- //GetParameters(Startup.instance.imageMenuModel);
- this.item3Checked = false;
- //重新初始化选项列表
- Args args = action.Lists[0];
- for (int j = 0; j < args.choiseList.Count; j++)
- {
- BooleanObject argsChoise = args.choiseList[j] as BooleanObject;
- if (argsChoise.Lists.Count > 0)
- {
- ColorNumber phaseColor = argsChoise.Lists[0] as ColorNumber;
- if (phaseColor.Key.Equals("phaseColor"))//色板取色
- {
- this.panel2.BackColor = Color.FromArgb(int.Parse((initScriptValues || initPamasValues ? phaseColor.value : phaseColor.initialValue).ToString()));
- }
- else if (phaseColor.Key.Equals("imageColor"))//原图取色
- {
- this.panel3.BackColor = Color.FromArgb(int.Parse((initScriptValues || initPamasValues ? phaseColor.value : phaseColor.initialValue).ToString()));
- }
- }
- }
- }
- if (action is Action5017)//图像偏移
- {
- //重新初始化选色面板
- for (int j = 0; j < action.Lists.Count; j++)
- {
- ColorNumber phaseColor = action.Lists[j] as ColorNumber;
- if (phaseColor is ColorNumber)
- {
- this.panel2.BackColor = Color.FromArgb(int.Parse((initScriptValues || initPamasValues ? phaseColor.value : phaseColor.initialValue).ToString()));
- break;
- }
- }
- }
- foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
- {
- if (control is NumberParamControl)
- {
- NumberParamControl numberParam = (NumberParamControl)control;
- if (numberParam.paramIndex >= 100)
- {
- //List<Args> list1s = action.Lists[0];
- Args args = /*list1s*/action.Lists[numberParam.paramIndex - 100];
- double fnum = 0;
- if (double.TryParse((initScriptValues || initPamasValues ? args.value : args.initialValue).ToString(), out fnum))
- {
- numberParam.Value = fnum;
- } else if (reset){
- numberParam.Value = (int)args.initialValue;
- }
-
-
-
-
- }
- }
- else if (control is RadioButton)
- {
- if (control.Tag.Equals(index))
- {
- ((RadioButton)control).Checked = true;
- }
- else
- {
- ((RadioButton)control).Checked = false;
- }
- }
- }
- }
- /// <summary>
- /// 原图取点的响应方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PicturePreviewControl1_item3MouseDown(object sender, MouseEventArgs e)
- {
- if (this.item3Checked)
- {
- System.Drawing.Point point = this.documentWorkspace.GetScalePoint(new System.Drawing.Point(e.X, e.Y));
- int x = point.X;
- int y = point.Y;
- if (x >= 0 && y >= 0 && x < this.documentWorkspace.CompositionSurface.Width && y < this.documentWorkspace.CompositionSurface.Height)
- {
- OpenCvSharp.Mat srt = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap);
- OpenCvSharp.Vec3b bgr = srt.At<OpenCvSharp.Vec3b>(y, x);
- Color color = Color.FromArgb(bgr[2], bgr[1], bgr[0]);
- //更改背景色,触发事件
- this.panel3.BackColor = color;
- OpenCvSharp.Mat mat = action.PerformProcess(srt);
- //mat.Set(e.Location.Y, e.Location.X, new OpenCvSharp.Vec3b(0, 0, 255));//测试取点的位置
- //picturePreviewControl1.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
- Document document = Document.FromMat(mat);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- }
- }
- }
- private void BshTransferAdjustDialog_Load(object sender, EventArgs e)
- {
- System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
- //图像名称输入框
- informationControl.fileNameTextBox1.Text = this.Text + "-" + stepLength;
- //picturePreviewControl1.isShown = true;
- parametersSettingControl.applyButtonClick += new EventHandler(applyButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
- parametersSettingControl.sureButtonClick += new EventHandler(sureButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
- //if (this.initScriptValues && this.appWorkspace.ScriptAutomatic)
- //{
- // this.startScriptAutomaticAction();
- //}
- }
- //应用
- private void applyButtonImpl(object sender, EventArgs e)
- {
- PluginAssemblys.ProgressThreadProcClass procClass = new PluginAssemblys.ProgressThreadProcClass();
- int itemCount = 100;
- PluginAssemblys.ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new PluginAssemblys.ProgressThreadProcClass.IFileTransferProgressEvents();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- try
- {
- OpenCvSharp.Mat mat = new OpenCvSharp.Mat();
- mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- //if (menuIdOverall == ActionType.ActionImageRotate)
- //{
- // OpenCvSharp.Mat src = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- // //OpenCvSharp.Cv2.CvtColor(src, src, OpenCvSharp.ColorConversionCodes.BGRA2BGR);
- // mat = GeometryIntent.MatRotate(src, float.Parse(action.lists[0].value.ToString()), new OpenCvSharp.Scalar(panel2.BackColor.B, panel2.BackColor.G, panel2.BackColor.R, 255));
- //}
- //else
- //{
- // mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- // //OpenCvSharp.Cv2.CvtColor(mat, mat, OpenCvSharp.ColorConversionCodes.BGRA2BGR);
- //}
- Document document = Document.FromMat(mat);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- this.applyButtonClick = true;
- }
- catch (Exception ex)
- {
- }
- finally
- {
- progressEvents.EndOperation(OperationResult.Finished);
- }
- };
- procClass.StartProgressAction(/*currentForm*/this, itemCount, copyThreadProc, progressEvents, null);
- }
- //确定
- internal void sureButtonImpl(object sender, EventArgs e)
- {
- PluginAssemblys.ProgressThreadProcClass procClass = new PluginAssemblys.ProgressThreadProcClass();
- int itemCount = 100;
- PluginAssemblys.ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new PluginAssemblys.ProgressThreadProcClass.IFileTransferProgressEvents();
- System.Threading.ThreadStart copyThreadProc =
- delegate ()
- {
- try
- {
- OpenCvSharp.Mat mat = new OpenCvSharp.Mat();
- if (!this.applyButtonClick)
- {
- if (menuIdOverall == ActionType.ActionImageRotate)
- {
- OpenCvSharp.Mat src = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- mat = GeometryIntent.MatRotate(src, float.Parse(action.lists[0].value.ToString()), new OpenCvSharp.Scalar(panel2.BackColor.B, panel2.BackColor.G, panel2.BackColor.R, 255));
- }
- else
- {
- mat = action.PerformProcess(OpenCvSharp.Extensions.BitmapConverter.ToMat(this.bitmap));
- }
- if (this.pixelFormat == PixelFormat.Format8bppIndexed && mat.Type() != OpenCvSharp.MatType.CV_8UC1)
- {
- mat = mat.CvtColor(OpenCvSharp.ColorConversionCodes.BGR2GRAY);
- }
- }
- else
- {
- mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.documentWorkspace.CompositionSurface.CreateAliasedBitmap());
- }
- this.Invoke(new EventHandler(delegate
- {
- //生成新图-是
- if (informationControl.radioButton1.Checked)
- {
- this.OpenFileImpl(mat);
- }
- else
- {
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat));
- AppWorkspace.ActiveDocumentWorkspace.Document = document;
- }
- this.Close();
- }));
- }
- catch (Exception)
- {
- }
- finally
- {
- progressEvents.EndOperation(OperationResult.Finished);
- }
- };
- procClass.StartProgressAction(/*currentForm*/this, itemCount, copyThreadProc, progressEvents, null);
- }
- //生成新图
- private void OpenFileImpl(OpenCvSharp.Mat mat)
- {
- DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
- Document document = Document.FromImage(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat));
- dw.Document = document;
- dw.fileText = informationControl.fileNameTextBox1.Text;
- //dw.xmlSaveModel = this.appWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
- //dw.rules = this.appWorkspace.ActiveDocumentWorkspace.rules;
- AppWorkspace.ActiveDocumentWorkspace = dw;
- Program.instance.step_length += 1;
- }
- //参数-重设
- private void button5_Click(object sender, EventArgs e)
- {
- reset = true;
- GetParameters(Program.instance.imageMenuModel);
- //初始化/重置参数
- resetNumber();
- Document document = Document.FromImage(this.bitmap);
- this.documentWorkspace.Document = document;
- this.documentWorkspace.Refresh();
- reset = false;
- //picturePreviewControl1.pictureBox1.Image = this.bitmap;
- }
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- private void InitializeLanguageText()
- {
- this.groupBoxParam.Text = PdnResources.GetString("Menu.params.text");
- this.button5.Text = PdnResources.GetString("Menu.rebuild.Text");
- this.groupBox1.Text = PdnResources.GetString("Menu.Preview.text");
- this.Text = PdnResources.GetString("Menu.geprocessiconditioningsaturationbrigh.Text");
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.parametersSettingControl = new SmartCoalApplication.Core.CustomControl.ParametersSettingAdjustControl();
- this.informationControl = new SmartCoalApplication.Core.CustomControl.InformationAdjustControl();
- this.groupBoxParam = new System.Windows.Forms.GroupBox();
- this.button5 = new System.Windows.Forms.Button();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.groupBoxParam.SuspendLayout();
- this.SuspendLayout();
- //
- // parametersSettingControl
- //
- this.parametersSettingControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.parametersSettingControl.Location = new System.Drawing.Point(12, 12);
- this.parametersSettingControl.Name = "parametersSettingControl";
- this.parametersSettingControl.Size = new System.Drawing.Size(918, 58);
- this.parametersSettingControl.TabIndex = 9;
- //
- // informationControl
- //
- this.informationControl.Location = new System.Drawing.Point(12, 76);
- this.informationControl.Name = "informationControl";
- this.informationControl.Size = new System.Drawing.Size(373, 82);
- this.informationControl.TabIndex = 11;
- //
- // groupBoxParam
- //
- this.groupBoxParam.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)));
- this.groupBoxParam.Controls.Add(this.button5);
- this.groupBoxParam.Location = new System.Drawing.Point(12, 164);
- this.groupBoxParam.Name = "groupBoxParam";
- this.groupBoxParam.Size = new System.Drawing.Size(373, 353);
- this.groupBoxParam.TabIndex = 12;
- this.groupBoxParam.TabStop = false;
- //
- // button5
- //
- this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button5.Location = new System.Drawing.Point(292, 324);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 1;
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox1.Location = new System.Drawing.Point(392, 77);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(538, 440);
- this.groupBox1.TabIndex = 13;
- this.groupBox1.TabStop = false;
- //
- // BshTransferAdjustDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(942, 529);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.groupBoxParam);
- this.Controls.Add(this.informationControl);
- this.Controls.Add(this.parametersSettingControl);
- this.MinimizeBox = false;
- this.Name = "BshTransferAdjustDialog";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.BshTransferAdjustDialog_FormClosing);
- this.Load += new System.EventHandler(this.BshTransferAdjustDialog_Load);
- this.groupBoxParam.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- private ParametersSettingAdjustControl parametersSettingControl;
- private InformationAdjustControl informationControl;
- private System.Windows.Forms.GroupBox groupBoxParam;
- private System.Windows.Forms.Button button5;
- private System.Windows.Forms.GroupBox groupBox1;
- private void BshTransferAdjustDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- string newpic = 1 + "";
- //获取参数实体
- ImageMenu imageMenu;
- if (Program.instance.imageMenuModel != null)
- {
- imageMenu = Program.instance.imageMenuModel;
- }
- else
- {
- imageMenu = new ImageMenu();
- imageMenu.ListParam = new List<ImageParam>();
- }
- //数字控制是否生成新图
- if (informationControl.radioButton1.Checked)
- newpic = 1 + "";
- else
- newpic = 0 + "";
- List<ImageParam> list = imageMenu.ListParam.Where(x => x.menuId == (int)action.MenuId).ToList();
- if (list.Count == 0)
- {
- ImageParam param = new ImageParam();
- param.menuId = (int)action.MenuId;
- param.param_key = "param_newpic";
- param.param_type = -1;
- param.param_value = newpic;
- imageMenu.ListParam.Add(param);
- }
- //判断页面是否有参数
- if (action.lists.Count > 0)
- {
- for (int i = 0; i < action.lists.Count; i++)
- {
- if (list.Count > 0)//是否存过参数
- {
- for (int j = 0; j < imageMenu.ListParam.Count; j++)//给参数实体赋值
- {
- if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == action.lists[i].key)
- {
- imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
- imageMenu.ListParam[j].param_value = action.lists[i].value.ToString();
- //imageMenu.ListParam[j].param_newpic = informationControl.radioButton1.Checked;
- }
- else if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == "param_newpic")
- {
- //imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
- imageMenu.ListParam[j].param_value = newpic;
- //imageMenu.ListParam[j].param_newpic = informationControl.radioButton1.Checked;
- }
- }
- //判断是否是白平衡
- if (action.MenuId == ActionType.ActionWhiteBalance)
- {
- for (int j = 0; j < imageMenu.ListParam.Count; j++)//给参数实体赋值
- {
- if (int.Parse(action.Lists[0].value.ToString()) > 1)
- {
- if (imageMenu.ListParam[j].param_key == "phaseColor" || imageMenu.ListParam[j].param_key == "imageColor")
- {
- imageMenu.ListParam[j].menuId = (int)action.MenuId;
- imageMenu.ListParam[j].param_key = action.Lists[0].choiseList[int.Parse(action.Lists[0].value.ToString()) - 1].Lists[0].key;
- imageMenu.ListParam[j].param_value = action.Lists[0].choiseList[int.Parse(action.Lists[0].value.ToString()) - 1].Lists[0].value.ToString();
- }
- }
- }
- }
- }
- else //如果没保存过新增
- {
- ImageParam param = new ImageParam();
- param.menuId = (int)action.MenuId;
- param.param_key = action.lists[i].key;
- param.param_type = (int)action.lists[i].Type;
- param.param_value = action.lists[i].value.ToString();
- //判断是否是白平衡
- if (action.MenuId == ActionType.ActionWhiteBalance)
- {
- ImageParam param5012 = new ImageParam();
- try
- {
- param5012.menuId = (int)action.MenuId;
- param5012.param_key = action.Lists[0].choiseList[int.Parse(action.Lists[0].value.ToString()) - 1].Lists[0].key;
- param5012.param_value = action.Lists[0].choiseList[int.Parse(action.Lists[0].value.ToString()) - 1].Lists[0].value.ToString();
- }
- catch (Exception)
- {
- //ImageParam param5012 = new ImageParam();
- param5012.menuId = (int)action.MenuId;
- param5012.param_key = "objectSelect";
- param5012.param_value = "1";
- }
- imageMenu.ListParam.Add(param5012);
- }
- imageMenu.ListParam.Add(param);
- }
- }
- }
- else //没有参数,给是否生成新图赋值
- {
- if (list.Count > 0)
- {
- for (int j = 0; j < imageMenu.ListParam.Count; j++)
- {
- if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == "param_newpic")
- {
- imageMenu.ListParam[j].param_value = newpic;
- }
- }
- }
- }
- Program.instance.imageMenuModel = imageMenu;
- //按路径和名称保存xml文件
- string userInfoXml = XmlSerializeHelper.XmlSerialize<ImageMenu>(imageMenu);
- //xml保存路径
- string filePath = Application.StartupPath + "\\Config\\" + "Default\\ParameterSaving\\ParameterSaving.xml";
- //保存xml
- FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
- }
- /// <summary>
- /// 初始化时获取参数
- /// </summary>
- /// <param name="imageMenu">系统读取的参数配置</param>
- public void GetParameters(ImageMenu imageMenu)
- {
- List<ImageParam> list = new List<ImageParam>();
- if (imageMenu != null && imageMenu.ListParam.Count > 0)
- list = imageMenu.ListParam.Where(x => x.menuId == (int)action.MenuId).ToList();
- if (list.Count > 0)
- {
- initPamasValues = true;
- for (int i = 0; i < action.Lists.Count; i++)
- {
- for (int j = 0; j < list.Count; j++)
- {
- if (list[j].param_key.Equals(action.Lists[i].key))
- {
- action.Lists[i].Type = (Dtryt)list[j].param_type;
- action.Lists[i].value = list[j].param_value;
- break;
- }
- }
- //判断是否是白平衡
- if (action.MenuId == ActionType.ActionWhiteBalance)
- {
- for (int j = 0; j < list.Count; j++)//给参数实体赋值
- {
- if (list[j].param_key == "phaseColor")
- {
- action.Lists[0].choiseList[1].Lists[0].key = "phaseColor";
- action.Lists[0].choiseList[1].Lists[0].value = list[j].param_value;
- }
- if (list[j].param_key == "imageColor")
- {
- action.Lists[0].choiseList[2].Lists[0].key = "imageColor";
- action.Lists[0].choiseList[2].Lists[0].value = list[j].param_value;
- }
- }
- }
- }
- for (int j = 0; j < list.Count; j++)
- {
- if ("param_newpic".Equals(list[j].param_key))
- {
- if (list[j].param_value == "1")
- {
- informationControl.radioButton1.Checked = true;
- informationControl.radioButton2.Checked = false;
- }
- else
- {
- informationControl.radioButton1.Checked = false;
- informationControl.radioButton2.Checked = true;
- }
- }
- }
- }
- }
- }
- }
|