上传界面显示
This commit is contained in:
325
DH.UI.Model.Winform/Element/MLResultDisplay.cs
Normal file
325
DH.UI.Model.Winform/Element/MLResultDisplay.cs
Normal file
@ -0,0 +1,325 @@
|
||||
|
||||
using DH.Commons.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
namespace DH.UI.Model.Winform
|
||||
{
|
||||
public class DetectResultDisplay : ElementBase
|
||||
{
|
||||
//深度学习 显示结果
|
||||
private List<DetectionResultDetail> mlResultList = null;
|
||||
public List<DetectionResultDetail> MLResultList
|
||||
{
|
||||
get => mlResultList;
|
||||
set
|
||||
{
|
||||
if (mlResultList != value)
|
||||
{
|
||||
mlResultList = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//测量结果
|
||||
//private List<IndexedSpec> specResultList = null;
|
||||
//public List<IndexedSpec> SpecResultList
|
||||
//{
|
||||
// get => specResultList;
|
||||
// set
|
||||
// {
|
||||
// if (specResultList != value)
|
||||
// {
|
||||
// specResultList = value;
|
||||
|
||||
// string specDisplay = "";
|
||||
// if (specResultList != null && specResultList.Count > 0)
|
||||
// {
|
||||
// specResultList.ForEach(s =>
|
||||
// {
|
||||
// specDisplay += $"{s.Code}:{(s.ActualValue ?? 0).ToString("f2")}\r\n";
|
||||
// });
|
||||
// }
|
||||
|
||||
// if (!string.IsNullOrWhiteSpace(specDisplay))
|
||||
// {
|
||||
// DisplayTxt += specDisplay;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
ResultState ResultState = ResultState.DetectNG;
|
||||
|
||||
string DisplayTxt = "";
|
||||
Bitmap ResultImage = null;
|
||||
PointF StartPoint = new PointF();
|
||||
Brush FontBrush = new SolidBrush(Color.Green);
|
||||
Pen DetectResultRectPen = new Pen(new SolidBrush(Color.Green));
|
||||
Font DetectResultFont = new Font(new FontFamily("Tahoma"), 15, GraphicsUnit.World);
|
||||
|
||||
public int ImageWidth { get; set; }
|
||||
public int ImageHeight { get; set; }
|
||||
public DetectResultDisplay() { }
|
||||
|
||||
//public DetectResultDisplay(NetResult result, List<IndexedSpec> specs, ResultState resultState, int imageWidth)
|
||||
//{
|
||||
// ImageWidth = imageWidth;
|
||||
|
||||
// ResultState = resultState;
|
||||
|
||||
// displayTxt = resultState.ToString() + "\r\n";
|
||||
// if (resultState != ResultState.OK)
|
||||
// {
|
||||
// fontBrush = new SolidBrush(Color.Red);
|
||||
// }
|
||||
|
||||
// NetResult = result;
|
||||
// SpecList = specs;
|
||||
|
||||
// Font = new Font(new FontFamily("Tahoma"), 35 * ImageWidth / 1400, GraphicsUnit.World);
|
||||
// startPoint = new PointF(150 * ImageWidth / 1400, 150 * ImageWidth / 1400);
|
||||
//}
|
||||
|
||||
public DetectResultDisplay(DetectStationResult detectResult, Bitmap resultImage, string displayTxt)
|
||||
{
|
||||
ImageWidth = resultImage.Width;
|
||||
ImageHeight = resultImage.Height;
|
||||
var longSide = ImageWidth > ImageHeight ? ImageWidth : ImageHeight;
|
||||
|
||||
MLResultList = detectResult.DetectDetails;
|
||||
// SpecResultList = detectResult.Specs;
|
||||
ResultState = detectResult.ResultState;
|
||||
ResultImage = resultImage;
|
||||
DisplayTxt = displayTxt;
|
||||
if (ResultState != ResultState.OK)
|
||||
{
|
||||
FontBrush = new SolidBrush(Color.Red);
|
||||
DetectResultRectPen = new Pen(new SolidBrush(Color.Red));
|
||||
}
|
||||
Font = new Font(new FontFamily("Tahoma"), 35 * longSide / 1400, GraphicsUnit.World);
|
||||
DetectResultFont = new Font(new FontFamily("Tahoma"), 25 * longSide / 1400, GraphicsUnit.World);
|
||||
StartPoint = new PointF(100 * ImageWidth / 1400, 100 * ImageHeight / 1400);
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public override void Draw(Graphics g)
|
||||
{
|
||||
//画检测结果图
|
||||
if (ResultImage != null && ResultState != ResultState.OK)
|
||||
{
|
||||
g.DrawImage(ResultImage, new Point(0, 0));
|
||||
}
|
||||
//画文字
|
||||
if (!string.IsNullOrWhiteSpace(DisplayTxt))
|
||||
{
|
||||
g.DrawString(DisplayTxt, Font, FontBrush, StartPoint);
|
||||
}
|
||||
//画外接矩形+label 深度学习
|
||||
if (MLResultList != null && MLResultList.Count > 0)
|
||||
{
|
||||
MLResultList.ForEach(d =>
|
||||
{
|
||||
g.DrawRectangle(DetectResultRectPen, d.Rect);
|
||||
|
||||
string locationTxt = $"{d.LabelDisplay}";
|
||||
var locationX = d.Rect.X;
|
||||
var locationY = d.Rect.Y <= 20 ? d.Rect.Y + 20 : d.Rect.Y - 20;
|
||||
g.DrawString(locationTxt, DetectResultFont, FontBrush, locationX, locationY);
|
||||
});
|
||||
}
|
||||
//画spec信息
|
||||
|
||||
//if (DetectResult != null && DetectResult.NetResult?.DetectDetails?.Count > 0)
|
||||
//{
|
||||
// DetectResult.NetResult?.DetectDetails.ForEach(d =>
|
||||
// {
|
||||
// g.DrawRectangle(defectRectPen, d.Rect);
|
||||
|
||||
// string locationTxt = $"{d.Rect.X},{d.Rect.Y}";
|
||||
// g.DrawString(locationTxt, defectFont, fontBrush, d.Rect.X, d.Rect.Y - 5);
|
||||
// });
|
||||
//}
|
||||
|
||||
//float fontHeight = g.MeasureString(displayTxt, Font).Height;
|
||||
//startPoint.Y += fontHeight * 1.2f;
|
||||
|
||||
//var defects = DetectResult.NetResult?.DetectDetails;
|
||||
//if (defects != null && defects.Count > 0)
|
||||
//{
|
||||
// defects.ForEach(d =>
|
||||
// {
|
||||
// g.DrawString($"{d.ClassName} X:{d.Rect.X.ToString("f2")} Y:{d.Rect.Y.ToString("f2")} S:{d.Area}", Font, d.FinalResult == EnumHelper.ResultState.OK ? fontBrushOK : fontBrushNG, startPoint);
|
||||
|
||||
// startPoint.Y += fontHeight;
|
||||
// });
|
||||
//}
|
||||
|
||||
//DetectResult.Specs.ForEach(s =>
|
||||
//{
|
||||
// g.DrawString($"{s.Code}:{(s.ActualValue ?? 0).ToString("f2")}", Font, s.MeasureResult ?? false == true ? fontBrushOK : fontBrushNG, startPoint);
|
||||
|
||||
// startPoint.Y += fontHeight;
|
||||
//});
|
||||
}
|
||||
|
||||
public override string GetDisplayText()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public override bool IsIntersect(RectangleF rect)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool IsMouseHover(PointF p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool IsMouseInSide(PointF p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnKeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawResult(Graphics g)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnMouseDownWhenNew(PointF p)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnMouseMoveWhenNew(PointF p)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnMouseUpWhenNew(PointF p)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Translate(float x, float y)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class RectResultDisplay : ElementBase
|
||||
{
|
||||
ResultState ResultState = ResultState.DetectNG;
|
||||
public string DisplayTxt = "";
|
||||
Color FillColor = Color.Lime;
|
||||
int FontSize = 15;
|
||||
RectangleF Rect = new RectangleF();
|
||||
bool IsFilled = false;
|
||||
|
||||
public RectResultDisplay() { }
|
||||
|
||||
public RectResultDisplay(ResultState _resultState, RectangleF _rect, string _displayTxt, Color _fillColor, bool _isFilled, int _fontSize)
|
||||
{
|
||||
ResultState = _resultState;
|
||||
Rect = _rect;
|
||||
DisplayTxt = _displayTxt;
|
||||
FillColor = _fillColor;
|
||||
IsFilled = _isFilled;
|
||||
FontSize = _fontSize;
|
||||
}
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
RectResultDisplay rect = new RectResultDisplay();
|
||||
|
||||
rect.ResultState = ResultState;
|
||||
rect.Rect = Rect;
|
||||
rect.DisplayTxt = DisplayTxt;
|
||||
rect.FillColor = FillColor;
|
||||
rect.FontSize = FontSize;
|
||||
rect.IsFilled = IsFilled;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
public override void Draw(Graphics g)
|
||||
{
|
||||
g.DrawRectangle(new Pen(FillColor, 1), Rect.X, Rect.Y, Rect.Width, Rect.Height);
|
||||
|
||||
if (IsFilled)
|
||||
{
|
||||
g.FillRectangle(new SolidBrush(Color.FromArgb(20, FillColor)), Rect);
|
||||
}
|
||||
|
||||
Font font = new Font("Tahoma", FontSize);
|
||||
var txtSize = g.MeasureString(DisplayTxt, font);
|
||||
|
||||
g.DrawString(DisplayTxt, font, new SolidBrush(FillColor), (float)(Rect.X + Rect.Width / 2.0 - txtSize.Width / 2.0), Rect.Y + Rect.Height + 5);
|
||||
}
|
||||
|
||||
public override string GetDisplayText()
|
||||
{
|
||||
return $"{ResultState} {DisplayTxt} ({Rect.X},{Rect.Y},{Rect.Width},{Rect.Height})";
|
||||
}
|
||||
|
||||
public override bool IsIntersect(RectangleF rect)
|
||||
{
|
||||
return rect.IntersectsWith(Rect);
|
||||
}
|
||||
|
||||
public override bool IsMouseHover(PointF p)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool IsMouseInSide(PointF p)
|
||||
{
|
||||
return Rect.Contains(p);
|
||||
}
|
||||
|
||||
public override void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnKeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnMouseDownWhenNew(PointF p)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnMouseMoveWhenNew(PointF p)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnMouseUpWhenNew(PointF p)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Translate(float x, float y)
|
||||
{
|
||||
Rect.Offset(new PointF(x, y));
|
||||
}
|
||||
|
||||
protected override void DrawResult(Graphics g)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user