CameraAutomaticDepth.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using OpenCvSharp;
  13. using OpenCvSharp.Extensions;
  14. using PaintDotNet.Adjust.BaseImage;
  15. using PaintDotNet.Base.SettingModel;
  16. using StageController;
  17. using StageController.M3H;
  18. using TUCAMAPI;
  19. using TUCamera;
  20. namespace PaintDotNet.ImageCollect.CameraEDOF
  21. {
  22. /// <summary>
  23. /// 自动景深扩展
  24. /// </summary>
  25. internal class CameraAutomaticDepth : FloatingToolForm
  26. {
  27. /// <summary>
  28. /// Required designer variable.
  29. /// </summary>
  30. private System.ComponentModel.IContainer components = null;
  31. /// <summary>
  32. /// Clean up any resources being used.
  33. /// </summary>
  34. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  35. protected override void Dispose(bool disposing)
  36. {
  37. if (disposing && (components != null))
  38. {
  39. components.Dispose();
  40. }
  41. base.Dispose(disposing);
  42. }
  43. #region Windows Form Designer generated code
  44. private void InitializeLanguageText()
  45. {
  46. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  47. this.btnCreatImgFile.Text = PdnResources.GetString("Menu.Createpicture.text");
  48. this.btnWorking.Text = PdnResources.GetString("Menu.Started.text");
  49. this.groupBox2.Text = PdnResources.GetString("Menu.paramssettings.text");
  50. this.rdoMod2.Text = PdnResources.GetString("Menu.Model2.Text");
  51. this.rdoMod1.Text = PdnResources.GetString("Menu.imagecapture.Autoeldexpansion.patternone.text");
  52. this.groupBox4.Text = PdnResources.GetString("Menu.ImageCollection.AutomaticDepth.Text");
  53. this.label1.Text = PdnResources.GetString("Menu.imagecapture.Autoeldexpansion.Shootingmode.text") + ":";
  54. this.Text = PdnResources.GetString("Menu.ImageCollection.AutomaticDepth.Text");
  55. this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text");
  56. }
  57. /// <summary>
  58. /// Required method for Designer support - do not modify
  59. /// the contents of this method with the code editor.
  60. /// </summary>
  61. private void InitializeComponent()
  62. {
  63. this.groupBox1 = new System.Windows.Forms.GroupBox();
  64. this.btnZClear = new System.Windows.Forms.Button();
  65. this.btnCreatImgFile = new System.Windows.Forms.Button();
  66. this.btnWorking = new System.Windows.Forms.Button();
  67. this.groupBox2 = new System.Windows.Forms.GroupBox();
  68. this.controlPanel = new System.Windows.Forms.Panel();
  69. this.rdoMod2 = new System.Windows.Forms.RadioButton();
  70. this.rdoMod1 = new System.Windows.Forms.RadioButton();
  71. this.label1 = new System.Windows.Forms.Label();
  72. this.splitContainer1 = new System.Windows.Forms.SplitContainer();
  73. this.groupBox3 = new System.Windows.Forms.GroupBox();
  74. this.picPreview = new System.Windows.Forms.PictureBox();
  75. this.groupBox4 = new System.Windows.Forms.GroupBox();
  76. this.picDepth = new System.Windows.Forms.PictureBox();
  77. this.groupBox1.SuspendLayout();
  78. this.groupBox2.SuspendLayout();
  79. ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
  80. this.splitContainer1.Panel1.SuspendLayout();
  81. this.splitContainer1.Panel2.SuspendLayout();
  82. this.splitContainer1.SuspendLayout();
  83. this.groupBox3.SuspendLayout();
  84. ((System.ComponentModel.ISupportInitialize)(this.picPreview)).BeginInit();
  85. this.groupBox4.SuspendLayout();
  86. ((System.ComponentModel.ISupportInitialize)(this.picDepth)).BeginInit();
  87. this.SuspendLayout();
  88. //
  89. // groupBox1
  90. //
  91. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  92. | System.Windows.Forms.AnchorStyles.Right)));
  93. this.groupBox1.Controls.Add(this.btnZClear);
  94. this.groupBox1.Controls.Add(this.btnCreatImgFile);
  95. this.groupBox1.Controls.Add(this.btnWorking);
  96. this.groupBox1.Location = new System.Drawing.Point(9, 10);
  97. this.groupBox1.Margin = new System.Windows.Forms.Padding(2);
  98. this.groupBox1.Name = "groupBox1";
  99. this.groupBox1.Padding = new System.Windows.Forms.Padding(2);
  100. this.groupBox1.Size = new System.Drawing.Size(935, 70);
  101. this.groupBox1.TabIndex = 0;
  102. this.groupBox1.TabStop = false;
  103. this.groupBox1.Text = "操作";
  104. //
  105. // btnZClear
  106. //
  107. this.btnZClear.Location = new System.Drawing.Point(661, 24);
  108. this.btnZClear.Name = "btnZClear";
  109. this.btnZClear.Size = new System.Drawing.Size(75, 23);
  110. this.btnZClear.TabIndex = 2;
  111. this.btnZClear.Text = "Z Clear";
  112. this.btnZClear.UseVisualStyleBackColor = true;
  113. this.btnZClear.Click += new System.EventHandler(this.btnZClear_Click);
  114. //
  115. // btnCreatImgFile
  116. //
  117. this.btnCreatImgFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  118. this.btnCreatImgFile.Location = new System.Drawing.Point(852, 22);
  119. this.btnCreatImgFile.Margin = new System.Windows.Forms.Padding(2);
  120. this.btnCreatImgFile.Name = "btnCreatImgFile";
  121. this.btnCreatImgFile.Size = new System.Drawing.Size(69, 27);
  122. this.btnCreatImgFile.TabIndex = 1;
  123. this.btnCreatImgFile.Text = "创建图片";
  124. this.btnCreatImgFile.UseVisualStyleBackColor = true;
  125. this.btnCreatImgFile.Click += new System.EventHandler(this.btnCreatImgFile_Click);
  126. //
  127. // btnWorking
  128. //
  129. this.btnWorking.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  130. this.btnWorking.Location = new System.Drawing.Point(758, 22);
  131. this.btnWorking.Margin = new System.Windows.Forms.Padding(2);
  132. this.btnWorking.Name = "btnWorking";
  133. this.btnWorking.Size = new System.Drawing.Size(67, 27);
  134. this.btnWorking.TabIndex = 0;
  135. this.btnWorking.Text = "开始";
  136. this.btnWorking.UseVisualStyleBackColor = true;
  137. this.btnWorking.Click += new System.EventHandler(this.btnWorking_Click);
  138. //
  139. // groupBox2
  140. //
  141. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  142. | System.Windows.Forms.AnchorStyles.Left)));
  143. this.groupBox2.Controls.Add(this.controlPanel);
  144. this.groupBox2.Controls.Add(this.rdoMod2);
  145. this.groupBox2.Controls.Add(this.rdoMod1);
  146. this.groupBox2.Controls.Add(this.label1);
  147. this.groupBox2.Location = new System.Drawing.Point(9, 94);
  148. this.groupBox2.Margin = new System.Windows.Forms.Padding(2);
  149. this.groupBox2.Name = "groupBox2";
  150. this.groupBox2.Padding = new System.Windows.Forms.Padding(2);
  151. this.groupBox2.Size = new System.Drawing.Size(295, 420);
  152. this.groupBox2.TabIndex = 1;
  153. this.groupBox2.TabStop = false;
  154. this.groupBox2.Text = "参数设置";
  155. //
  156. // controlPanel
  157. //
  158. this.controlPanel.Location = new System.Drawing.Point(4, 59);
  159. this.controlPanel.Margin = new System.Windows.Forms.Padding(2);
  160. this.controlPanel.Name = "controlPanel";
  161. this.controlPanel.Size = new System.Drawing.Size(281, 350);
  162. this.controlPanel.TabIndex = 3;
  163. //
  164. // rdoMod2
  165. //
  166. this.rdoMod2.AutoSize = true;
  167. this.rdoMod2.Location = new System.Drawing.Point(164, 30);
  168. this.rdoMod2.Margin = new System.Windows.Forms.Padding(2);
  169. this.rdoMod2.Name = "rdoMod2";
  170. this.rdoMod2.Size = new System.Drawing.Size(14, 13);
  171. this.rdoMod2.TabIndex = 2;
  172. this.rdoMod2.UseVisualStyleBackColor = true;
  173. this.rdoMod2.Visible = false;
  174. this.rdoMod2.CheckedChanged += new System.EventHandler(this.rdoMod2_CheckedChanged);
  175. //
  176. // rdoMod1
  177. //
  178. this.rdoMod1.AutoSize = true;
  179. this.rdoMod1.Checked = true;
  180. this.rdoMod1.Location = new System.Drawing.Point(90, 29);
  181. this.rdoMod1.Margin = new System.Windows.Forms.Padding(2);
  182. this.rdoMod1.Name = "rdoMod1";
  183. this.rdoMod1.Size = new System.Drawing.Size(14, 13);
  184. this.rdoMod1.TabIndex = 1;
  185. this.rdoMod1.TabStop = true;
  186. this.rdoMod1.UseVisualStyleBackColor = true;
  187. this.rdoMod1.CheckedChanged += new System.EventHandler(this.rdoMod1_CheckedChanged);
  188. //
  189. // label1
  190. //
  191. this.label1.AutoSize = true;
  192. this.label1.Location = new System.Drawing.Point(16, 30);
  193. this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  194. this.label1.Name = "label1";
  195. this.label1.Size = new System.Drawing.Size(0, 12);
  196. this.label1.TabIndex = 0;
  197. //
  198. // splitContainer1
  199. //
  200. this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  201. | System.Windows.Forms.AnchorStyles.Left)
  202. | System.Windows.Forms.AnchorStyles.Right)));
  203. this.splitContainer1.Location = new System.Drawing.Point(309, 91);
  204. this.splitContainer1.Margin = new System.Windows.Forms.Padding(2);
  205. this.splitContainer1.Name = "splitContainer1";
  206. //
  207. // splitContainer1.Panel1
  208. //
  209. this.splitContainer1.Panel1.Controls.Add(this.groupBox3);
  210. //
  211. // splitContainer1.Panel2
  212. //
  213. this.splitContainer1.Panel2.Controls.Add(this.groupBox4);
  214. this.splitContainer1.Size = new System.Drawing.Size(636, 427);
  215. this.splitContainer1.SplitterDistance = 279;
  216. this.splitContainer1.SplitterWidth = 3;
  217. this.splitContainer1.TabIndex = 4;
  218. //
  219. // groupBox3
  220. //
  221. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  222. | System.Windows.Forms.AnchorStyles.Left)
  223. | System.Windows.Forms.AnchorStyles.Right)));
  224. this.groupBox3.Controls.Add(this.picPreview);
  225. this.groupBox3.Location = new System.Drawing.Point(2, 2);
  226. this.groupBox3.Margin = new System.Windows.Forms.Padding(2);
  227. this.groupBox3.Name = "groupBox3";
  228. this.groupBox3.Padding = new System.Windows.Forms.Padding(2);
  229. this.groupBox3.Size = new System.Drawing.Size(274, 422);
  230. this.groupBox3.TabIndex = 3;
  231. this.groupBox3.TabStop = false;
  232. this.groupBox3.Text = "预览";
  233. //
  234. // picPreview
  235. //
  236. this.picPreview.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  237. | System.Windows.Forms.AnchorStyles.Right)));
  238. this.picPreview.Location = new System.Drawing.Point(15, 59);
  239. this.picPreview.Margin = new System.Windows.Forms.Padding(2);
  240. this.picPreview.Name = "picPreview";
  241. this.picPreview.Size = new System.Drawing.Size(247, 338);
  242. this.picPreview.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  243. this.picPreview.TabIndex = 0;
  244. this.picPreview.TabStop = false;
  245. //
  246. // groupBox4
  247. //
  248. this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  249. | System.Windows.Forms.AnchorStyles.Left)
  250. | System.Windows.Forms.AnchorStyles.Right)));
  251. this.groupBox4.Controls.Add(this.picDepth);
  252. this.groupBox4.Location = new System.Drawing.Point(2, 2);
  253. this.groupBox4.Margin = new System.Windows.Forms.Padding(2);
  254. this.groupBox4.Name = "groupBox4";
  255. this.groupBox4.Padding = new System.Windows.Forms.Padding(2);
  256. this.groupBox4.Size = new System.Drawing.Size(355, 422);
  257. this.groupBox4.TabIndex = 4;
  258. this.groupBox4.TabStop = false;
  259. this.groupBox4.Text = "自动景深扩展";
  260. //
  261. // picDepth
  262. //
  263. this.picDepth.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  264. | System.Windows.Forms.AnchorStyles.Right)));
  265. this.picDepth.Location = new System.Drawing.Point(13, 59);
  266. this.picDepth.Margin = new System.Windows.Forms.Padding(2);
  267. this.picDepth.Name = "picDepth";
  268. this.picDepth.Size = new System.Drawing.Size(327, 338);
  269. this.picDepth.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  270. this.picDepth.TabIndex = 1;
  271. this.picDepth.TabStop = false;
  272. //
  273. // CameraAutomaticDepth
  274. //
  275. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  276. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  277. this.ClientSize = new System.Drawing.Size(953, 523);
  278. this.Controls.Add(this.splitContainer1);
  279. this.Controls.Add(this.groupBox2);
  280. this.Controls.Add(this.groupBox1);
  281. this.Margin = new System.Windows.Forms.Padding(2);
  282. this.Name = "CameraAutomaticDepth";
  283. this.Text = "自动景深扩展";
  284. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CameraAutomaticDepth_FormClosing);
  285. this.Load += new System.EventHandler(this.CameraAutomaticDepth_Load);
  286. this.Controls.SetChildIndex(this.groupBox1, 0);
  287. this.Controls.SetChildIndex(this.groupBox2, 0);
  288. this.Controls.SetChildIndex(this.splitContainer1, 0);
  289. this.groupBox1.ResumeLayout(false);
  290. this.groupBox2.ResumeLayout(false);
  291. this.groupBox2.PerformLayout();
  292. this.splitContainer1.Panel1.ResumeLayout(false);
  293. this.splitContainer1.Panel2.ResumeLayout(false);
  294. ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
  295. this.splitContainer1.ResumeLayout(false);
  296. this.groupBox3.ResumeLayout(false);
  297. ((System.ComponentModel.ISupportInitialize)(this.picPreview)).EndInit();
  298. this.groupBox4.ResumeLayout(false);
  299. ((System.ComponentModel.ISupportInitialize)(this.picDepth)).EndInit();
  300. this.ResumeLayout(false);
  301. }
  302. #endregion
  303. #region 控件
  304. private System.Windows.Forms.GroupBox groupBox1;
  305. private System.Windows.Forms.Button btnCreatImgFile;
  306. private System.Windows.Forms.Button btnWorking;
  307. private System.Windows.Forms.GroupBox groupBox2;
  308. private System.Windows.Forms.RadioButton rdoMod2;
  309. private System.Windows.Forms.RadioButton rdoMod1;
  310. private System.Windows.Forms.Label label1;
  311. private System.Windows.Forms.Panel controlPanel;
  312. private System.Windows.Forms.SplitContainer splitContainer1;
  313. private System.Windows.Forms.GroupBox groupBox3;
  314. private System.Windows.Forms.PictureBox picPreview;
  315. private System.Windows.Forms.GroupBox groupBox4;
  316. private System.Windows.Forms.PictureBox picDepth;
  317. #endregion
  318. private AppWorkspace m_appWorkspace;
  319. // 已移动次数
  320. private int m_moveTimes;
  321. // 当前位置
  322. private double m_currentStep => m_Stage.Z;
  323. private string m_picturePath = Application.StartupPath + "\\Picture\\";
  324. private TUCamera.TUCamera m_camera;
  325. private AxisController m_Stage;
  326. private ParameterOneControl m_parameterOne;
  327. private bool m_isWorking;
  328. private Mat m_matClone;
  329. private Mat[] Coll_Ori = new Mat[2];
  330. private Mat m_merge;
  331. private Button btnZClear;
  332. public CameraAutomaticDepth(AppWorkspace appWorkspace)
  333. {
  334. this.m_appWorkspace = appWorkspace;
  335. // this.DoubleBuffered = true;//设置本窗体
  336. //SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  337. //SetStyle(ControlStyles.UserPaint, true);
  338. //SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  339. //SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
  340. InitializeComponent();
  341. InitializeLanguageText();
  342. }
  343. /// <summary>
  344. /// 加载数据
  345. /// </summary>
  346. public void InitializeData()
  347. {
  348. try
  349. {
  350. m_Stage = AxisController.GetInstance();
  351. m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
  352. m_camera.m_bufHandler += CallbackDraw;
  353. m_camera.StartWaitForFrame();
  354. // 默认选中显示模式一
  355. rdoMod1.Checked = true;
  356. controlPanel.Controls.Clear();
  357. m_parameterOne = new ParameterOneControl(m_Stage);
  358. controlPanel.Controls.Add(m_parameterOne);
  359. }
  360. catch (Exception ex)
  361. {
  362. MessageBox.Show(ex.Message);
  363. }
  364. }
  365. private void CameraAutomaticDepth_Load(object sender, EventArgs e)
  366. {
  367. InitializeData();
  368. }
  369. object obj = new object();
  370. /// <summary>
  371. /// 绘制
  372. /// </summary>
  373. /// <param name="pBuf"></param>
  374. /// <param name="obj"></param>
  375. public void CallbackDraw(Bitmap frame)
  376. {
  377. m_matClone = BitmapConverter.ToMat(frame);
  378. picPreview.Image = (Image)frame.Clone();
  379. }
  380. private void rdoMod1_CheckedChanged(object sender, EventArgs e)
  381. {
  382. controlPanel.Controls.Clear();
  383. ParameterOneControl parameterOne = new ParameterOneControl(m_Stage);
  384. controlPanel.Controls.Add(parameterOne);
  385. }
  386. private void rdoMod2_CheckedChanged(object sender, EventArgs e)
  387. {
  388. controlPanel.Controls.Clear();
  389. ParameterTwoControl parameterTwo = new ParameterTwoControl();
  390. controlPanel.Controls.Add(parameterTwo);
  391. }
  392. private void CameraAutomaticDepth_FormClosing(object sender, FormClosingEventArgs e)
  393. {
  394. m_camera.m_bufHandler -= CallbackDraw;
  395. m_camera.StopWaitForFrame();
  396. }
  397. private void btnWorking_Click(object sender, EventArgs e)
  398. {
  399. m_merge = null;
  400. try
  401. {
  402. if (!m_camera.IsOpen())
  403. {
  404. MessageBox.Show(PdnResources.GetString("Menu.merafoundpleaseconfirthatthecameraisconne.Text"));
  405. return;
  406. }
  407. if (m_isWorking)
  408. {
  409. StopWorking();
  410. return;
  411. }
  412. if (m_parameterOne.StopPos == 0 || m_parameterOne.StartPos == 0)
  413. {
  414. MessageBox.Show(PdnResources.GetString("Menu.Pleasesetthestartandstoppositions2.Text"));
  415. return;
  416. }
  417. // 重新自动计算,防止没有手动点击计算
  418. m_parameterOne.Calculate();
  419. var zscanparm = m_parameterOne.ZScanParameter;
  420. m_Stage.ZScan(zscanparm.Start, zscanparm.Track, zscanparm.Times, Shooting, null, StopWorking);
  421. m_isWorking = true;
  422. btnWorking.Text = PdnResources.GetString("Menu.stop.text");
  423. m_moveTimes = 0;
  424. // 禁用控件
  425. m_parameterOne.Enabled = false;
  426. }
  427. catch (Exception ex)
  428. {
  429. MessageBox.Show(ex.Message);
  430. }
  431. }
  432. private void StopWorking()
  433. {
  434. m_Stage.FreeZ();
  435. m_isWorking = false;
  436. this.Invoke(new Action(() =>
  437. {
  438. // 更改控件状态
  439. m_parameterOne.Enabled = true;
  440. btnWorking.Text = PdnResources.GetString("Menu.Started.text");
  441. }));
  442. }
  443. int m_captureWait = 200;
  444. private void Shooting()
  445. {
  446. Thread.Sleep(m_captureWait);
  447. // 修改拍摄高度
  448. this.Invoke(new Action(() =>
  449. {
  450. m_parameterOne.updatelblHeight(m_currentStep);
  451. }));
  452. if (m_merge == null)
  453. {
  454. m_merge = m_matClone;
  455. }
  456. else
  457. {
  458. Coll_Ori[1] = m_matClone;
  459. Coll_Ori[0] = m_merge;
  460. m_merge = Merge.GetMergeMatForCamera(Coll_Ori);
  461. }
  462. picDepth.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_merge);
  463. GC.Collect();
  464. ++m_moveTimes;
  465. if (m_moveTimes == m_parameterOne.Times)
  466. {
  467. // StopWorking();
  468. return;
  469. }
  470. }
  471. #region 等待机制
  472. bool _waitFlag = false;
  473. private void ResetWait()
  474. { _waitFlag = false; }
  475. private void Wait()
  476. {
  477. _waitFlag = true;
  478. while (_waitFlag)
  479. {
  480. Thread.Sleep(100);
  481. }
  482. }
  483. #endregion
  484. private void btnCreatImgFile_Click(object sender, EventArgs e)
  485. {
  486. if (m_merge == null)
  487. {
  488. MessageBox.Show(PdnResources.GetString("Menu.ofimageshavenotyetbeengene.Text"));
  489. return;
  490. }
  491. Bitmap bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_merge);
  492. DocumentWorkspace dw = m_appWorkspace.AddNewDocumentWorkspace();
  493. Document document = Document.FromImage(bitmap);
  494. dw.Document = document;
  495. dw.xmlSaveModel = Startup.instance.ruleDB;
  496. dw.InitRulerInfo();
  497. m_appWorkspace.ActiveDocumentWorkspace = dw;
  498. }
  499. #region StageEvents
  500. public void OnUpdatePosition()
  501. {
  502. try //可能出现窗口销毁后回调
  503. {
  504. if (!this.IsDisposed)
  505. this.Invoke(new Action(() =>
  506. {
  507. m_parameterOne.PositionZ = m_Stage.Z;
  508. }));
  509. }
  510. catch { }
  511. }
  512. public void OnTimeoutConnect()
  513. {
  514. StopWorking();
  515. MessageBox.Show(PdnResources.GetString("Menu.Theconsoleresponsetimeout.Text"));
  516. }
  517. public void OnErrorSend()
  518. {
  519. StopWorking();
  520. MessageBox.Show(PdnResources.GetString("Menu.Replydataarsingerror.Text"));
  521. }
  522. #endregion
  523. private void btnZClear_Click(object sender, EventArgs e)
  524. {
  525. m_Stage.ClearPosZ();
  526. }
  527. }
  528. }