MainWindow.xaml.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Threading;
  4. using System.Windows.Media.Imaging;
  5. using System.Collections.Generic;
  6. using System.Collections.Concurrent;
  7. using System.Threading.Tasks;
  8. using System.Drawing;
  9. using System.Drawing.Imaging;
  10. using Microsoft.Win32;
  11. using System.Threading;
  12. using System.Diagnostics;
  13. using Accord.Video.FFMPEG;
  14. using System.IO;
  15. using System.Runtime.InteropServices;
  16. using Accord.Video.DirectShow;
  17. using Accord.Video;
  18. using System.Windows.Media;
  19. using PixelFormat = System.Drawing.Imaging.PixelFormat;
  20. using Color = System.Drawing.Color;
  21. using AI.Common.Implements;
  22. using AI.Common.Interface;
  23. using YOLOInstanceSegProcessLib;
  24. using Rect = AI.Common.Interface.Rect;
  25. namespace YOLOInstanceSegDemo
  26. {
  27. /// <summary>
  28. /// MainWindow.xaml 的交互逻辑
  29. /// </summary>
  30. public partial class MainWindow : Window
  31. {
  32. private IInferenceNetwork _inferNet = null;
  33. private BitmapImage _origImg = null;
  34. private BitmapImage _dstImg = null;
  35. private int _doneImageNum = 0;
  36. private volatile bool _isCropped = false;
  37. private Stopwatch _stopWatch = new Stopwatch();
  38. private LesionSegImg _LesionDetectSeg;
  39. int coreCount = Environment.ProcessorCount * 2;
  40. int numCPU;
  41. private volatile bool _enableAI = true;
  42. private volatile bool _continuouslyDetecting = false;
  43. List<DetectedObject> inferResult = new List<DetectedObject>();
  44. int oriWidth = 0;
  45. int oriHeight = 0;
  46. private readonly object _videoReaderLocker = new object();
  47. private VideoFileReader _videoReader;
  48. private volatile int _displayCount = 0;
  49. private ManualResetEvent _playEvent = new ManualResetEvent(false);
  50. private VideoCaptureDevice _videoCapture;
  51. /// <summary>
  52. /// 用于RawImage和Bitmap之间进行转换的帮助类
  53. /// </summary>
  54. public static class RawImageShowUtils
  55. {
  56. /// <summary>
  57. /// 将System.Drawimg.Bitmap转为RawImage
  58. /// </summary>
  59. /// <param name="image"></param>
  60. /// <param name="keepChannel"></param>
  61. /// <returns></returns>
  62. public static RawImage BitmapToRawImage(Bitmap image, bool keepColorType = false)
  63. {
  64. int width = image.Width;
  65. int height = image.Height;
  66. PixelFormat pixelFormat = image.PixelFormat;
  67. if (pixelFormat != PixelFormat.Format24bppRgb && pixelFormat != PixelFormat.Format32bppArgb
  68. && pixelFormat != PixelFormat.Format8bppIndexed && pixelFormat != PixelFormat.Format16bppGrayScale)
  69. {
  70. throw new Exception("Unexpected image pixel format:" + pixelFormat);
  71. }
  72. EnumColorType origColorType = EnumColorType.Gray8;
  73. int origBytesPerPixel = 1;
  74. if (pixelFormat == PixelFormat.Format8bppIndexed)
  75. {
  76. origColorType = EnumColorType.Gray8;
  77. origBytesPerPixel = 1;
  78. }
  79. else if (pixelFormat == PixelFormat.Format16bppGrayScale)
  80. {
  81. origColorType = EnumColorType.Gray16;
  82. origBytesPerPixel = 2;
  83. }
  84. else if (pixelFormat == PixelFormat.Format24bppRgb)
  85. {
  86. // 注意Bitmap里的24bppRgb其实通道顺序是BGR
  87. origColorType = EnumColorType.Bgr;
  88. origBytesPerPixel = 3;
  89. }
  90. else
  91. {
  92. // 注意Bitmap里的32Argb其实通道顺序是Bgra
  93. origColorType = EnumColorType.Bgra;
  94. origBytesPerPixel = 4;
  95. }
  96. EnumColorType dstColorType;
  97. int dstBytesPerPixel;
  98. if (keepColorType)
  99. {
  100. dstColorType = origColorType;
  101. dstBytesPerPixel = origBytesPerPixel;
  102. }
  103. else
  104. {
  105. // 如果没有指定要keepColorType的话,默认都转成BGR
  106. dstColorType = EnumColorType.Bgr;
  107. dstBytesPerPixel = 3;
  108. }
  109. var bmData = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, pixelFormat);
  110. byte[] dstDataArray = new byte[width * height * dstBytesPerPixel];
  111. unsafe
  112. {
  113. int stride = bmData.Stride;
  114. int dstStride = width * dstBytesPerPixel;
  115. IntPtr ptr = bmData.Scan0;
  116. IntPtr ptrH, ptrW;
  117. // 原图和目标图的ColorType相同
  118. if (origColorType == dstColorType)
  119. {
  120. for (int nh = 0; nh < height; nh++)
  121. {
  122. ptrH = IntPtr.Add(ptr, nh * stride);
  123. Marshal.Copy(ptrH, dstDataArray, nh * dstStride, dstStride);
  124. }
  125. }
  126. // 原图和目标图的ColorType不同
  127. else
  128. {
  129. // 如果原图是8位灰度图
  130. if (origColorType == EnumColorType.Gray8)
  131. {
  132. if (dstColorType == EnumColorType.Gray16)
  133. {
  134. byte gray;
  135. int dstOffset;
  136. for (int nh = 0; nh < height; nh++)
  137. {
  138. ptrH = IntPtr.Add(ptr, nh * stride);
  139. for (int nw = 0; nw < width; nw++)
  140. {
  141. ptrW = IntPtr.Add(ptrH, nw * origBytesPerPixel);
  142. gray = Marshal.ReadByte(ptrW);
  143. dstOffset = nh * dstStride + nw * dstBytesPerPixel;
  144. dstDataArray[dstOffset] = gray;
  145. // 高位为0,因此不用赋值
  146. }
  147. }
  148. }
  149. else
  150. {
  151. byte gray;
  152. int dstOffset;
  153. for (int nh = 0; nh < height; nh++)
  154. {
  155. ptrH = IntPtr.Add(ptr, nh * stride);
  156. for (int nw = 0; nw < width; nw++)
  157. {
  158. ptrW = IntPtr.Add(ptrH, nw * origBytesPerPixel);
  159. gray = Marshal.ReadByte(ptrW);
  160. dstOffset = nh * dstStride + nw * dstBytesPerPixel;
  161. dstDataArray[dstOffset] = gray;
  162. dstDataArray[dstOffset + 1] = gray;
  163. dstDataArray[dstOffset + 2] = gray;
  164. }
  165. }
  166. if (dstColorType == EnumColorType.Bgra)
  167. {
  168. for (int nh = 0; nh < height; nh++)
  169. {
  170. for (int nw = 0; nw < width; nw++)
  171. {
  172. dstOffset = nh * dstStride + nw * dstBytesPerPixel;
  173. dstDataArray[dstOffset + 3] = 255;
  174. }
  175. }
  176. }
  177. }
  178. }
  179. // 如果原图是BGR彩色图
  180. if (origColorType == EnumColorType.Bgr)
  181. {
  182. if (dstColorType == EnumColorType.Gray8 || dstColorType == EnumColorType.Gray16)
  183. {
  184. byte red, green, blue, gray;
  185. int dstOffset;
  186. for (int nh = 0; nh < height; nh++)
  187. {
  188. ptrH = IntPtr.Add(ptr, nh * stride);
  189. for (int nw = 0; nw < width; nw++)
  190. {
  191. ptrW = IntPtr.Add(ptrH, nw * origBytesPerPixel);
  192. blue = Marshal.ReadByte(ptrW);
  193. ptrW = IntPtr.Add(ptrW, 1);
  194. green = Marshal.ReadByte(ptrW);
  195. ptrW = IntPtr.Add(ptrW, 1);
  196. red = Marshal.ReadByte(ptrW);
  197. gray = RawImage.PixelRGBToGray(red, green, blue);
  198. dstOffset = nh * dstStride + nw * dstBytesPerPixel;
  199. dstDataArray[dstOffset] = gray;
  200. }
  201. }
  202. }
  203. if (dstColorType == EnumColorType.Bgra)
  204. {
  205. int dstOffset;
  206. for (int nh = 0; nh < height; nh++)
  207. {
  208. ptrH = IntPtr.Add(ptr, nh * stride);
  209. for (int nw = 0; nw < width; nw++)
  210. {
  211. ptrW = IntPtr.Add(ptrH, nw * origBytesPerPixel);
  212. dstOffset = nh * dstStride + nw * dstBytesPerPixel;
  213. Marshal.Copy(ptrW, dstDataArray, dstOffset, 3);
  214. dstDataArray[dstOffset + 3] = 255;
  215. }
  216. }
  217. }
  218. }
  219. // 如果原图是BGRA彩色图
  220. if (origColorType == EnumColorType.Bgra)
  221. {
  222. if (dstColorType == EnumColorType.Gray8 || dstColorType == EnumColorType.Gray16)
  223. {
  224. byte red, green, blue, gray;
  225. int dstOffset;
  226. for (int nh = 0; nh < height; nh++)
  227. {
  228. ptrH = IntPtr.Add(ptr, nh * stride);
  229. for (int nw = 0; nw < width; nw++)
  230. {
  231. ptrW = IntPtr.Add(ptrH, nw * origBytesPerPixel);
  232. blue = Marshal.ReadByte(ptrW);
  233. ptrW = IntPtr.Add(ptrW, 1);
  234. green = Marshal.ReadByte(ptrW);
  235. ptrW = IntPtr.Add(ptrW, 1);
  236. red = Marshal.ReadByte(ptrW);
  237. gray = RawImage.PixelRGBToGray(red, green, blue);
  238. dstOffset = nh * dstStride + nw * dstBytesPerPixel;
  239. dstDataArray[dstOffset] = gray;
  240. }
  241. }
  242. }
  243. if (dstColorType == EnumColorType.Bgr)
  244. {
  245. int dstOffset;
  246. for (int nh = 0; nh < height; nh++)
  247. {
  248. ptrH = IntPtr.Add(ptr, nh * stride);
  249. for (int nw = 0; nw < width; nw++)
  250. {
  251. ptrW = IntPtr.Add(ptrH, nw * origBytesPerPixel);
  252. dstOffset = nh * dstStride + nw * dstBytesPerPixel;
  253. Marshal.Copy(ptrW, dstDataArray, dstOffset, 3);
  254. }
  255. }
  256. }
  257. }
  258. }
  259. }
  260. image.UnlockBits(bmData);
  261. return new RawImage(dstDataArray, width, height, dstColorType);
  262. }
  263. /// <summary>
  264. /// 将RawImage转为System.Drawing.Bitmap
  265. /// </summary>
  266. /// <param name="image"></param>
  267. /// <returns></returns>
  268. public static Bitmap RawImageToBitmap(RawImage image)
  269. {
  270. int width = image.Width;
  271. int height = image.Height;
  272. EnumColorType colorType = image.ColorType;
  273. PixelFormat pixelFormat;
  274. EnumColorType dstColorType;
  275. IRawImage clonedImage;
  276. switch (colorType)
  277. {
  278. case EnumColorType.Gray8:
  279. clonedImage = image;
  280. pixelFormat = PixelFormat.Format8bppIndexed;
  281. dstColorType = EnumColorType.Gray8;
  282. break;
  283. case EnumColorType.Gray16:
  284. clonedImage = image;
  285. pixelFormat = PixelFormat.Format16bppGrayScale;
  286. dstColorType = EnumColorType.Gray16;
  287. break;
  288. case EnumColorType.GrayF32:
  289. clonedImage = image.Clone(EnumColorType.Gray8);
  290. pixelFormat = PixelFormat.Format8bppIndexed;
  291. dstColorType = EnumColorType.Gray8;
  292. break;
  293. case EnumColorType.Bgr:
  294. clonedImage = image;
  295. pixelFormat = PixelFormat.Format24bppRgb;
  296. dstColorType = EnumColorType.Bgr;
  297. break;
  298. case EnumColorType.Rgb:
  299. clonedImage = image.Clone(EnumColorType.Bgr);
  300. pixelFormat = PixelFormat.Format24bppRgb;
  301. dstColorType = EnumColorType.Bgr;
  302. break;
  303. case EnumColorType.Bgra:
  304. clonedImage = image;
  305. pixelFormat = PixelFormat.Format32bppArgb;
  306. dstColorType = EnumColorType.Bgra;
  307. break;
  308. case EnumColorType.Rgba:
  309. clonedImage = image.Clone(EnumColorType.Bgra);
  310. pixelFormat = PixelFormat.Format32bppArgb;
  311. dstColorType = EnumColorType.Bgra;
  312. break;
  313. default:
  314. throw new ArgumentOutOfRangeException("Unexpected image.colorType.");
  315. }
  316. Bitmap dstBmp = new Bitmap(width, height, pixelFormat);
  317. var bmData = dstBmp.LockBits(new System.Drawing.Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, pixelFormat);
  318. unsafe
  319. {
  320. int stride = bmData.Stride;
  321. IntPtr ptr = bmData.Scan0;
  322. byte[] dataBuffer = clonedImage.DataBuffer;
  323. int bytePerPixel = clonedImage.BytesPerPixel;
  324. if (stride == width * bytePerPixel)
  325. {
  326. Marshal.Copy(dataBuffer, 0, ptr, width * height * bytePerPixel);
  327. }
  328. else
  329. {
  330. IntPtr ptrDst;
  331. for (int ni = 0; ni < height; ni++)
  332. {
  333. ptrDst = IntPtr.Add(ptr, ni * stride);
  334. Marshal.Copy(dataBuffer, ni * width * bytePerPixel, ptrDst, width * bytePerPixel);
  335. }
  336. }
  337. }
  338. dstBmp.UnlockBits(bmData);
  339. // 灰度图像需要写调色板
  340. if (dstColorType == EnumColorType.Gray8)
  341. {
  342. var palette = dstBmp.Palette;
  343. for (int ni = 0; ni < 256; ni++)
  344. {
  345. palette.Entries[ni] = Color.FromArgb(ni, ni, ni);
  346. }
  347. dstBmp.Palette = palette;
  348. }
  349. return dstBmp;
  350. }
  351. /// <summary>
  352. /// 将Bitmap转换为BitmapImage
  353. /// </summary>
  354. /// <param name="img"></param>
  355. /// <returns></returns>
  356. public static BitmapImage BitmapToBitmapImage(Bitmap img)
  357. {
  358. BitmapImage bmpimg = new BitmapImage();
  359. using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
  360. {
  361. img.Save(ms, ImageFormat.Png);
  362. bmpimg.BeginInit();
  363. bmpimg.StreamSource = ms;
  364. bmpimg.CacheOption = BitmapCacheOption.OnLoad;
  365. bmpimg.EndInit();
  366. bmpimg.Freeze();
  367. ms.Dispose();
  368. }
  369. return bmpimg;
  370. }
  371. }
  372. public MainWindow()
  373. {
  374. InitializeComponent();
  375. try
  376. {
  377. numCPU = Convert.ToInt32(TextBoxCPU.Text);
  378. if (numCPU <= 0 || numCPU > coreCount)
  379. throw new Exception("CPU数目设置错误");
  380. }
  381. catch (Exception excep)
  382. {
  383. MessageBox.Show("CPU数目设置错误,只能为正整数且小于本机CPU线程总数!");
  384. return;
  385. }
  386. try
  387. {
  388. string netDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Networks");
  389. _LesionDetectSeg = new LesionSegImg(numCPU, netDir);
  390. }
  391. catch (Exception excep)
  392. {
  393. MessageBox.Show("doMyocardialSegment失败!");
  394. return;
  395. }
  396. }
  397. private void OnBtnTestClicked(object sender, RoutedEventArgs e)
  398. {
  399. StopPlay();
  400. try
  401. {
  402. OpenFileDialog openFileDialog = new OpenFileDialog
  403. {
  404. Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg;*.avi;*.mp4",
  405. Multiselect = false,
  406. Title = "选择一幅或多幅图",
  407. };
  408. if (openFileDialog.ShowDialog() == true)
  409. {
  410. var fileName = openFileDialog.FileName;
  411. var fileExtension = Path.GetExtension(fileName);
  412. if (fileExtension == ".png" || fileExtension == ".jpg" || fileExtension == ".bmp" || fileExtension == ".jpeg")
  413. {
  414. var bitmap = new Bitmap(fileName);
  415. if (_enableAI)
  416. {
  417. DoImgTest(bitmap);
  418. }
  419. MyImageCanvas.UpdateImage(bitmap);
  420. bitmap.Dispose();
  421. }
  422. else
  423. {
  424. long frameCount;
  425. lock (_videoReaderLocker)
  426. {
  427. _videoReader = new VideoFileReader();
  428. _videoReader.Open(fileName);
  429. frameCount = _videoReader.FrameCount;
  430. }
  431. _displayCount = 0;
  432. _playEvent.Reset();
  433. Task.Run(() =>
  434. {
  435. _continuouslyDetecting = true;
  436. bool breakFlag = false;
  437. while (!_playEvent.WaitOne(1) && !breakFlag)
  438. {
  439. for (var ni = 0; ni < frameCount; ni++)
  440. {
  441. if (_playEvent.WaitOne(1))
  442. {
  443. breakFlag = true;
  444. break;
  445. }
  446. Bitmap bitmap;
  447. lock (_videoReaderLocker)
  448. {
  449. bitmap = _videoReader.ReadVideoFrame(ni);
  450. }
  451. _displayCount++;
  452. //Console.WriteLine(_displayCount);
  453. // Thread.Sleep(1000);
  454. if (_enableAI)
  455. {
  456. DoImgTest(bitmap);
  457. }
  458. // 更新显示图像
  459. MyImageCanvas.UpdateImage(bitmap);
  460. bitmap.Dispose();
  461. if (_playEvent.WaitOne(0))
  462. {
  463. breakFlag = true;
  464. break;
  465. }
  466. }
  467. }
  468. _continuouslyDetecting = false;
  469. });
  470. VideoFileReader videoReader = new VideoFileReader();
  471. videoReader.Open(fileName);
  472. int totalCount = (int)videoReader.FrameCount;
  473. videoReader.Close();
  474. for (int ni = 0; ni < totalCount; ni++)
  475. {
  476. videoReader.Open(fileName);
  477. videoReader.Close();
  478. }
  479. videoReader.Dispose();
  480. }
  481. }
  482. }
  483. catch (Exception excep)
  484. {
  485. MessageBox.Show("加载测试图片时出错:" + excep);
  486. }
  487. }
  488. private void DoImgTest(Bitmap bmp)
  489. {
  490. try
  491. {
  492. RawImage rawImg = RawImageShowUtils.BitmapToRawImage(bmp);
  493. _stopWatch.Restart();
  494. inferResult = _LesionDetectSeg.ProcessLesionSegImg(rawImg, _isCropped);
  495. // inferResult = new List<DetectedObject>();
  496. long inferTime = _stopWatch.ElapsedMilliseconds;
  497. _stopWatch.Stop();
  498. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  499. {
  500. ForwardTime.Text = inferTime.ToString();
  501. }));
  502. using (var g = Graphics.FromImage(bmp))
  503. {
  504. System.Drawing.Brush brush = System.Drawing.Brushes.Red;
  505. if (inferResult.Count > 0)
  506. {
  507. int len = inferResult.Count;
  508. for (int nj = 0; nj < len; nj++)
  509. {
  510. string labels = inferResult[nj].Label.Name;
  511. Rect box = (Rect)inferResult[nj].BoundingBox;
  512. g.DrawString(labels + ":" + inferResult[nj].Score.ToString("0.0" + "%"), new Font("Arial", 10),
  513. brush, box.Left + 10, box.Top + 10);
  514. System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(box.Left,
  515. box.Top, box.Width, box.Height);
  516. g.DrawRectangle(new System.Drawing.Pen(brush, 2), rect2);
  517. IContour contour = inferResult[nj].Contour;
  518. if (contour == null)
  519. {
  520. continue;
  521. }
  522. int count = contour.Contours.Length;
  523. for (int ni = 0; ni < count; ni++)
  524. {
  525. var contourPoints = contour.Contours[ni];
  526. int pointCount = contourPoints.Points.Length;
  527. System.Drawing.Point[] contourPointsDraw = new System.Drawing.Point[pointCount]; // Use an array of Point
  528. for (int j = 0; j < pointCount; j++)
  529. {
  530. var point = new System.Drawing.Point(contourPoints.Points[j].X, contourPoints.Points[j].Y);
  531. contourPointsDraw[j] = point;
  532. }
  533. // Create a GraphicsPath object for drawing the contour
  534. System.Drawing.Drawing2D.GraphicsPath contourPath = new System.Drawing.Drawing2D.GraphicsPath();
  535. contourPath.AddPolygon(contourPointsDraw);
  536. // Draw the contour using the GraphicsPath
  537. g.DrawPath(new System.Drawing.Pen(brush, 2), contourPath);
  538. }
  539. }
  540. }
  541. }
  542. _doneImageNum += 1;
  543. }
  544. catch (Exception excep)
  545. {
  546. MessageBox.Show("测试图像时出错:" + excep);
  547. }
  548. }
  549. private void OnUncheckedEnableAI(object sender, RoutedEventArgs e)
  550. {
  551. _enableAI = false;
  552. MyImageCanvas.SetShowParams(_enableAI);
  553. }
  554. private void OnCheckedEnableAI(object sender, RoutedEventArgs e)
  555. {
  556. _enableAI = true;
  557. MyImageCanvas.SetShowParams(_enableAI);
  558. if (!_continuouslyDetecting && MyImageCanvas.Image != null)
  559. {
  560. DoImgTest(MyImageCanvas.Image);
  561. }
  562. }
  563. private void StopPlay()
  564. {
  565. _playEvent.Set();
  566. lock (_videoReaderLocker)
  567. {
  568. if (_videoReader != null)
  569. {
  570. _videoReader.Close();
  571. _videoReader.Dispose();
  572. _videoReader = null;
  573. }
  574. }
  575. if (_videoCapture != null)
  576. {
  577. _videoCapture.NewFrame -= OnVideoCaptureNewFrame;
  578. _videoCapture.SignalToStop();
  579. _videoCapture = null;
  580. }
  581. _continuouslyDetecting = false;
  582. }
  583. private void OnVideoCaptureNewFrame(object sender, NewFrameEventArgs e)
  584. {
  585. var bitmap = e.Frame;
  586. // 更新显示图像
  587. MyImageCanvas.UpdateImage(bitmap);
  588. _displayCount++;
  589. if (_enableAI)
  590. {
  591. DoImgTest(bitmap);
  592. }
  593. MyImageCanvas.UpdateImage(bitmap);
  594. bitmap.Dispose();
  595. }
  596. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  597. {
  598. _inferNet?.Dispose();
  599. }
  600. private void OnCheckedIsCropped(object sender, RoutedEventArgs e)
  601. {
  602. _isCropped = true;
  603. }
  604. private void OnUncheckedIsCropped(object sender, RoutedEventArgs e)
  605. {
  606. _isCropped = false;
  607. }
  608. }
  609. }