版博士V2.0程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

186 linhas
6.6 KiB

  1. using ImageToolKits;
  2. using OpenCvSharp;
  3. using ProductionControl.Utils;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace ProductionControl.UI
  15. {
  16. public partial class FrmGetPosByPic : Form
  17. {
  18. List<ImageBox.BaseDrawParam> pickARoi = new List<ImageBox.BaseDrawParam>();
  19. Mat Img;
  20. private TextBox[] tbArray = new TextBox[14];
  21. string _Path;
  22. double[] _Points;
  23. public FrmGetPosByPic(string map, double[] pointlist)
  24. {
  25. _Path = map;
  26. _Points = pointlist;
  27. pickARoi.Clear();
  28. InitializeComponent();
  29. //lbPoslist.Items.Clear();
  30. this.imageBox1.SetLowLevelMode(14);
  31. imageBox1.DrawOverAllEventHandler += imgBox_DrawOverAllEventHandler;
  32. tbArray[0] = this.textBox1;
  33. tbArray[1] = this.textBox2;
  34. tbArray[2] = this.textBox3;
  35. tbArray[3] = this.textBox4;
  36. tbArray[4] = this.textBox5;
  37. tbArray[5] = this.textBox6;
  38. tbArray[6] = this.textBox7;
  39. tbArray[7] = this.textBox8;
  40. tbArray[8] = this.textBox9;
  41. tbArray[9] = this.textBox10;
  42. tbArray[10] = this.textBox11;
  43. tbArray[11] = this.textBox12;
  44. tbArray[12] = this.textBox13;
  45. tbArray[13] = this.textBox14;
  46. }
  47. public string GetMapPath()
  48. { return _Path; }
  49. public double[] GetPoints()
  50. {
  51. return _Points; }
  52. void imgBox_DrawOverAllEventHandler(object sender, List<ImageBox.BaseDrawParam> e)
  53. {
  54. if (e.Count > 0)
  55. {
  56. imageBox1.RefreshWindow(imageBox1.Image, e, ImageBox.ImageModeEnum.Part);
  57. this.pickARoi = imageBox1.GetLowPoints();
  58. for (int i = 0; i < 14; i++)
  59. {
  60. if (i < e.Count)
  61. tbArray[i].Text = "X:" + (e[i] as ImageBox.Point).Column.ToString("0.000") + ", Y:" + (e[i] as ImageBox.Point).Row.ToString("0.000");
  62. else
  63. tbArray[i].Text = "";
  64. }
  65. }
  66. }
  67. private void FrmGetPosByPic_Load(object sender, EventArgs e)
  68. {
  69. List<ImageBox.BaseDrawParam> roi = new List<ImageBox.BaseDrawParam>();
  70. if (File.Exists(_Path))
  71. {
  72. Img = new Mat(_Path);
  73. if ((_Points[0] != 0) && (_Points[2] != 0) && (_Points[4] != 0) && (_Points[6] != 0) && (_Points[8] != 0))
  74. {
  75. //this.imageBox1.RefreshWindow(Img);
  76. if (_Points.Length == (14 * 2))
  77. {
  78. for (int i = 0; i < 14; i++)
  79. {
  80. //string pos = sizeLibProp.GetPointList[5 + 2 * i].ToString() + "," + sizeLibProp.GetPointList[5 + 2 * i +1].ToString();
  81. //lbPoslist.Items.Add(pos);
  82. ImageBox.BaseDrawParam point = new ImageBox.Point((float)_Points[2 * i + 1], (float)_Points[2 * i]);
  83. tbArray[i].Text = "X:" + _Points[2 * i + 0].ToString("0.000") + ", Y:" + _Points[2 * i + 1].ToString("0.000");
  84. roi.Add(point);
  85. pickARoi.Add(point);
  86. }
  87. imageBox1.SetDrawPrms(pickARoi);
  88. //imageBox1.RefreshWindow(Img, roi);
  89. //imageBox1.Refresh();
  90. }
  91. else if (_Points.Length > 0)
  92. MessageBox.Show("点位数据错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
  93. }
  94. //else
  95. //{
  96. //imageBox1.RefreshWindow(Img, roi);
  97. //imageBox1.Refresh();
  98. //}
  99. }
  100. else
  101. {
  102. string maop_path = FileUtil.selectFile();
  103. if (File.Exists(maop_path))
  104. {
  105. _Path = maop_path;
  106. Img = new Mat(maop_path);
  107. this.imageBox1.RefreshWindow(Img);
  108. }
  109. else
  110. {
  111. MessageBox.Show("无图纸图片加载!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
  112. return;
  113. }
  114. }
  115. imageBox1.RefreshWindow(Img, roi);
  116. imageBox1.Refresh();
  117. imageBox1.DisplayROIs(roi);
  118. }
  119. private void tsbtnClear_Click(object sender, EventArgs e)
  120. {
  121. if (MessageBox.Show("是否清空所有点位?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
  122. {
  123. pickARoi.Clear();
  124. this.imageBox1.ClearLowPoints();
  125. this.imageBox1.RefreshWindow(Img);
  126. for (int i = 0; i < 14; i++)
  127. {
  128. tbArray[i].Text = "";
  129. }
  130. }
  131. }
  132. private void tsbtnClose_Click(object sender, EventArgs e)
  133. {
  134. this.Close();
  135. }
  136. private void tsbtnSave_Click(object sender, EventArgs e)
  137. {
  138. pickARoi = this.imageBox1.GetLowPoints();
  139. if (pickARoi.Count == 14)
  140. {
  141. _Points = new double[14 * 2];
  142. for (int i = 0; i < 14; i++)
  143. {
  144. _Points[2 * i] = Math.Round((pickARoi[i] as ImageBox.Point).Column,3);
  145. _Points[2 * i + 1] = Math.Round((pickARoi[i] as ImageBox.Point).Row,3);
  146. }
  147. this.DialogResult = DialogResult.OK;
  148. }
  149. else if (pickARoi.Count >0)
  150. MessageBox.Show("点位设置错误,点数不对!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
  151. else
  152. {
  153. _Points = new double[14 * 2];
  154. for (int i = 0; i < 14; i++)
  155. {
  156. _Points[2 * i] = 0;
  157. _Points[2 * i + 1] = 0;
  158. }
  159. }
  160. }
  161. private void tsbtnDelectPos_Click(object sender, EventArgs e)
  162. {
  163. this.imageBox1.DelectOntPoint();
  164. this.pickARoi.RemoveAt(pickARoi.Count - 1);
  165. }
  166. }
  167. }