版博士V2.0程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

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