ShuLiClass.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. using CCDCount.MODEL.ConfigModel;
  2. using CCDCount.MODEL.ShuLiClass;
  3. using LogClass;
  4. using MvCameraControl;
  5. using System;
  6. using System.Collections.Concurrent;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Threading;
  12. namespace CCDCount.DLL
  13. {
  14. public class ShuLiClass
  15. {
  16. #region 变量
  17. /// <summary>
  18. /// 当活跃物体转变为历史物体时的回调事件
  19. /// </summary>
  20. public event EventHandler<ActiveObjectEventArgsClass> WorkCompleted;
  21. private List<ActiveObjectClass> activeObjects = new List<ActiveObjectClass>(); // 当前跟踪中的物体
  22. private List<ActiveObjectClass> historyActiveObjects = new List<ActiveObjectClass>(); // 历史物体
  23. private ConcurrentQueue<byte[]> ImageBytes = new ConcurrentQueue<byte[]>(); //图像数据队列
  24. private ConcurrentQueue<IImage> IFrameDatas = new ConcurrentQueue<IImage>(); //图像数据队列
  25. private Thread IdentifyImageProcessThread = null; // 识别线程
  26. private bool IsIdentify = false; //线程是否开始识别的标志
  27. private long currentLine = 0; //行数记录
  28. private ShuLiConfigClass shuLiConfig = null;// 数粒参数配置文件
  29. private List<int> ChannelsRoi = new List<int>();
  30. private int ChannelWidth = 0;//每个区域的宽度
  31. private int IdentifyImageWidth = -1;
  32. private static readonly object _lockObj = new object(); // 专用锁对象\
  33. private int ObjectNum = 0;
  34. public int ImageNum { get { return IFrameDatas.Count; } }
  35. #endregion
  36. #region 公共方法
  37. /// <summary>
  38. /// 初始化构造方法
  39. /// </summary>
  40. public ShuLiClass()
  41. {
  42. // 加载默认参数
  43. shuLiConfig = new ShuLiConfigClass()
  44. {
  45. Channel = 8,
  46. PandingCode = 2
  47. };
  48. }
  49. public ShuLiClass(ShuLiConfigClass config)
  50. {
  51. if(config.IsLoadCanfig)
  52. {
  53. // 加载传出的参数
  54. shuLiConfig = config;
  55. }
  56. else
  57. {
  58. // 加载默认参数
  59. shuLiConfig = new ShuLiConfigClass()
  60. {
  61. Channel = 8,
  62. PandingCode = 2
  63. };
  64. }
  65. }
  66. /// <summary>
  67. /// 处理图像序列的主入口
  68. /// </summary>
  69. /// <param name="image">图像像素数据</param>
  70. /// <param name="ImageWidth">图像宽</param>
  71. /// <param name="currentLine">当前行数</param>
  72. /// <returns>检测到的物体总数</returns>
  73. public bool ProcessImageSequence(IImage image)
  74. {
  75. bool result = false;
  76. for (int i = 0;i<image.Height;i++)
  77. {
  78. result = ProcessLine(image,i);
  79. currentLine += 1;
  80. }
  81. return result;
  82. }
  83. /// <summary>
  84. /// 返回最后一个历史物品
  85. /// </summary>
  86. /// <returns></returns>
  87. public ActiveObjectClass GetLastActive()
  88. {
  89. if (historyActiveObjects.Count() == 0)
  90. return null;
  91. return historyActiveObjects.Last();
  92. }
  93. /// <summary>
  94. /// 返回历史物品
  95. /// </summary>
  96. /// <returns></returns>
  97. public List<ActiveObjectClass> GetHistoryActive()
  98. {
  99. lock (_lockObj) // 加锁
  100. {
  101. return historyActiveObjects.ToList();
  102. }
  103. }
  104. /// <summary>
  105. /// 返回缓存在内存的历史物品的总数量
  106. /// </summary>
  107. /// <returns></returns>
  108. public int GetHistoryActiveNum()
  109. {
  110. lock (_lockObj) // 加锁
  111. return historyActiveObjects.Count();
  112. }
  113. /// <summary>
  114. /// 清除缓存的内存的中的历史数据
  115. /// </summary>
  116. public void ClearHistoryActive()
  117. {
  118. historyActiveObjects.Clear();
  119. }
  120. /// <summary>
  121. /// 获取历史数据中,正常数据数量
  122. /// </summary>
  123. /// <returns></returns>
  124. public int GetOkHistoryNum()
  125. {
  126. lock (_lockObj)
  127. return historyActiveObjects.Where(o=>o.StateCode == 0).Count();
  128. }
  129. /// <summary>
  130. /// 获取历史数据中,异常数据数量
  131. /// </summary>
  132. /// <returns></returns>
  133. public int GetNgHistoryNum()
  134. {
  135. lock (_lockObj)
  136. return historyActiveObjects.Where(o=>o.StateCode != 0).Count();
  137. }
  138. /// <summary>
  139. /// 开启识别
  140. /// </summary>
  141. public void StartIdentifyFuntion(int ImaageWidth)
  142. {
  143. UpdateIdentifyImageWidth(ImaageWidth);
  144. InitChannel();
  145. try
  146. {
  147. // 标志位置位true
  148. IsIdentify = true;
  149. // 打开识别线程
  150. IdentifyImageProcessThread = new Thread(IdentifyImageProcess)
  151. {
  152. Priority = ThreadPriority.Highest
  153. };
  154. IdentifyImageProcessThread.Start();
  155. }
  156. catch (Exception ex)
  157. {
  158. LOG.error("Start thread failed!, " + ex.Message);
  159. throw;
  160. }
  161. }
  162. /// <summary>
  163. /// 关闭识别
  164. /// </summary>
  165. public void StopIdentifyFuntion()
  166. {
  167. try
  168. {
  169. // 标志位设为false
  170. IsIdentify = false;
  171. if(IdentifyImageProcessThread!=null&& IdentifyImageProcessThread.IsAlive)
  172. IdentifyImageProcessThread.Join();
  173. }
  174. catch (Exception ex)
  175. {
  176. LOG.error("Stop thread failed!, " + ex.Message);
  177. throw;
  178. }
  179. }
  180. /// <summary>
  181. /// 向识别队列添加一个数据
  182. /// </summary>
  183. /// <param name="items"></param>
  184. public void SetOnceIdentifyImageData(byte[] items)
  185. {
  186. ImageBytes.Enqueue(items.Clone() as byte[]);
  187. }
  188. /// <summary>
  189. /// 向识别队列添加一个数据
  190. /// </summary>
  191. /// <param name="items"></param>
  192. public void SetOnceIdentifyImageData(IImage items)
  193. {
  194. IFrameDatas.Enqueue(items.Clone() as IImage);
  195. }
  196. /// <summary>
  197. /// 保存参数
  198. /// </summary>
  199. public void SaveConfig()
  200. {
  201. if(!Directory.Exists(".\\Config\\")) Directory.CreateDirectory(".\\Config\\");
  202. XmlStorage.SerializeToXml(shuLiConfig, ".\\Config\\ShuLiConfig.xml");
  203. }
  204. /// <summary>
  205. /// 更新检测宽度信息
  206. /// </summary>
  207. /// <param name="Width"></param>
  208. public void UpdateIdentifyImageWidth(int Width)
  209. {
  210. IdentifyImageWidth = Width;
  211. }
  212. /// <summary>
  213. /// 初始化通道划分
  214. /// </summary>
  215. /// <param name="ImageWidth"></param>
  216. public void InitChannel()
  217. {
  218. shuLiConfig.ImageWidth = IdentifyImageWidth;
  219. if (shuLiConfig.Channel > 0)
  220. {
  221. if (shuLiConfig.IsIdentifyRoiOpen)
  222. {
  223. ChannelWidth = (shuLiConfig.IdentifyStopX - shuLiConfig.IdentifyStartX) / shuLiConfig.Channel;
  224. }
  225. else
  226. {
  227. ChannelWidth = shuLiConfig.ImageWidth / shuLiConfig.Channel;
  228. }
  229. for (int i = 0; i < shuLiConfig.Channel; i++)
  230. {
  231. ChannelsRoi.Add(ChannelWidth + i * ChannelWidth);
  232. }
  233. }
  234. }
  235. /// <summary>
  236. /// 获取配置信息
  237. /// </summary>
  238. /// <returns></returns>
  239. public ShuLiConfigClass GetConfigValue()
  240. {
  241. ShuLiConfigClass result = shuLiConfig;
  242. return result;
  243. }
  244. #endregion
  245. #region 私有方法
  246. /// <summary>
  247. /// 对外通知事件
  248. /// </summary>
  249. private void OnWorkCompleted(List<ActiveObjectClass> activeObject)
  250. {
  251. ActiveObjectEventArgsClass activeObjectEventArgs = new ActiveObjectEventArgsClass(activeObject);
  252. // 触发事件
  253. WorkCompleted?.Invoke(this, activeObjectEventArgs);
  254. }
  255. /// <summary>
  256. /// 处理单行像素数据
  257. /// 返回值为false的时候无活跃物体转变为历史物体
  258. /// 返回值为true的时候有活跃物体转变为历史物体
  259. /// </summary>
  260. /// <param name="image">当前行像素数组</param>
  261. private bool ProcessLine(IImage imagedata,int RowNo)
  262. {
  263. bool result = false;
  264. // 步骤1:检测当前行的有效区域
  265. var currentRegions = FindValidRegions(imagedata,RowNo);
  266. if (currentRegions.Count == 1)
  267. {
  268. if (currentRegions[0].End - (currentRegions[0]).Start + 1 == imagedata.Width)
  269. {
  270. LOG.error("当前行有效区域为整行,检查视野和光源");
  271. return false;
  272. }
  273. }
  274. // 步骤2:处理当前行每个区域
  275. for (int i = 0; i < currentRegions.Count; i++)
  276. {
  277. var region = currentRegions[i];
  278. // 查找全部可合并的活跃物体(有重叠+在允许间隔内)
  279. var matcheds = activeObjects.Where(o =>
  280. IsOverlapping(o, region) &&
  281. (currentLine - o.LastSeenLine - 1) <= shuLiConfig.MAX_GAP).ToList();
  282. //当有多个可合并的活跃物体时,将多个物体合并
  283. if (matcheds.Count >= 2)
  284. {
  285. // 合并有效区域队列
  286. var CopeRowsData = new List<RowStartEndCol>();
  287. matcheds.ForEach(o => CopeRowsData = CopeRowsData.Concat(o.RowsData).ToList());
  288. // 合并有效区域并保存在新的区域中
  289. var MergeMatched = new ActiveObjectClass
  290. {
  291. MinStartCol = matcheds.Min(o => o.MinStartCol),
  292. MaxEndCol = matcheds.Max(o => o.MaxEndCol),
  293. StartLine = matcheds.Min(o => o.StartLine),
  294. LastSeenLine = matcheds.Max(o => o.LastSeenLine),
  295. LastSeenLineStartCol = matcheds.Min(o => o.LastSeenLineStartCol),
  296. LastSeenLineEndCol = matcheds.Max(o => o.LastSeenLineEndCol),
  297. StartCheckTime = matcheds.Min(o => o.StartCheckTime),
  298. EndCheckTime = matcheds.Max(o => o.EndCheckTime),
  299. Area = matcheds.Sum(o => o.Area),
  300. RowsData = CopeRowsData,
  301. ImageWidth = matcheds.FirstOrDefault().ImageWidth,
  302. };
  303. // 从活跃区域中删除被合并的区域
  304. matcheds.ForEach(o => activeObjects.Remove(o));
  305. // 保存新的区域到活跃区域中
  306. activeObjects.Add(MergeMatched);
  307. }
  308. // 搜获可用且可合并的活跃区域
  309. var matched = activeObjects.FirstOrDefault(o =>
  310. IsOverlapping(o, region) &&
  311. (currentLine - o.LastSeenLine - 1) <= shuLiConfig.MAX_GAP);
  312. if (matched != null)
  313. {
  314. // 合并区域:扩展物体边界并更新状态
  315. matched.MinStartCol = Math.Min(matched.MinStartCol, region.Start);
  316. matched.MaxEndCol = Math.Max(matched.MaxEndCol, region.End);
  317. matched.Area += region.End - region.Start + 1;
  318. matched.LastSeenLine = currentLine;
  319. matched.RowsData.Add(new RowStartEndCol
  320. {
  321. StartCol = region.Start,
  322. EndCol = region.End,
  323. RowsCol = currentLine,
  324. });
  325. }
  326. else
  327. {
  328. // 创建新物体(首次出现的区域)
  329. activeObjects.Add(new ActiveObjectClass
  330. {
  331. MinStartCol = region.Start,
  332. MaxEndCol = region.End,
  333. StartLine = currentLine,
  334. LastSeenLine = currentLine,
  335. LastSeenLineStartCol = region.Start,
  336. LastSeenLineEndCol = region.End,
  337. StartCheckTime = DateTime.Now,
  338. Area = region.End - region.Start + 1,
  339. ImageWidth = IdentifyImageWidth,
  340. RowsData = new List<RowStartEndCol> {
  341. new RowStartEndCol {
  342. StartCol = region.Start,
  343. EndCol = region.End,
  344. RowsCol = currentLine,
  345. }
  346. }
  347. });
  348. }
  349. }
  350. currentRegions.Clear();
  351. // 更新有效物体的最后一行的起始点
  352. activeObjects.Where(o => o.LastSeenLine == currentLine).ToList().ForEach(o => o.LastSeenLineStartCol = o.RowsData.Where(p => p.RowsCol == currentLine).Min(p => p.StartCol));
  353. activeObjects.Where(o => o.LastSeenLine == currentLine).ToList().ForEach(o => o.LastSeenLineEndCol = o.RowsData.Where(p => p.RowsCol == currentLine).Max(p => p.EndCol));
  354. // 步骤3:清理超时未更新的物体
  355. var lostObjects = activeObjects
  356. .Where(o => (currentLine - o.LastSeenLine) > shuLiConfig.MAX_GAP || (o.LastSeenLine - o.StartLine) > shuLiConfig.MAX_Idetify_Height)
  357. .ToList();
  358. List<ActiveObjectClass> OneActive = new List<ActiveObjectClass>();
  359. // 有物体转变为活跃物体,返回值转为true
  360. if (lostObjects.Count() > 0)
  361. {
  362. result = true;
  363. foreach (var item in lostObjects)
  364. {
  365. //噪点判定
  366. if (item.LastSeenLine - item.StartLine < shuLiConfig.NoiseFilter_Threshold ||
  367. item.RowsData.Max(o => o.EndCol - o.StartCol) < shuLiConfig.NoiseFilter_Threshold)
  368. continue;
  369. //转为历史物体,添加缺少的参数
  370. item.Num = ObjectNum += 1;
  371. item.ChannelNO = ActiveChannel(item);
  372. item.EndCheckTime = DateTime.Now;
  373. OneActive.Add(item);
  374. if ((item.LastSeenLine - item.StartLine) > shuLiConfig.MAX_Idetify_Height)
  375. {
  376. item.StateCode = 7;
  377. LOG.error("ShuLiClass-ProcessLine:非颗粒,视野异常");
  378. Console.WriteLine("ShuLiClass-ProcessLine:非颗粒,视野异常");
  379. }
  380. else if (shuLiConfig.PandingCode != -1)
  381. {
  382. if (item.Area < shuLiConfig.MinArea
  383. && (shuLiConfig.PandingCode == 2 || shuLiConfig.PandingCode == 1))
  384. {
  385. item.StateCode = 5;
  386. LOG.log(string.Format("颗粒编号{0}:面积过小", item.Num));
  387. Console.WriteLine("颗粒编号{0}:面积过小", item.Num);
  388. }
  389. else if (item.Area > shuLiConfig.MaxArea
  390. && (shuLiConfig.PandingCode == 2 || shuLiConfig.PandingCode == 1))
  391. {
  392. item.StateCode = 6;
  393. LOG.log(string.Format("颗粒编号{0}:面积过大", item.Num));
  394. Console.WriteLine("颗粒编号{0}:面积过大", item.Num);
  395. }
  396. else if (item.LastSeenLine - item.StartLine < shuLiConfig.MIN_OBJECT_HEIGHT
  397. && (shuLiConfig.PandingCode == 2 || shuLiConfig.PandingCode == 0))
  398. {
  399. item.StateCode = 2;
  400. LOG.log(string.Format("颗粒编号{0}:超短粒", item.Num));
  401. Console.WriteLine("颗粒编号{0}:超短粒", item.Num);
  402. }
  403. else if (item.LastSeenLine - item.StartLine > shuLiConfig.MAX_OBJECT_HEIGHT
  404. && (shuLiConfig.PandingCode == 2 || shuLiConfig.PandingCode == 0))
  405. {
  406. item.StateCode = 1;
  407. LOG.log(string.Format("颗粒编号{0}:超长粒", item.Num));
  408. Console.WriteLine("颗粒编号{0}:超长粒", item.Num);
  409. }
  410. else if (item.RowsData.Max(o => o.EndCol - o.StartCol) > shuLiConfig.MAX_OBJECT_WIDTH
  411. && (shuLiConfig.PandingCode == 2 || shuLiConfig.PandingCode == 0))
  412. {
  413. item.StateCode = 3;
  414. LOG.log(string.Format("颗粒编号{0}:超宽粒", item.Num));
  415. Console.WriteLine("颗粒编号{0}:超宽粒", item.Num);
  416. }
  417. else if (item.RowsData.Max(o => o.EndCol - o.StartCol) < shuLiConfig.MIN_OBJECT_WIDTH
  418. && (shuLiConfig.PandingCode == 2 || shuLiConfig.PandingCode == 0))
  419. {
  420. item.StateCode = 4;
  421. LOG.log(string.Format("颗粒编号{0}:超窄粒", item.Num));
  422. Console.WriteLine("颗粒编号{0}:超窄粒", item.Num);
  423. }
  424. else
  425. {
  426. item.StateCode = 0;
  427. LOG.log(string.Format("颗粒编号{0}:正常粒", item.Num));
  428. Console.WriteLine("颗粒编号{0}:正常粒", item.Num);
  429. }
  430. }
  431. }
  432. if (OneActive.Count > 0)
  433. //触发回调事件
  434. OnWorkCompleted(OneActive);
  435. }
  436. else
  437. {
  438. OneActive = null;
  439. }
  440. lock (_lockObj)
  441. {
  442. // 累加到总数并从活跃物体转移到历史物体
  443. lostObjects.Where(o => o.LastSeenLine - o.StartLine >= shuLiConfig.NoiseFilter_Threshold && o.StateCode != 7).ToList().ForEach(o => historyActiveObjects.Add(o));
  444. lostObjects.ForEach(o => activeObjects.Remove(o));
  445. lostObjects.ForEach(o => historyActiveObjects.Where(P => P.Num == o.Num - 100).ToList().ForEach(P => P.RowsData.Clear()));
  446. }
  447. return result;
  448. }
  449. /// <summary>
  450. /// 检测有效物体区域(横向连续黑色像素段)
  451. /// </summary>
  452. /// <param name="line">当前行像素数组</param>
  453. /// <returns>有效区域列表(起始/结束位置)</returns>
  454. private List<(int Start, int End)> FindValidRegions(IImage image,int RowNo)
  455. {
  456. List<(int Start, int End)> regions = new List<(int Start, int End)>();
  457. int start = -1; // 当前区域起始标记
  458. // 遍历所有像素列
  459. if (shuLiConfig.IsIdentifyRoiOpen)
  460. {
  461. for (int i = (int)image.Width*RowNo + shuLiConfig.IdentifyStartX; i < (int)image.Width * RowNo + shuLiConfig.IdentifyStopX; i++)
  462. {
  463. if (image.PixelData[i] < shuLiConfig.RegionThreshold) // 发现黑色像素
  464. {
  465. if (start == -1) start = i%(int)image.Width; // 开始新区域
  466. }
  467. else if (start != -1) // 遇到白色像素且存在进行中的区域
  468. {
  469. // 检查区域宽度是否达标
  470. if (i - start >= shuLiConfig.MIN_OBJECT_WIDTH)
  471. {
  472. regions.Add((start, (i - 1)% (int)image.Width)); // 记录有效区域
  473. }
  474. start = -1; // 重置区域标记
  475. }
  476. }
  477. }
  478. else
  479. {
  480. for (int i = (int)image.Width * RowNo; i < (int)image.Width * (RowNo+1); i++)
  481. {
  482. if (image.PixelData[i] < shuLiConfig.RegionThreshold) // 发现黑色像素
  483. {
  484. if (start == -1) start = i % (int)image.Width; // 开始新区域
  485. }
  486. else if (start != -1) // 遇到白色像素且存在进行中的区域
  487. {
  488. // 检查区域宽度是否达标
  489. if (i - start >= shuLiConfig.MIN_OBJECT_WIDTH)
  490. {
  491. regions.Add((start, (i - 1) % (int)image.Width)); // 记录有效区域
  492. }
  493. start = -1; // 重置区域标记
  494. }
  495. }
  496. }
  497. // 处理行尾未闭合的区域
  498. if (start != -1 && image.Width - start >= shuLiConfig.MIN_OBJECT_WIDTH)
  499. {
  500. regions.Add((start, (int)image.Width - 1));
  501. }
  502. return regions;
  503. }
  504. /// <summary>
  505. /// 判断区域重叠(与活跃物体的横向坐标重叠检测)
  506. /// </summary>
  507. /// <param name="obj">活跃物体</param>
  508. /// <param name="region">当前区域</param>
  509. /// <returns>是否发生重叠</returns>
  510. private bool IsOverlapping(ActiveObjectClass obj, (int Start, int End) region)
  511. {
  512. // 判断区域是否不相交的逆条件
  513. return !(region.End < obj.LastSeenLineStartCol || region.Start > obj.LastSeenLineEndCol);
  514. }
  515. /// <summary>
  516. /// 通道区域判定
  517. /// </summary>
  518. /// <param name="activeObject"></param>
  519. /// <returns></returns>
  520. private int ActiveChannel(ActiveObjectClass activeObject)
  521. {
  522. int result = -1;
  523. int StartChannel = activeObject.MinStartCol / ChannelWidth;
  524. int EndChannel = activeObject.MaxEndCol / ChannelWidth;
  525. if (StartChannel == EndChannel)
  526. {
  527. result = StartChannel;
  528. }
  529. else if (EndChannel - StartChannel>1)
  530. {
  531. Console.WriteLine("ActiveChannel-Error");
  532. //error
  533. }
  534. else
  535. {
  536. result = ChannelsRoi[StartChannel] - activeObject.MinStartCol > activeObject.MaxEndCol - ChannelsRoi[StartChannel]? StartChannel: EndChannel;
  537. }
  538. return result;
  539. }
  540. #endregion
  541. #region 线程方法
  542. /// <summary>
  543. /// 识别图像线程
  544. /// </summary>
  545. private void IdentifyImageProcess()
  546. {
  547. //Stopwatch stopwatch = Stopwatch.StartNew();
  548. IImage IframeData = null;
  549. while (IsIdentify)
  550. {
  551. //判断队列中是否有数据
  552. if (IFrameDatas.Count() > 0)
  553. {
  554. //stopwatch.Restart();
  555. IFrameDatas.TryDequeue(out IframeData);
  556. //是否成功取得数据
  557. if (IframeData != null)
  558. {
  559. //识别
  560. ProcessImageSequence(IframeData);
  561. }
  562. else
  563. {
  564. Console.WriteLine("识别数据为空");
  565. continue;
  566. }
  567. //输出耗时
  568. //stopwatch.Stop();
  569. ///Console.WriteLine("识别线程单次运行耗时:" + stopwatch.Elapsed.ToString());
  570. }
  571. else
  572. {
  573. Thread.Sleep(1);
  574. }
  575. }
  576. }
  577. #endregion
  578. }
  579. }