public void DrawDetectedBoundingBoxOnImage(DetectedItemInfo selectedItem = null) { var src = new BitmapImage(new Uri(m_ImageInfoModel.ImagePath, UriKind.Absolute)); Pen pen; DrawingVisual dv = new DrawingVisual(); using (DrawingContext dc = dv.RenderOpen()) { dc.DrawImage(src, new Rect(0, 0, src.PixelWidth, src.PixelHeight)); foreach (DetectedItemInfo item in DetectedItemInfoList) { if (item.Compare(selectedItem)) { pen = new Pen(Brushes.Green, 3); var overLayBrush = new SolidColorBrush(Color.FromArgb(150, 255, 255, 102)); dc.DrawRectangle(overLayBrush, pen, new Rect(item.X, item.Y, item.Width, item.Height)); } else { pen = new Pen(Brushes.Blue, 3); dc.DrawRectangle(Brushes.Transparent, pen, new Rect(item.X, item.Y, item.Width, item.Height)); } } } RenderTargetBitmap rtb = new RenderTargetBitmap(src.PixelWidth, src.PixelHeight, 96, 96, PixelFormats.Pbgra32); rtb.Render(dv); ImgSrc = rtb; }
public bool Compare(DetectedItemInfo newItem) { bool result = false; if (newItem != null) { if (newItem.Type == this.Type && newItem.Confidence == this.Confidence && newItem.X == this.X && newItem.Y == this.Y && newItem.Width == this.Width && newItem.Height == this.Height) { result = true; } } return(result); }
private void ResultsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { ResultInfoModel resultModel = ResultsDataGrid.SelectedItem as ResultInfoModel; if (resultModel == null) { return; } DetectedItemInfo item = new DetectedItemInfo(); item.Type = resultModel.DetectionLabel; item.Confidence = resultModel.Confidence; item.X = resultModel.DetectedBoxLeftTopX; item.Y = resultModel.DetectedBoxLeftTopY; item.Width = resultModel.DetectedBoxWidth; item.Height = resultModel.DetectedBoxHeight; PreviewImageModel previewModel = PreviewImageModel.Instance; previewModel.DrawDetectedBoundingBoxOnImage(item); }