版博士V2.0程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

730 lines
29 KiB

  1. //#define Defect3
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using MaiMuAOI.SysCtrl;
  14. using MaiMuControl.Device;
  15. using Microsoft.ML.OnnxRuntime;
  16. using Microsoft.ML.OnnxRuntime.Tensors;
  17. using OpenCvSharp;
  18. using Yolo5;
  19. namespace MaiMuAOI.ImageProcessing
  20. {
  21. public class DefectLib : IDisposable
  22. {
  23. public Action<WarningEnum, string> WarningEvent;
  24. /// <summary>
  25. /// 检测结果JSON(原图,结果)
  26. /// </summary>
  27. public Action<DefectTask> finishEvent;
  28. /// <summary>
  29. /// 是否打开设备成功
  30. /// </summary>
  31. public bool IsInit { get; private set; } = false;
  32. //private System.Timers.Timer timer = new System.Timers.Timer();
  33. private Yolo_Class yolo1;
  34. private InferenceSession _onnxSession;
  35. private Yolo_Class yolo2;
  36. private InferenceSession _onnxSession2;
  37. private Yolo_Class yolo3;
  38. private InferenceSession _onnxSession3;
  39. //
  40. private Thread t_task, t_task_operation, t_task_operation2, t_task_operation3, t_task_tag;
  41. //=======task list
  42. private List<DefectTask> taskList = new List<DefectTask>();
  43. private List<DefectTask> taskOperationList = new List<DefectTask>();
  44. private List<DefectTask> taskTagList = new List<DefectTask>();
  45. public DefectLib()
  46. {
  47. }
  48. public bool start()
  49. {
  50. try
  51. {
  52. yolo1 = new Yolo_Class();
  53. yolo2 = new Yolo_Class();
  54. #if Defect3
  55. yolo3 = new Yolo_Class();
  56. #endif
  57. //加载模型(只加载一次即可)
  58. //string modelFilePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\DevCfg\\best.onnx";
  59. //_onnxSession = yolo1.LoadModel(modelFilePath, true);//false-CPU true-显卡
  60. IsInit = true;
  61. //timer.Elapsed += Timer_Elapsed;
  62. //timer.Interval = 100;
  63. //timer.Enabled = true;
  64. taskList.Clear();
  65. taskOperationList.Clear();
  66. taskTagList.Clear();
  67. //MessageBox.Show("11");
  68. t_task = new System.Threading.Thread(runStep);
  69. t_task.IsBackground = true;
  70. t_task.Start();
  71. //MessageBox.Show("22");
  72. t_task_operation = new System.Threading.Thread(run2);
  73. t_task_operation.IsBackground = true;
  74. t_task_operation.Start();
  75. //MessageBox.Show("33");
  76. t_task_operation2 = new System.Threading.Thread(run3);
  77. t_task_operation2.IsBackground = true;
  78. t_task_operation2.Start();
  79. //MessageBox.Show("44");
  80. #if Defect3
  81. t_task_operation3 = new System.Threading.Thread(run4);
  82. t_task_operation3.IsBackground = true;
  83. t_task_operation3.Start();
  84. #endif
  85. //MessageBox.Show("55");
  86. return true;
  87. }
  88. catch (Exception ex)
  89. {
  90. WarningEvent?.Invoke(WarningEnum.High, ex.Message);
  91. return false;
  92. }
  93. }
  94. public void stop()
  95. {
  96. if (!IsInit) return;
  97. try
  98. {
  99. IsInit = false;
  100. //timer.Elapsed -= Timer_Elapsed;
  101. //释放模型
  102. if (_onnxSession != null)
  103. {
  104. _onnxSession.Dispose();
  105. _onnxSession = null;
  106. }
  107. if (_onnxSession2 != null)
  108. {
  109. _onnxSession2.Dispose();
  110. _onnxSession2 = null;
  111. }
  112. #if Defect3
  113. if (_onnxSession3 != null)
  114. {
  115. _onnxSession3.Dispose();
  116. _onnxSession3 = null;
  117. }
  118. #endif
  119. _preLoadONNXFilePath = null;
  120. if (t_task != null)
  121. {
  122. bool b = t_task.Join(5000);
  123. if (!b) t_task.Abort();
  124. t_task = null;
  125. }
  126. if (t_task_operation != null)
  127. {
  128. bool b = t_task_operation.Join(5000);
  129. if (!b) t_task_operation.Abort();
  130. t_task_operation = null;
  131. }
  132. if (t_task_operation2 != null)
  133. {
  134. bool b = t_task_operation2.Join(5000);
  135. if (!b) t_task_operation2.Abort();
  136. t_task_operation2 = null;
  137. }
  138. #if Defect3
  139. if (t_task_operation3 != null)
  140. {
  141. bool b = t_task_operation3.Join(5000);
  142. if (!b) t_task_operation3.Abort();
  143. t_task_operation3 = null;
  144. }
  145. #endif
  146. if (t_task_tag != null)
  147. {
  148. bool b = t_task_tag.Join(5000);
  149. if (!b) t_task_tag.Abort();
  150. t_task_tag = null;
  151. }
  152. taskList.Clear();
  153. taskOperationList.Clear();
  154. taskTagList.Clear();
  155. }
  156. catch { }
  157. }
  158. private string _preLoadONNXFilePath;//记录上次成功加载的模型,不重复加载
  159. public void loadModelFile(string onnxFilePath)
  160. {
  161. try
  162. {
  163. //string modelFilePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\DevCfg\\best.onnx";
  164. //不重复加载
  165. if (!string.IsNullOrWhiteSpace(_preLoadONNXFilePath) && _preLoadONNXFilePath.ToLower() == onnxFilePath.ToLower())
  166. return;
  167. //MessageBox.Show("1");
  168. //Task.Run(async () =>
  169. //{
  170. // if (_onnxSession != null)
  171. // {
  172. // _onnxSession.Dispose();
  173. // _onnxSession = null;
  174. // }
  175. // _onnxSession = yolo1.LoadModel(onnxFilePath, true);//false-CPU true-显卡
  176. // _preLoadONNXFilePath = onnxFilePath;
  177. //});
  178. if (_onnxSession != null)
  179. {
  180. _onnxSession.Dispose();
  181. _onnxSession = null;
  182. }
  183. _onnxSession = yolo1.LoadModel(onnxFilePath, true);//false-CPU true-显卡
  184. //MessageBox.Show("2");
  185. if (_onnxSession2 != null)
  186. {
  187. _onnxSession2.Dispose();
  188. _onnxSession2 = null;
  189. }
  190. _onnxSession2 = yolo2.LoadModel(onnxFilePath, true);//false-CPU true-显卡
  191. #if Defect3
  192. //MessageBox.Show("3");
  193. if (_onnxSession3 != null)
  194. {
  195. _onnxSession3.Dispose();
  196. _onnxSession3 = null;
  197. }
  198. _onnxSession3 = yolo3.LoadModel(onnxFilePath, true);//false-CPU true-显卡
  199. #endif
  200. //MessageBox.Show("4");
  201. _preLoadONNXFilePath = onnxFilePath;
  202. }
  203. catch (Exception ex)
  204. {
  205. MessageBox.Show(ex.Message);
  206. }
  207. }
  208. /// <summary>
  209. /// 保存图片
  210. /// </summary>
  211. /// <param name="Img"></param>图片
  212. /// <param name="pictureUrl"></param>保存路径
  213. /// <param name="pictureName"></param>保存名称
  214. private void SaveImage(Bitmap Img, string pictureUrl, string pictureName)
  215. {
  216. if (!Directory.Exists(pictureUrl))
  217. {
  218. Directory.CreateDirectory(pictureUrl);
  219. }
  220. FileInfo FileUrl = new FileInfo(pictureUrl);//防止路径中有日期导致路径错误
  221. try
  222. {
  223. using (Bitmap bitmap = new Bitmap(Img))
  224. {
  225. using (MemoryStream stream = new MemoryStream())
  226. {
  227. bitmap.Save(stream, ImageFormat.Bmp);
  228. System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
  229. //img.Save(FileUrl +"\\"+ pictureName);
  230. //img.Dispose();
  231. string szURL = FileUrl + "\\" + pictureName;
  232. img.Save(szURL, ImageFormat.Bmp);
  233. img.Dispose();
  234. }
  235. }
  236. }
  237. catch (Exception)
  238. {
  239. if (Img != null)
  240. {
  241. Img.Dispose();
  242. }
  243. }
  244. }
  245. private void runStep()
  246. {
  247. while (IsInit)
  248. {
  249. if (taskList.Count < 1 || _onnxSession == null)
  250. {
  251. Thread.Sleep(5);
  252. continue;
  253. }
  254. //
  255. var task = pop();
  256. try
  257. {
  258. if (task != null)
  259. {
  260. Stopwatch stopwatch = Stopwatch.StartNew();
  261. //源图
  262. //Bitmap bmp = yolo1.Read2Bmp(file_path);
  263. //切割图像,输入图像格式14208*10640
  264. stopwatch.Start();
  265. task.bmps_cut = yolo1.OpenCVToCutsMat(task.bmp, task.cut_size.Width, task.cut_size.Height);
  266. stopwatch.Stop();
  267. task.stopwatch[0] = stopwatch.ElapsedMilliseconds;
  268. //Resize图像
  269. stopwatch.Restart();
  270. task.bmps_resize = yolo1.OpenCVToResizesMat(task.bmps_cut, task.resize.Width, task.resize.Height);
  271. stopwatch.Stop();
  272. task.stopwatch[1] = stopwatch.ElapsedMilliseconds;
  273. //预处理模型
  274. stopwatch.Restart();
  275. task.tensors = yolo1.PreprocessImageMat(task.bmps_resize);
  276. stopwatch.Stop();
  277. task.stopwatch[2] = stopwatch.ElapsedMilliseconds;
  278. lock (taskOperationList)
  279. taskOperationList.Add(task);
  280. }
  281. Thread.Sleep(5);
  282. }
  283. catch (Exception ex)
  284. {
  285. WarningEvent?.Invoke(WarningEnum.Low, "DefectLib task1 err:" + ex.Message);
  286. task.isSucceed = false;
  287. task.resultInfo = ex.Message;
  288. callback(task);
  289. }
  290. }
  291. }
  292. private void run2()
  293. {
  294. while (IsInit)
  295. {
  296. if (taskOperationList.Count < 1)
  297. {
  298. Thread.Sleep(5);
  299. continue;
  300. }
  301. //
  302. var task = pop2();
  303. int liStep = 0;
  304. try
  305. {
  306. if (task != null)
  307. {
  308. Stopwatch stopwatch = Stopwatch.StartNew();
  309. //====运行推理(必需单队列)
  310. stopwatch.Start();
  311. IDisposableReadOnlyCollection<DisposableNamedOnnxValue>[] results = yolo1.RunModlel(_onnxSession, task.tensors);
  312. liStep = 1;
  313. task.informationList = yolo1.ScreeningResults_YD(results, task.bmps_resize, task.thresholds, task.thresholdsClass, task.recAreaThreshold);
  314. liStep = 2;
  315. //当前大图上缺陷个数
  316. int currPicDefectCount = 0;
  317. for (int x = 0; x < task.informationList.Count(); x++)
  318. currPicDefectCount += task.informationList[x].Count();
  319. task.defectCount = currPicDefectCount;
  320. stopwatch.Stop();
  321. task.stopwatch[3] = stopwatch.ElapsedMilliseconds;
  322. liStep = 3;
  323. if (task.informationList.Count > 0)
  324. {
  325. liStep = 4;
  326. //lock (taskTagList)
  327. // taskTagList.Add(task);
  328. //====打标 ,有缺陷返回缺陷图片数组,没缺陷返回所有图片数组
  329. stopwatch.Restart();
  330. task.bmps_tag = yolo1.DrawYoloPrediction2Mat(task.bmps_cut, task.informationList, 27, SixLabors.ImageSharp.Color.OrangeRed, task.resize.Width,
  331. task.Xmm, task.Ymm, out task.defectInfor2RestorationDesk);
  332. liStep = 5;
  333. if (ConfMgr.Instance.SysConfigParams.OpenFlawDistribution)
  334. {
  335. //大图缺陷坐标转换到图纸坐标
  336. if (!string.IsNullOrWhiteSpace(task.drawingPagePath) && task.defectInfor2RestorationDesk != null && task.defectInfor2RestorationDesk.Count > 0)
  337. task.defectInfor2RestorationDeskPage = yolo1.DefectDrawGerberImage(task.drawingPagePath, task.defectInfor2RestorationDesk);
  338. }
  339. stopwatch.Stop();
  340. task.stopwatch[4] = stopwatch.ElapsedMilliseconds;
  341. liStep = 6;
  342. task.bmpCompress = yolo1.ResizesMat_4(task.bmp);
  343. task.isSucceed = true;
  344. callback(task);
  345. }
  346. else
  347. {
  348. task.isSucceed = true;
  349. callback(task);
  350. }
  351. }
  352. Thread.Sleep(5);
  353. }
  354. catch (Exception ex)
  355. {
  356. WarningEvent?.Invoke(WarningEnum.Low, $"DefectLib task2 err({liStep}):" + ex.Message);
  357. task.isSucceed = false;
  358. task.resultInfo = ex.Message;
  359. callback(task);
  360. }
  361. }
  362. }
  363. private void run3()
  364. {
  365. while (IsInit)
  366. {
  367. if (taskOperationList.Count < 1)
  368. {
  369. Thread.Sleep(5);
  370. continue;
  371. }
  372. //
  373. var task = pop2();
  374. int liStep = 0;
  375. try
  376. {
  377. if (task != null)
  378. {
  379. Stopwatch stopwatch = Stopwatch.StartNew();
  380. //====运行推理(必需单队列)
  381. stopwatch.Start();
  382. IDisposableReadOnlyCollection<DisposableNamedOnnxValue>[] results = yolo2.RunModlel(_onnxSession2, task.tensors);
  383. liStep = 1;
  384. task.informationList = yolo2.ScreeningResults_YD(results, task.bmps_resize, task.thresholds, task.thresholdsClass, task.recAreaThreshold);
  385. liStep = 2;
  386. //当前大图上缺陷个数
  387. int currPicDefectCount = 0;
  388. for (int x = 0; x < task.informationList.Count(); x++)
  389. currPicDefectCount += task.informationList[x].Count();
  390. task.defectCount = currPicDefectCount;
  391. stopwatch.Stop();
  392. task.stopwatch[3] = stopwatch.ElapsedMilliseconds;
  393. liStep = 3;
  394. if (task.informationList.Count > 0)
  395. {
  396. liStep = 4;
  397. //lock (taskTagList)
  398. // taskTagList.Add(task);
  399. //====打标 ,有缺陷返回缺陷图片数组,没缺陷返回所有图片数组
  400. stopwatch.Restart();
  401. task.bmps_tag = yolo2.DrawYoloPrediction2Mat(task.bmps_cut, task.informationList, 27, SixLabors.ImageSharp.Color.OrangeRed, task.resize.Width,
  402. task.Xmm, task.Ymm, out task.defectInfor2RestorationDesk);
  403. liStep = 5;
  404. if (ConfMgr.Instance.SysConfigParams.OpenFlawDistribution)
  405. {
  406. //大图缺陷坐标转换到图纸坐标
  407. if (!string.IsNullOrWhiteSpace(task.drawingPagePath) && task.defectInfor2RestorationDesk != null && task.defectInfor2RestorationDesk.Count > 0)
  408. task.defectInfor2RestorationDeskPage = yolo2.DefectDrawGerberImage(task.drawingPagePath, task.defectInfor2RestorationDesk);
  409. }
  410. stopwatch.Stop();
  411. task.stopwatch[4] = stopwatch.ElapsedMilliseconds;
  412. liStep = 6;
  413. task.bmpCompress = yolo2.ResizesMat_4(task.bmp);
  414. task.isSucceed = true;
  415. callback(task);
  416. }
  417. else
  418. {
  419. task.isSucceed = true;
  420. callback(task);
  421. }
  422. }
  423. Thread.Sleep(5);
  424. }
  425. catch (Exception ex)
  426. {
  427. WarningEvent?.Invoke(WarningEnum.Low, $"DefectLib task3 err({liStep}):" + ex.Message);
  428. task.isSucceed = false;
  429. task.resultInfo = ex.Message;
  430. callback(task);
  431. }
  432. }
  433. }
  434. private void run4()
  435. {
  436. while (IsInit)
  437. {
  438. if (taskOperationList.Count < 1)
  439. {
  440. Thread.Sleep(5);
  441. continue;
  442. }
  443. //
  444. var task = pop2();
  445. int liStep = 0;
  446. try
  447. {
  448. if (task != null)
  449. {
  450. Stopwatch stopwatch = Stopwatch.StartNew();
  451. //====运行推理(必需单队列)
  452. stopwatch.Start();
  453. IDisposableReadOnlyCollection<DisposableNamedOnnxValue>[] results = yolo3.RunModlel(_onnxSession3, task.tensors);
  454. liStep = 1;
  455. task.informationList = yolo3.ScreeningResults_YD(results, task.bmps_resize, task.thresholds, task.thresholdsClass, task.recAreaThreshold);
  456. liStep = 2;
  457. //当前大图上缺陷个数
  458. int currPicDefectCount = 0;
  459. for (int x = 0; x < task.informationList.Count(); x++)
  460. currPicDefectCount += task.informationList[x].Count();
  461. task.defectCount = currPicDefectCount;
  462. stopwatch.Stop();
  463. task.stopwatch[3] = stopwatch.ElapsedMilliseconds;
  464. liStep = 3;
  465. if (task.informationList.Count > 0)
  466. {
  467. liStep = 4;
  468. //lock (taskTagList)
  469. // taskTagList.Add(task);
  470. //====打标 ,有缺陷返回缺陷图片数组,没缺陷返回所有图片数组
  471. stopwatch.Restart();
  472. task.bmps_tag = yolo3.DrawYoloPrediction2Mat(task.bmps_cut, task.informationList, 27, SixLabors.ImageSharp.Color.OrangeRed, task.resize.Width,
  473. task.Xmm, task.Ymm, out task.defectInfor2RestorationDesk);
  474. liStep = 5;
  475. if (ConfMgr.Instance.SysConfigParams.OpenFlawDistribution)
  476. {
  477. //大图缺陷坐标转换到图纸坐标
  478. if (!string.IsNullOrWhiteSpace(task.drawingPagePath) && task.defectInfor2RestorationDesk != null && task.defectInfor2RestorationDesk.Count > 0)
  479. task.defectInfor2RestorationDeskPage = yolo3.DefectDrawGerberImage(task.drawingPagePath, task.defectInfor2RestorationDesk);
  480. }
  481. stopwatch.Stop();
  482. task.stopwatch[4] = stopwatch.ElapsedMilliseconds;
  483. liStep = 6;
  484. task.bmpCompress = yolo3.ResizesMat_4(task.bmp);
  485. task.isSucceed = true;
  486. callback(task);
  487. }
  488. else
  489. {
  490. task.isSucceed = true;
  491. callback(task);
  492. }
  493. }
  494. Thread.Sleep(5);
  495. }
  496. catch (Exception ex)
  497. {
  498. WarningEvent?.Invoke(WarningEnum.Low, $"DefectLib task4 err({liStep}):" + ex.Message);
  499. task.isSucceed = false;
  500. task.resultInfo = ex.Message;
  501. callback(task);
  502. }
  503. }
  504. }
  505. /// <summary>
  506. /// 已不用
  507. /// </summary>
  508. private void run5()
  509. {
  510. while (IsInit)
  511. {
  512. if (taskTagList.Count < 1)
  513. {
  514. Thread.Sleep(0);
  515. continue;
  516. }
  517. //
  518. var task = pop3();
  519. try
  520. {
  521. if (task != null)
  522. {
  523. Stopwatch stopwatch = Stopwatch.StartNew();
  524. //====打标 ,有缺陷返回缺陷图片数组,没缺陷返回所有图片数组
  525. stopwatch.Start();
  526. task.bmps_tag = yolo1.DrawYoloPrediction2Mat(task.bmps_cut, task.informationList, 27, SixLabors.ImageSharp.Color.OrangeRed, task.resize.Width,
  527. task.Xmm,task.Ymm,out task.defectInfor2RestorationDesk);
  528. stopwatch.Stop();
  529. task.stopwatch[4] = stopwatch.ElapsedMilliseconds;
  530. task.isSucceed = true;
  531. callback(task);
  532. }
  533. }
  534. catch (Exception ex)
  535. {
  536. WarningEvent?.Invoke(WarningEnum.Low, "DefectLib task3 err:" + ex.Message);
  537. task.isSucceed = false;
  538. task.resultInfo = ex.Message;
  539. callback(task);
  540. }
  541. }
  542. }
  543. private void callback(DefectTask task)
  544. {
  545. //返回成功/失败,异步调用
  546. if (task.finishEvent != null || (task.finishEvent = finishEvent) != null)
  547. //task.finishEvent.BeginInvoke(result, errInfo, res => task.finishEvent.EndInvoke(res), null);
  548. System.Threading.ThreadPool.QueueUserWorkItem(waitCallback, task);
  549. }
  550. //异步回调
  551. WaitCallback waitCallback = new WaitCallback(o =>
  552. {
  553. var task = (DefectTask)o;
  554. task.finishEvent(task);
  555. });
  556. public class DefectTask
  557. {
  558. public int stepIndex;
  559. public string processName;
  560. public string drawingPagePath;//图纸路径bmp
  561. //图索引
  562. public int index = 0;
  563. /// <summary>
  564. /// 绝对位置-----X2轴
  565. /// </summary>
  566. public double Xmm;
  567. /// <summary>
  568. /// 绝对位置-----Y轴
  569. /// </summary>
  570. public double Ymm;
  571. /// <summary>
  572. /// 源文件
  573. /// </summary>
  574. public Mat bmp;
  575. public Mat bmpCompress;//压缩有缺陷大图
  576. public System.Drawing.Size cut_size = new System.Drawing.Size(592, 532);
  577. public System.Drawing.Size resize = new System.Drawing.Size(224, 224);
  578. /// <summary>
  579. /// 阈值
  580. /// </summary>
  581. public float thresholds = 0.4f;
  582. /// <summary>
  583. /// 种类阈值
  584. /// </summary>
  585. public string thresholdsClass;
  586. /// <summary>
  587. /// 缺陷在面积内数量
  588. /// </summary>
  589. public Dictionary<string, float> recAreaThreshold;
  590. /// <summary>
  591. /// 完成后回调
  592. /// </summary>
  593. public Action<DefectTask> finishEvent;
  594. //
  595. public long createTime = DateTime.Now.Ticks;
  596. public DateTime nowTime;
  597. //中间变量,供step2使用
  598. public Mat[] bmps_cut;
  599. public Mat[] bmps_resize;
  600. //预处理模型
  601. public Tensor<float>[] tensors;
  602. //==结果返回
  603. public List<Dictionary<int, List<string>[]>> informationList;
  604. public int defectCount;//informationList中的缺陷数
  605. public List<List<string>> defectInfor2RestorationDesk, defectInfor2RestorationDeskPage;//打标缺陷转为图纸的坐标
  606. public Bitmap[] bmps_tag; //打标小图 //bmps_tag.count<=bmps_cut.count bmps_tag.count=informationList.count
  607. public bool isSucceed;//转换是否成功
  608. public string resultInfo = "";//成功或失败信息
  609. public long[] stopwatch = new long[5];
  610. }
  611. public void add(DefectTask task)
  612. {
  613. lock (taskList)
  614. taskList.Add(task);
  615. }
  616. /// <summary>
  617. /// 打标 返回每张图的绝对位置X,Y
  618. /// </summary>
  619. /// <param name="defectBmpIndex">缺陷小图索引</param>
  620. /// <param name="X">拍照位绝对位置-----X2轴</param>
  621. /// <param name="Y">拍照位绝对位置-----Y轴</param>
  622. /// <param name="imagewidth">裁剪小图的宽592</param>
  623. /// <param name="imageheight">裁剪小图的高532</param>
  624. public List<double> makeTag(int defectBmpIndex, double X, double Y, int imagewidth, int imageheight)
  625. {
  626. return yolo1.ImageXY(defectBmpIndex, X, Y, imagewidth, imageheight);
  627. }
  628. /// <summary>
  629. /// 用相机1查看缺陷点
  630. /// </summary>
  631. /// <param name="defectBmpIndex"></param>
  632. /// <param name="X"></param>
  633. /// <param name="Y"></param>
  634. /// <param name="imagewidth"></param>
  635. /// <param name="imageheight"></param>
  636. /// <returns></returns>
  637. public List<double> viewTag(int defectBmpIndex, double X, double Y, int imagewidth, int imageheight)
  638. {
  639. return yolo1.ImageXY2(defectBmpIndex, X, Y, imagewidth, imageheight);
  640. }
  641. private DefectTask pop()
  642. {
  643. lock (taskList)
  644. {
  645. if (taskList.Count < 1)
  646. return null;
  647. //int index = 0;// taskList.FindIndex(p => { return p.isSync; });
  648. //if (index < 0) index = 0;
  649. var task = taskList[0];
  650. taskList.RemoveAt(0);
  651. return task;
  652. }
  653. }
  654. private DefectTask pop2()
  655. {
  656. lock (taskOperationList)
  657. {
  658. if (taskOperationList.Count < 1)
  659. return null;
  660. //int index = 0;// taskList.FindIndex(p => { return p.isSync; });
  661. //if (index < 0) index = 0;
  662. var task = taskOperationList[0];
  663. taskOperationList.RemoveAt(0);
  664. return task;
  665. }
  666. }
  667. private DefectTask pop3()
  668. {
  669. lock (taskTagList)
  670. {
  671. if (taskTagList.Count < 1)
  672. return null;
  673. //int index = 0;// taskList.FindIndex(p => { return p.isSync; });
  674. //if (index < 0) index = 0;
  675. var task = taskTagList[0];
  676. taskTagList.RemoveAt(0);
  677. return task;
  678. }
  679. }
  680. public void Dispose()
  681. {
  682. stop();
  683. }
  684. }
  685. }