|
|
@@ -1793,7 +1793,7 @@ namespace TeamAAS_VP.Services
|
|
|
/// 执行相机拍照并运行 ToolBlock,返回是否成功并通过 out 参数返回 Outputs。
|
|
|
/// 该方法会发布 RenderUpdateNotification 以更新 UI。
|
|
|
/// </summary>
|
|
|
- public bool ExecutePhoto(ProcedureModel procedure,ICogImage[] imges,Dictionary<string, string> InputTerminal, out CogToolBlockTerminalCollection outputCollection,bool is3dmodel)
|
|
|
+ public bool ExecutePhoto(ProcedureModel procedure,ICogImage[] imges,Dictionary<string, string> InputTerminal, out CogToolBlockTerminalCollection outputCollection,bool is3dmodel, float confThreshold = 0.25f, float iouThreshold = 0.45f)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
@@ -1804,7 +1804,6 @@ namespace TeamAAS_VP.Services
|
|
|
procedure.ToolBlock.Inputs["InputImage2"].Value = imges[1];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 2. 为ToolBlock传入其他输入终端
|
|
|
if (InputTerminal != null)
|
|
|
{
|
|
|
@@ -1829,9 +1828,7 @@ namespace TeamAAS_VP.Services
|
|
|
// photoAiValue 可能为 null/空,建议给个默认值
|
|
|
bool enablePhotoAi = photoAiValue == "1";
|
|
|
if (enablePhotoAi == true)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
+ {
|
|
|
string exeDir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
|
string modelPath = System.IO.Path.Combine(exeDir, "TrainPhoto", "weights", "best_openvino_model", "best.xml");
|
|
|
@@ -1848,26 +1845,26 @@ namespace TeamAAS_VP.Services
|
|
|
|
|
|
//string imagePath = "G:\\TEST\\文件\\左上插线\\1.bmp";
|
|
|
|
|
|
- using (var yolo = new YoloOpenVINOInference(modelPath, metadataPath))
|
|
|
+ using (var yolo = new YoloOpenVINOInference(modelPath, metadataPath, confThreshold, iouThreshold))
|
|
|
{
|
|
|
using (var bitmap = imges[0].ToBitmap())
|
|
|
{
|
|
|
var results = yolo.Infer(bitmap);
|
|
|
procedure.ToolBlock.Inputs["PhotoData"].Value = "";
|
|
|
+ procedure.ToolBlock.Inputs["Confidence"].Value ="";
|
|
|
// 输出结果
|
|
|
- //Console.WriteLine($"检测到 {results.Count} 个目标:");
|
|
|
SendTaskMessage($"识别的个数:{results.Count()}", MessageLevel.Alarm);
|
|
|
-
|
|
|
+ string ClassName = "";
|
|
|
+ string Confidence = "";
|
|
|
foreach (var det in results)
|
|
|
{
|
|
|
- //Console.WriteLine($" - {det.ClassName}: 置信度={det.Confidence:F4}, " +
|
|
|
- // $"边界框=[{det.Box[0]:F0}, {det.Box[1]:F0}, {det.Box[2]:F0}, {det.Box[3]:F0}]");
|
|
|
SendTaskMessage($" - {det.ClassName}: 置信度={det.Confidence:F4}, " +
|
|
|
$"边界框=[{det.Box[0]:F0}, {det.Box[1]:F0}, {det.Box[2]:F0}, {det.Box[3]:F0}]", MessageLevel.Alarm);
|
|
|
- procedure.ToolBlock.Inputs["PhotoData"].Value = $"{det.ClassName}" + ",";
|
|
|
+ ClassName += $"{det.ClassName}" + ",";
|
|
|
+ Confidence += $"{det.Confidence}" + ",";
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ procedure.ToolBlock.Inputs["PhotoData"].Value = ClassName;
|
|
|
+ procedure.ToolBlock.Inputs["Confidence"].Value = Confidence;
|
|
|
// 绘制结果 - 使用 OpenCvSharp
|
|
|
using (var image2 = ImageHelper.ICogImageConvertMat(imges[0]))
|
|
|
{
|
|
|
@@ -1941,6 +1938,7 @@ namespace TeamAAS_VP.Services
|
|
|
//Console.WriteLine($"结果已保存到: {outputPath}");
|
|
|
var cogImage = ImageHelper.MatConvertICogImage(image2);
|
|
|
procedure.ToolBlock.Inputs["InputImage"].Value = cogImage;
|
|
|
+ procedure.ToolBlock.Run();
|
|
|
outputCollection = procedure.ToolBlock.Outputs; //获取输出终端集合
|
|
|
ICogRecord record = null;
|
|
|
foreach (CogToolBlockTerminal item in outputCollection)
|
|
|
@@ -1967,12 +1965,10 @@ namespace TeamAAS_VP.Services
|
|
|
// 生成文件名
|
|
|
imgName = template.Generate();
|
|
|
}
|
|
|
- procedure.ToolBlock.Run();
|
|
|
_eventAggregator.GetEvent<RenderUpdateNotification>().Publish(new ShowRender()
|
|
|
{
|
|
|
Id = procedure.DisplayId,
|
|
|
DisplayName = procedure.DisplayName,
|
|
|
- //Image = (ICogImage)procedure.ToolBlock.Outputs["OriImage"].Value,
|
|
|
Image = cogImage,
|
|
|
Graphic = outputCollection["Graphic"].Value as CogGraphicCollection,
|
|
|
Record = record,
|
|
|
@@ -2406,7 +2402,7 @@ namespace TeamAAS_VP.Services
|
|
|
/// <param name="robotCoord"></param>
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<(bool IsSucceed, string[] Items, double Count)> ExecutePhotoGetSinglePoint1(ProcedureModel procedure, ICogImage[] imges, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken,bool is3dmodel)
|
|
|
+ public async Task<(bool IsSucceed, string[] Items, double Count)> ExecutePhotoGetSinglePoint1(ProcedureModel procedure, ICogImage[] imges, Dictionary<string, string> InputTerminal, double[] robotCoord, CancellationToken cancellationToken,bool is3dmodel, float confThreshold = 0.25f, float iouThreshold = 0.45f)
|
|
|
{
|
|
|
DateTime nowtime = DateTime.Now;
|
|
|
try
|
|
|
@@ -2418,7 +2414,7 @@ namespace TeamAAS_VP.Services
|
|
|
SendTaskMessage(Lang.开始执行视觉流程.Replace("{0}", $"{i + 1}").Replace("{1}", procedure.Name), MessageLevel.Info);
|
|
|
|
|
|
// 1. 执行相机拍照并运行视觉工具
|
|
|
- bool visionSucceed = ExecutePhoto(procedure, imges, InputTerminal, out CogToolBlockTerminalCollection outputCollection, is3dmodel);
|
|
|
+ bool visionSucceed = ExecutePhoto(procedure, imges, InputTerminal, out CogToolBlockTerminalCollection outputCollection, is3dmodel, confThreshold, iouThreshold);
|
|
|
if (!visionSucceed)
|
|
|
{
|
|
|
SendTaskMessage(Lang.视觉任务执行失败, MessageLevel.Error);
|