版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

743 rivejä
30 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. WarningEvent?.Invoke(WarningEnum.High, "加载模型报错:" + ex.Message);
  206. MessageBox.Show(ex.Message);
  207. }
  208. }
  209. /// <summary>
  210. /// 保存图片
  211. /// </summary>
  212. /// <param name="Img"></param>图片
  213. /// <param name="pictureUrl"></param>保存路径
  214. /// <param name="pictureName"></param>保存名称
  215. private void SaveImage(Bitmap Img, string pictureUrl, string pictureName)
  216. {
  217. if (!Directory.Exists(pictureUrl))
  218. {
  219. Directory.CreateDirectory(pictureUrl);
  220. }
  221. FileInfo FileUrl = new FileInfo(pictureUrl);//防止路径中有日期导致路径错误
  222. try
  223. {
  224. using (Bitmap bitmap = new Bitmap(Img))
  225. {
  226. using (MemoryStream stream = new MemoryStream())
  227. {
  228. bitmap.Save(stream, ImageFormat.Bmp);
  229. System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
  230. //img.Save(FileUrl +"\\"+ pictureName);
  231. //img.Dispose();
  232. string szURL = FileUrl + "\\" + pictureName;
  233. img.Save(szURL, ImageFormat.Bmp);
  234. img.Dispose();
  235. }
  236. }
  237. }
  238. catch (Exception)
  239. {
  240. if (Img != null)
  241. {
  242. Img.Dispose();
  243. }
  244. }
  245. }
  246. private void runStep()
  247. {
  248. while (IsInit)
  249. {
  250. if (taskList.Count < 1 || _onnxSession == null)
  251. {
  252. Thread.Sleep(5);
  253. continue;
  254. }
  255. //
  256. var task = pop();
  257. try
  258. {
  259. if (task != null)
  260. {
  261. Stopwatch stopwatch = Stopwatch.StartNew();
  262. //源图
  263. //Bitmap bmp = yolo1.Read2Bmp(file_path);
  264. //切割图像,输入图像格式14208*10640
  265. stopwatch.Start();
  266. task.bmps_cut = yolo1.OpenCVToCutsMat(task.bmp, task.cut_size.Width, task.cut_size.Height);
  267. stopwatch.Stop();
  268. task.stopwatch[0] = stopwatch.ElapsedMilliseconds;
  269. //Resize图像
  270. stopwatch.Restart();
  271. task.bmps_resize = yolo1.OpenCVToResizesMat(task.bmps_cut, task.resize.Width, task.resize.Height);
  272. stopwatch.Stop();
  273. task.stopwatch[1] = stopwatch.ElapsedMilliseconds;
  274. //预处理模型
  275. stopwatch.Restart();
  276. task.tensors = yolo1.PreprocessImageMat(task.bmps_resize);
  277. stopwatch.Stop();
  278. task.stopwatch[2] = stopwatch.ElapsedMilliseconds;
  279. lock (taskOperationList)
  280. taskOperationList.Add(task);
  281. }
  282. Thread.Sleep(5);
  283. }
  284. catch (Exception ex)
  285. {
  286. WarningEvent?.Invoke(WarningEnum.Low, "DefectLib task1 err:" + ex.Message);
  287. task.isSucceed = false;
  288. task.resultInfo = ex.Message;
  289. callback(task);
  290. }
  291. }
  292. }
  293. private void run2()
  294. {
  295. while (IsInit)
  296. {
  297. if (taskOperationList.Count < 1)
  298. {
  299. Thread.Sleep(5);
  300. continue;
  301. }
  302. //
  303. var task = pop2();
  304. int liStep = 0;
  305. try
  306. {
  307. if (task != null)
  308. {
  309. Stopwatch stopwatch = Stopwatch.StartNew();
  310. //====运行推理(必需单队列)
  311. stopwatch.Start();
  312. IDisposableReadOnlyCollection<DisposableNamedOnnxValue>[] results = yolo1.RunModlel(_onnxSession, task.tensors);
  313. liStep = 1;
  314. if (task.modelType == "rj")
  315. task.informationList = yolo1.ScreeningResults_YD_RJ(results, task.bmps_resize, task.thresholds, task.thresholdsClass, task.recAreaThreshold);
  316. else
  317. task.informationList = yolo1.ScreeningResults_YD(results, task.bmps_resize, task.thresholds, task.thresholdsClass, task.recAreaThreshold);
  318. liStep = 2;
  319. //当前大图上缺陷个数
  320. int currPicDefectCount = 0;
  321. for (int x = 0; x < task.informationList.Count(); x++)
  322. currPicDefectCount += task.informationList[x].Count();
  323. task.defectCount = currPicDefectCount;
  324. stopwatch.Stop();
  325. task.stopwatch[3] = stopwatch.ElapsedMilliseconds;
  326. liStep = 3;
  327. if (task.informationList.Count > 0)
  328. {
  329. liStep = 4;
  330. //lock (taskTagList)
  331. // taskTagList.Add(task);
  332. //====打标 ,有缺陷返回缺陷图片数组,没缺陷返回所有图片数组
  333. stopwatch.Restart();
  334. task.bmps_tag = yolo1.DrawYoloPrediction2Mat(task.bmps_cut, task.informationList, 27, SixLabors.ImageSharp.Color.OrangeRed, task.resize.Width,
  335. task.Xmm, task.Ymm, out task.defectInfor2RestorationDesk);
  336. liStep = 5;
  337. if (ConfMgr.Instance.SysConfigParams.OpenFlawDistribution)
  338. {
  339. //大图缺陷坐标转换到图纸坐标
  340. if (!string.IsNullOrWhiteSpace(task.drawingPagePath) && task.defectInfor2RestorationDesk != null && task.defectInfor2RestorationDesk.Count > 0)
  341. task.defectInfor2RestorationDeskPage = yolo1.DefectDrawGerberImage(task.drawingPagePath, task.defectInfor2RestorationDesk);
  342. }
  343. stopwatch.Stop();
  344. task.stopwatch[4] = stopwatch.ElapsedMilliseconds;
  345. liStep = 6;
  346. task.bmpCompress = yolo1.ResizesMat_4(task.bmp);
  347. task.isSucceed = true;
  348. callback(task);
  349. }
  350. else
  351. {
  352. task.isSucceed = true;
  353. callback(task);
  354. }
  355. }
  356. Thread.Sleep(5);
  357. }
  358. catch (Exception ex)
  359. {
  360. WarningEvent?.Invoke(WarningEnum.Low, $"DefectLib task2 err({liStep}):" + ex.Message);
  361. task.isSucceed = false;
  362. task.resultInfo = ex.Message;
  363. callback(task);
  364. }
  365. }
  366. }
  367. private void run3()
  368. {
  369. while (IsInit)
  370. {
  371. if (taskOperationList.Count < 1)
  372. {
  373. Thread.Sleep(5);
  374. continue;
  375. }
  376. //
  377. var task = pop2();
  378. int liStep = 0;
  379. try
  380. {
  381. if (task != null)
  382. {
  383. Stopwatch stopwatch = Stopwatch.StartNew();
  384. //====运行推理(必需单队列)
  385. stopwatch.Start();
  386. IDisposableReadOnlyCollection<DisposableNamedOnnxValue>[] results = yolo2.RunModlel(_onnxSession2, task.tensors);
  387. liStep = 1;
  388. if (task.modelType == "rj")
  389. task.informationList = yolo2.ScreeningResults_YD_RJ(results, task.bmps_resize, task.thresholds, task.thresholdsClass, task.recAreaThreshold);
  390. else
  391. task.informationList = yolo2.ScreeningResults_YD(results, task.bmps_resize, task.thresholds, task.thresholdsClass, task.recAreaThreshold);
  392. liStep = 2;
  393. //当前大图上缺陷个数
  394. int currPicDefectCount = 0;
  395. for (int x = 0; x < task.informationList.Count(); x++)
  396. currPicDefectCount += task.informationList[x].Count();
  397. task.defectCount = currPicDefectCount;
  398. stopwatch.Stop();
  399. task.stopwatch[3] = stopwatch.ElapsedMilliseconds;
  400. liStep = 3;
  401. if (task.informationList.Count > 0)
  402. {
  403. liStep = 4;
  404. //lock (taskTagList)
  405. // taskTagList.Add(task);
  406. //====打标 ,有缺陷返回缺陷图片数组,没缺陷返回所有图片数组
  407. stopwatch.Restart();
  408. task.bmps_tag = yolo2.DrawYoloPrediction2Mat(task.bmps_cut, task.informationList, 27, SixLabors.ImageSharp.Color.OrangeRed, task.resize.Width,
  409. task.Xmm, task.Ymm, out task.defectInfor2RestorationDesk);
  410. liStep = 5;
  411. if (ConfMgr.Instance.SysConfigParams.OpenFlawDistribution)
  412. {
  413. //大图缺陷坐标转换到图纸坐标
  414. if (!string.IsNullOrWhiteSpace(task.drawingPagePath) && task.defectInfor2RestorationDesk != null && task.defectInfor2RestorationDesk.Count > 0)
  415. task.defectInfor2RestorationDeskPage = yolo2.DefectDrawGerberImage(task.drawingPagePath, task.defectInfor2RestorationDesk);
  416. }
  417. stopwatch.Stop();
  418. task.stopwatch[4] = stopwatch.ElapsedMilliseconds;
  419. liStep = 6;
  420. task.bmpCompress = yolo2.ResizesMat_4(task.bmp);
  421. task.isSucceed = true;
  422. callback(task);
  423. }
  424. else
  425. {
  426. task.isSucceed = true;
  427. callback(task);
  428. }
  429. }
  430. Thread.Sleep(5);
  431. }
  432. catch (Exception ex)
  433. {
  434. WarningEvent?.Invoke(WarningEnum.Low, $"DefectLib task3 err({liStep}):" + ex.Message);
  435. task.isSucceed = false;
  436. task.resultInfo = ex.Message;
  437. callback(task);
  438. }
  439. }
  440. }
  441. private void run4()
  442. {
  443. while (IsInit)
  444. {
  445. if (taskOperationList.Count < 1)
  446. {
  447. Thread.Sleep(5);
  448. continue;
  449. }
  450. //
  451. var task = pop2();
  452. int liStep = 0;
  453. try
  454. {
  455. if (task != null)
  456. {
  457. Stopwatch stopwatch = Stopwatch.StartNew();
  458. //====运行推理(必需单队列)
  459. stopwatch.Start();
  460. IDisposableReadOnlyCollection<DisposableNamedOnnxValue>[] results = yolo3.RunModlel(_onnxSession3, task.tensors);
  461. liStep = 1;
  462. if(task.modelType == "rj")
  463. task.informationList = yolo3.ScreeningResults_YD_RJ(results, task.bmps_resize, task.thresholds, task.thresholdsClass, task.recAreaThreshold);
  464. else
  465. task.informationList = yolo3.ScreeningResults_YD(results, task.bmps_resize, task.thresholds, task.thresholdsClass, task.recAreaThreshold);
  466. liStep = 2;
  467. //当前大图上缺陷个数
  468. int currPicDefectCount = 0;
  469. for (int x = 0; x < task.informationList.Count(); x++)
  470. currPicDefectCount += task.informationList[x].Count();
  471. task.defectCount = currPicDefectCount;
  472. stopwatch.Stop();
  473. task.stopwatch[3] = stopwatch.ElapsedMilliseconds;
  474. liStep = 3;
  475. if (task.informationList.Count > 0)
  476. {
  477. liStep = 4;
  478. //lock (taskTagList)
  479. // taskTagList.Add(task);
  480. //====打标 ,有缺陷返回缺陷图片数组,没缺陷返回所有图片数组
  481. stopwatch.Restart();
  482. task.bmps_tag = yolo3.DrawYoloPrediction2Mat(task.bmps_cut, task.informationList, 27, SixLabors.ImageSharp.Color.OrangeRed, task.resize.Width,
  483. task.Xmm, task.Ymm, out task.defectInfor2RestorationDesk);
  484. liStep = 5;
  485. if (ConfMgr.Instance.SysConfigParams.OpenFlawDistribution)
  486. {
  487. //大图缺陷坐标转换到图纸坐标
  488. if (!string.IsNullOrWhiteSpace(task.drawingPagePath) && task.defectInfor2RestorationDesk != null && task.defectInfor2RestorationDesk.Count > 0)
  489. task.defectInfor2RestorationDeskPage = yolo3.DefectDrawGerberImage(task.drawingPagePath, task.defectInfor2RestorationDesk);
  490. }
  491. stopwatch.Stop();
  492. task.stopwatch[4] = stopwatch.ElapsedMilliseconds;
  493. liStep = 6;
  494. task.bmpCompress = yolo3.ResizesMat_4(task.bmp);
  495. task.isSucceed = true;
  496. callback(task);
  497. }
  498. else
  499. {
  500. task.isSucceed = true;
  501. callback(task);
  502. }
  503. }
  504. Thread.Sleep(5);
  505. }
  506. catch (Exception ex)
  507. {
  508. WarningEvent?.Invoke(WarningEnum.Low, $"DefectLib task4 err({liStep}):" + ex.Message);
  509. task.isSucceed = false;
  510. task.resultInfo = ex.Message;
  511. callback(task);
  512. }
  513. }
  514. }
  515. /// <summary>
  516. /// 已不用
  517. /// </summary>
  518. private void run5()
  519. {
  520. while (IsInit)
  521. {
  522. if (taskTagList.Count < 1)
  523. {
  524. Thread.Sleep(0);
  525. continue;
  526. }
  527. //
  528. var task = pop3();
  529. try
  530. {
  531. if (task != null)
  532. {
  533. Stopwatch stopwatch = Stopwatch.StartNew();
  534. //====打标 ,有缺陷返回缺陷图片数组,没缺陷返回所有图片数组
  535. stopwatch.Start();
  536. task.bmps_tag = yolo1.DrawYoloPrediction2Mat(task.bmps_cut, task.informationList, 27, SixLabors.ImageSharp.Color.OrangeRed, task.resize.Width,
  537. task.Xmm,task.Ymm,out task.defectInfor2RestorationDesk);
  538. stopwatch.Stop();
  539. task.stopwatch[4] = stopwatch.ElapsedMilliseconds;
  540. task.isSucceed = true;
  541. callback(task);
  542. }
  543. }
  544. catch (Exception ex)
  545. {
  546. WarningEvent?.Invoke(WarningEnum.Low, "DefectLib task3 err:" + ex.Message);
  547. task.isSucceed = false;
  548. task.resultInfo = ex.Message;
  549. callback(task);
  550. }
  551. }
  552. }
  553. private void callback(DefectTask task)
  554. {
  555. //返回成功/失败,异步调用
  556. if (task.finishEvent != null || (task.finishEvent = finishEvent) != null)
  557. //task.finishEvent.BeginInvoke(result, errInfo, res => task.finishEvent.EndInvoke(res), null);
  558. System.Threading.ThreadPool.QueueUserWorkItem(waitCallback, task);
  559. }
  560. //异步回调
  561. WaitCallback waitCallback = new WaitCallback(o =>
  562. {
  563. var task = (DefectTask)o;
  564. task.finishEvent(task);
  565. });
  566. public class DefectTask
  567. {
  568. public int stepIndex;
  569. public string processName;
  570. //2024 03 22 加入模型类型 rj pt;
  571. public string modelType;
  572. public string drawingPagePath;//图纸路径bmp
  573. //图索引
  574. public int index = 0;
  575. /// <summary>
  576. /// 绝对位置-----X2轴
  577. /// </summary>
  578. public double Xmm;
  579. /// <summary>
  580. /// 绝对位置-----Y轴
  581. /// </summary>
  582. public double Ymm;
  583. /// <summary>
  584. /// 源文件
  585. /// </summary>
  586. public Mat bmp;
  587. public Mat bmpCompress;//压缩有缺陷大图
  588. public System.Drawing.Size cut_size = new System.Drawing.Size(592, 532);
  589. public System.Drawing.Size resize = new System.Drawing.Size(224, 224);
  590. /// <summary>
  591. /// 阈值
  592. /// </summary>
  593. public float thresholds = 0.4f;
  594. /// <summary>
  595. /// 种类阈值
  596. /// </summary>
  597. public string thresholdsClass;
  598. /// <summary>
  599. /// 缺陷在面积内数量
  600. /// </summary>
  601. public Dictionary<string, float> recAreaThreshold;
  602. /// <summary>
  603. /// 完成后回调
  604. /// </summary>
  605. public Action<DefectTask> finishEvent;
  606. //
  607. public long createTime = DateTime.Now.Ticks;
  608. public DateTime nowTime;
  609. //中间变量,供step2使用
  610. public Mat[] bmps_cut;
  611. public Mat[] bmps_resize;
  612. //预处理模型
  613. public Tensor<float>[] tensors;
  614. //==结果返回
  615. public List<Dictionary<int, List<string>[]>> informationList;
  616. public int defectCount;//informationList中的缺陷数
  617. public List<List<string>> defectInfor2RestorationDesk, defectInfor2RestorationDeskPage;//打标缺陷转为图纸的坐标
  618. public Bitmap[] bmps_tag; //打标小图 //bmps_tag.count<=bmps_cut.count bmps_tag.count=informationList.count
  619. public bool isSucceed;//转换是否成功
  620. public string resultInfo = "";//成功或失败信息
  621. public long[] stopwatch = new long[5];
  622. }
  623. public void add(DefectTask task)
  624. {
  625. lock (taskList)
  626. taskList.Add(task);
  627. }
  628. /// <summary>
  629. /// 打标 返回每张图的绝对位置X,Y
  630. /// </summary>
  631. /// <param name="defectBmpIndex">缺陷小图索引</param>
  632. /// <param name="X">拍照位绝对位置-----X2轴</param>
  633. /// <param name="Y">拍照位绝对位置-----Y轴</param>
  634. /// <param name="imagewidth">裁剪小图的宽592</param>
  635. /// <param name="imageheight">裁剪小图的高532</param>
  636. public List<double> makeTag(int defectBmpIndex, double X, double Y, int imagewidth, int imageheight)
  637. {
  638. return yolo1.ImageXY(defectBmpIndex, X, Y, imagewidth, imageheight);
  639. }
  640. /// <summary>
  641. /// 用相机1查看缺陷点
  642. /// </summary>
  643. /// <param name="defectBmpIndex"></param>
  644. /// <param name="X"></param>
  645. /// <param name="Y"></param>
  646. /// <param name="imagewidth"></param>
  647. /// <param name="imageheight"></param>
  648. /// <returns></returns>
  649. public List<double> viewTag(int defectBmpIndex, double X, double Y, int imagewidth, int imageheight)
  650. {
  651. return yolo1.ImageXY2(defectBmpIndex, X, Y, imagewidth, imageheight);
  652. }
  653. private DefectTask pop()
  654. {
  655. lock (taskList)
  656. {
  657. if (taskList.Count < 1)
  658. return null;
  659. //int index = 0;// taskList.FindIndex(p => { return p.isSync; });
  660. //if (index < 0) index = 0;
  661. var task = taskList[0];
  662. taskList.RemoveAt(0);
  663. return task;
  664. }
  665. }
  666. private DefectTask pop2()
  667. {
  668. lock (taskOperationList)
  669. {
  670. if (taskOperationList.Count < 1)
  671. return null;
  672. //int index = 0;// taskList.FindIndex(p => { return p.isSync; });
  673. //if (index < 0) index = 0;
  674. var task = taskOperationList[0];
  675. taskOperationList.RemoveAt(0);
  676. return task;
  677. }
  678. }
  679. private DefectTask pop3()
  680. {
  681. lock (taskTagList)
  682. {
  683. if (taskTagList.Count < 1)
  684. return null;
  685. //int index = 0;// taskList.FindIndex(p => { return p.isSync; });
  686. //if (index < 0) index = 0;
  687. var task = taskTagList[0];
  688. taskTagList.RemoveAt(0);
  689. return task;
  690. }
  691. }
  692. public void Dispose()
  693. {
  694. stop();
  695. }
  696. }
  697. }