| | |
| | | public event Action OnFullResetDone; |
| | | #endregion |
| | | |
| | | string _precision = "f3"; |
| | | |
| | | public override void Open() |
| | | { |
| | | InitialSetting(); |
| | |
| | | |
| | | Reset(null, null, null); |
| | | FullReset(null); |
| | | |
| | | if (Config.Precision > 0) |
| | | { |
| | | _precision = "f" + Config.Precision; |
| | | } |
| | | |
| | | IncomingCheckMethod = InitialMESWebServiceMethod(IncomingCheckMethodName, out IncomingCheckObj); |
| | | DataUploadMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj); |
| | | } |
| | | |
| | | private void InitialMotionCardBaseAxisAlarm() |
| | |
| | | } |
| | | #endregion |
| | | |
| | | public string BarCode { get; set; } |
| | | |
| | | List<ProductionMeasurement> productionList = new List<ProductionMeasurement>(); |
| | | |
| | | [ProcessMethod("", "StartJob", "开始扫描", InvokeType.TestInvoke)] |
| | |
| | | throw new ProcessException(SafetyMsg, null, ExceptionLevel.Fatal); |
| | | } |
| | | |
| | | string hint = ""; |
| | | if (MachineState != MachineState.Ready) |
| | | throw new ProcessException("机台未就绪,请勿开始测量", null, ExceptionLevel.Fatal); |
| | | { |
| | | hint = "机台未就绪,请勿开始测量"; |
| | | OnCheckHintUpload?.Invoke(hint, true); |
| | | throw new ProcessException(hint, null, ExceptionLevel.Fatal); |
| | | } |
| | | |
| | | if (string.IsNullOrWhiteSpace(BarCode)) |
| | | { |
| | | hint = "未输入产品条码,请勿开始测量"; |
| | | OnClearBarcode?.Invoke(); |
| | | throw new ProcessException("未输入产品条码,请勿开始测量"); |
| | | OnCheckHintUpload?.Invoke(hint, true); |
| | | throw new ProcessException(hint); |
| | | } |
| | | |
| | | MachineState = MachineState.Running; |
| | | |
| | | OnCheckHintUpload?.Invoke(hint, true); |
| | | OnMeasureStart?.Invoke(); |
| | | |
| | | var measurements = Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().DeepSerializeClone(); |
| | | measurements.ForEach(m => |
| | | //var measurements = Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().DeepSerializeClone(); |
| | | //measurements.ForEach(m => |
| | | //{ |
| | | // m.InitialKeyUnitMeasureChanged(); |
| | | //}); |
| | | |
| | | List<MeasurementUnit> measurements = new List<MeasurementUnit>(); |
| | | Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().ForEach(u => |
| | | { |
| | | var m = u.Copy(); |
| | | m.InitialKeyUnitMeasureChanged(); |
| | | measurements.Add(m); |
| | | }); |
| | | |
| | | var pMeasure = new ProductionMeasurement() |
| | |
| | | Measurements = measurements, |
| | | StartTime = DateTime.Now, |
| | | }; |
| | | |
| | | BarCode = ""; |
| | | |
| | | var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode); |
| | | if (existedProduction != null) |
| | |
| | | RunImageHandle(s.CameraOp.OpConfig, set, s.Id, s.Name, pMeasure.Measurements); |
| | | }); |
| | | |
| | | BarCode = ""; |
| | | LogAsync(DateTime.Now, $"{pMeasure.Barcode}测量动作完成", ""); |
| | | |
| | | GC.Collect(0, GCCollectionMode.Optimized); |
| | | |
| | | return new ProcessResponse(true); |
| | | } |
| | |
| | | { |
| | | if (m.KeyUnitCollection.Any(k => k.IsDone == false)) |
| | | { |
| | | m.Spec.ActualValue = -999; |
| | | //m.Spec.ActualValue = -999; |
| | | m.Spec.ActualValue = null; |
| | | } |
| | | else |
| | | { |
| | |
| | | if (!_halconToolDict.ContainsKey(toolKey)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}算法未初始化", ""); |
| | | m.Spec.ActualValue = -999; |
| | | //m.Spec.ActualValue = -999; |
| | | m.Spec.ActualValue = null; |
| | | } |
| | | else |
| | | { |
| | | var array = m.KeyUnitCollection.SelectMany(u => u.MeasureValueDict.Values.ToList().ConvertAll(v => v ?? -999)).ToArray(); |
| | | _halconToolDict[toolKey].InputTupleDic["INPUT_Params"] = new HTuple(array); |
| | | if (!_halconToolDict[toolKey].RunProcedure(out string error)) |
| | | //var array = m.KeyUnitCollection.SelectMany(u => u.MeasureValueDict.Values.ToList().ConvertAll(v => v ?? -999)).ToArray(); |
| | | var array = m.KeyUnitCollection.SelectMany(u => u.MeasureValueDict.Values.Select(v => v ?? -999)).ToArray(); |
| | | |
| | | if (array == null || array.Length == 0) |
| | | { |
| | | LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}算法异常,{error}", ""); |
| | | m.Spec.ActualValue = -999; |
| | | LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}未能获取对应检测值", ""); |
| | | //m.Spec.ActualValue = -999; |
| | | m.Spec.ActualValue = null; |
| | | } |
| | | else |
| | | { |
| | | m.Spec.ActualValue = double.Parse(_halconToolDict[toolKey].GetResultTuple("OUTPUT_Result").D.ToString("f2")); |
| | | //LogAsync(DateTime.Now, $"{m.GetDisplayText()}数据{m.Spec.ActualValue},结果{(m.Spec.MeasureResult == null ? "TBD" : (m.Spec.MeasureResult == true ? "OK" : "NG"))}", ""); |
| | | |
| | | _halconToolDict[toolKey].InputTupleDic["INPUT_Params"] = new HTuple(array); |
| | | if (!_halconToolDict[toolKey].RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{m.GetDisplayText()}{m.Spec.Code}算法异常,{error}", ""); |
| | | //m.Spec.ActualValue = -999; |
| | | m.Spec.ActualValue = null; |
| | | } |
| | | else |
| | | { |
| | | m.Spec.ActualValue = double.Parse(_halconToolDict[toolKey].GetResultTuple("OUTPUT_Result").D.ToString(_precision)); |
| | | //LogAsync(DateTime.Now, $"{m.GetDisplayText()}数据{m.Spec.ActualValue},结果{(m.Spec.MeasureResult == null ? "TBD" : (m.Spec.MeasureResult == true ? "OK" : "NG"))}", ""); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | //LogAsync(DateTime.Now, $"{m.GetDisplayText()}检测结果", $"{((m.Spec.MeasureResult ?? false) ? "OK" : "NG")}"); |
| | | |
| | | KeyIndicator indicator = new KeyIndicator(m.Id, m.DisplayLocation); |
| | | indicator.Text = (m.Spec.ActualValue == null || m.Spec.ActualValue == -999) ? "NA" : m.Spec.ActualValue.Value.ToString("f2"); |
| | | //indicator.Text = (m.Spec.ActualValue == null || m.Spec.ActualValue == -999) ? "NA" : m.Spec.ActualValue.Value.ToString(_precision); |
| | | indicator.Text = m.Spec.ActualValue == null ? "NA" : m.Spec.ActualValue.Value.ToString(_precision); |
| | | indicator.ResultState = m.Spec.MeasureResult; |
| | | pMeasure.ElementList.Add(indicator); |
| | | //输出图形基元到界面 |
| | |
| | | } |
| | | |
| | | pMeasure.EndTime = DateTime.Now; |
| | | bool pResult = pMeasure.Measurements.All(u => u.Spec.MeasureResult == true); |
| | | pMeasure.PResult = pResult ? "OK" : "NG"; |
| | | OnUpdateResult?.Invoke(DateTime.Now, pResult ? 1 : 0); |
| | | //bool pResult = pMeasure.Measurements.All(u => u.Spec.MeasureResult == true); |
| | | //pMeasure.PResult = pResult ? "OK" : "NG"; |
| | | //OnUpdateResult?.Invoke(DateTime.Now, pResult ? 1 : 0); |
| | | //OnUpdateCT?.Invoke((float)(pMeasure.EndTime.Value - pMeasure.StartTime.Value).TotalSeconds); |
| | | |
| | | int result = -1; |
| | | if (pMeasure.Measurements.Any(u => u.Spec.MeasureResult == null)) |
| | | { |
| | | pMeasure.PResult = "NA"; |
| | | } |
| | | else if (pMeasure.Measurements.Any(u => u.Spec.MeasureResult == false)) |
| | | { |
| | | pMeasure.PResult = "NG"; |
| | | result = 0; |
| | | } |
| | | else |
| | | { |
| | | pMeasure.PResult = "OK"; |
| | | result = 1; |
| | | } |
| | | OnUpdateResult?.Invoke(DateTime.Now, result); |
| | | OnUpdateCT?.Invoke((float)(pMeasure.EndTime.Value - pMeasure.StartTime.Value).TotalSeconds); |
| | | |
| | | LogAsync(DateTime.Now, $"{pMeasure.Barcode} 检测完成,结果 {pMeasure.PResult}", ""); |
| | |
| | | |
| | | var measurementUnitResultAndKeyUnitDataSet = GetMeasurementUnitResultAndKeyUnitData(pMeasure); |
| | | |
| | | //MES输出 todo |
| | | if (Config.IsEnableMESUpload) |
| | | if (pMeasure.PResult != "NA") |
| | | { |
| | | //MES输出 |
| | | MESCheckDataUpload(pMeasure); |
| | | } |
| | | |
| | | //Excel报表输出 (单个产品的excel导出) |
| | |
| | | |
| | | productionList.RemoveAll(p => p.Barcode == pMeasure.Barcode); |
| | | pMeasure.Dispose(); |
| | | //LogAsync(DateTime.Now, $"{pMeasure.Barcode}产品信息释放完成", JsonConvert.SerializeObject(pMeasure)); |
| | | } |
| | | } |
| | | |
| | |
| | | measurementUnitResult.Keys = measurementUnit.KeyUnitCollection[0].KeyResultId + "~" + measurementUnit.KeyUnitCollection[measurementUnit.KeyUnitCollection.Count() - 1].KeyResultId; |
| | | } |
| | | measurementUnitResult.MeasurementType = measurementUnit.MeasureType; |
| | | measurementUnitResult.MeasurementValue = measurementUnit.Spec.ActualValue == null ? "NA" : measurementUnit.Spec.ActualValue.Value.ToString("f2"); |
| | | measurementUnitResult.MeasurementValue = measurementUnit.Spec.ActualValue == null ? "NA" : measurementUnit.Spec.ActualValue.Value.ToString(_precision); |
| | | measurementUnitResult.MeasurementResult = measurementUnit.Spec.MeasureResult.Value ? "OK" : "NG"; |
| | | |
| | | measurementUnitResults.Add(measurementUnitResult); |
| | |
| | | keyUnitData.ProductionBarcode = productionMeasurementRecords.ProductionBarcode; |
| | | keyUnitData.Key = keyUnit.Key; |
| | | keyUnitData.MeasurementItem = keyValue.Key; |
| | | keyUnitData.ItemValue = keyValue.Value == null ? "NA" : keyValue.Value.Value.ToString("f2"); |
| | | keyUnitData.ItemValue = keyValue.Value == null ? "NA" : keyValue.Value.Value.ToString(_precision); |
| | | keyUnitDatas.Add(keyUnitData); |
| | | |
| | | MeasurementAndKeyDataRelation measurementAndKeyDataRelation = new MeasurementAndKeyDataRelation(); |
| | |
| | | |
| | | #region RawData |
| | | { |
| | | //rawDataSheet = package.Workbook.Worksheets["RawData"]; |
| | | |
| | | int rowDataStartCol = rawDataSheet.Dimension.Columns; |
| | | var barcodeCell = rawDataSheet.Cells[1, rowDataStartCol + 1, 1, rowDataStartCol + 4]; |
| | | barcodeCell.Merge = true; |
| | |
| | | { |
| | | int slantStartCol = slantSheet.Dimension.Columns; |
| | | |
| | | //var barcodeCell = slantSheet.Cells[1, slantStartCol + 1, 1, slantStartCol + 2]; |
| | | //barcodeCell.Merge = true; |
| | | //barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode; |
| | | //SetTitleCell(barcodeCell); |
| | | |
| | | var barcodeCell = slantSheet.Cells[1, slantStartCol + 1]; |
| | | barcodeCell.Value = exportData.ProductionMeasurementRecord.ProductionBarcode; |
| | | SetTitleCell(barcodeCell); |
| | |
| | | var valueCell = slantSheet.Cells[2, slantStartCol + 1]; |
| | | valueCell.Value = "Value"; |
| | | SetTitleCell(valueCell); |
| | | |
| | | //var resultCell = slantSheet.Cells[2, slantStartCol + 2]; |
| | | //resultCell.Value = "Result"; |
| | | //SetTitleCell(resultCell); |
| | | |
| | | slantMeasures.ForEach(m => |
| | | { |
| | |
| | | #endregion |
| | | |
| | | package.Save(); |
| | | |
| | | rawDataSheet.Dispose(); |
| | | slantSheet.Dispose(); |
| | | alignmentSheet.Dispose(); |
| | | rowAlignmentSheet.Dispose(); |
| | | }; |
| | | } |
| | | }); |
| | |
| | | private async void RunImageHandle(IOperationConfig opConfig, IImageSet imgSet, string snapshotId, string snapshotName, List<MeasurementUnit> measureList) |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | | var keys = Config.KeyUnitCollection.Where(u => u.IsEnabled && u.SnapshotPointId == snapshotId); |
| | | var keyBindCollection = measureList.SelectMany(u => u.KeyUnitCollection).Where(u => keys.Any(k => k.Key == u.Key)).ToList(); |
| | | { |
| | | var keys = Config.KeyUnitCollection.Where(u => u.IsEnabled && u.SnapshotPointId == snapshotId); |
| | | var keyBindCollection = measureList.SelectMany(u => u.KeyUnitCollection).Where(u => keys.Any(k => k.Key == u.Key)).ToList(); |
| | | |
| | | string toolKey = (opConfig as CameraOprerationConfigBase).AlgorithemPath; |
| | | //HObject images = imgSet.HImage; |
| | | string toolKey = (opConfig as CameraOprerationConfigBase).AlgorithemPath; |
| | | //HObject images = imgSet.HImage; |
| | | |
| | | HObject images = new HObject(); |
| | | LaserScanParam scanParam = JsonConvert.DeserializeObject<LaserScanParam>(imgSet.ImageData); |
| | | LogAsync(DateTime.Now, $"扫描参数:{imgSet.ImageData}", ""); |
| | | HObject images = new HObject(); |
| | | LaserScanParam scanParam = JsonConvert.DeserializeObject<LaserScanParam>(imgSet.ImageData); |
| | | LogAsync(DateTime.Now, $"扫描参数:{imgSet.ImageData}", ""); |
| | | |
| | | if (!string.IsNullOrWhiteSpace(toolKey)) |
| | | { |
| | | toolKey = snapshotId + "|" + toolKey; |
| | | if (!_halconToolDict.ContainsKey(toolKey)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{snapshotName}未初始化取图算法配置", ""); |
| | | keyBindCollection.ForEach(k => k.FillKeyValues(null)); |
| | | return; |
| | | } |
| | | if (!string.IsNullOrWhiteSpace(toolKey)) |
| | | { |
| | | toolKey = snapshotId + "|" + toolKey; |
| | | if (!_halconToolDict.ContainsKey(toolKey)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{snapshotName}未初始化取图算法配置", ""); |
| | | keyBindCollection.ForEach(k => k.FillKeyValues(null)); |
| | | return; |
| | | } |
| | | |
| | | //string fileName = Path.Combine(Config.ImageSaveFolder, "BeforeRun", $"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.tif"); |
| | | //imgSet.HImage.WriteImage("tiff", 0, fileName); |
| | | //string fileName = Path.Combine(Config.ImageSaveFolder, "BeforeRun", $"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.tif"); |
| | | //imgSet.HImage.WriteImage("tiff", 0, fileName); |
| | | |
| | | _halconToolDict[toolKey].InputImageDic["INPUT_Image"] = imgSet.HImage; |
| | | if (!_halconToolDict[toolKey].RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{snapshotName}取图算法异常,{error}", ""); |
| | | keyBindCollection.ForEach(k => k.FillKeyValues(null)); |
| | | return; |
| | | } |
| | | if (imgSet.HImage == null) |
| | | { |
| | | LogAsync(DateTime.Now, $"{snapshotName}图片为空对象", ""); |
| | | keyBindCollection.ForEach(k => k.FillKeyValues(null)); |
| | | return; |
| | | } |
| | | |
| | | images = _halconToolDict[toolKey].GetResultObject("OUTPUT_Images"); |
| | | } |
| | | _halconToolDict[toolKey].InputImageDic["INPUT_Image"] = imgSet.HImage; |
| | | if (!_halconToolDict[toolKey].RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{snapshotName}取图算法异常,{error}", ""); |
| | | keyBindCollection.ForEach(k => k.FillKeyValues(null)); |
| | | return; |
| | | } |
| | | |
| | | HOperatorSet.CountObj(images, out HTuple count); |
| | | LogAsync(DateTime.Now, $"{snapshotName}切图{count.I}张", ""); |
| | | images = _halconToolDict[toolKey].GetResultObject("OUTPUT_Images"); |
| | | } |
| | | |
| | | if (count == 0) |
| | | { |
| | | LogAsync(DateTime.Now, $"{snapshotName}取图算法未输出图像", ""); |
| | | keyBindCollection.ForEach(k => k.FillKeyValues(null)); |
| | | return; |
| | | } |
| | | HOperatorSet.CountObj(images, out HTuple count); |
| | | LogAsync(DateTime.Now, $"{snapshotName}切图{count.I}张", ""); |
| | | |
| | | var excludeKeys = keys.Where(u => u.ImageSeq > count.I).ToList(); |
| | | if (excludeKeys.Count > 0) |
| | | { |
| | | LogAsync(DateTime.Now, $"{string.Join(" ", excludeKeys.Select(u => u.AliasName))}未在图片获取序列中", ""); |
| | | keyBindCollection.Where(k => excludeKeys.Any(u => u.Key == k.Key)).ToList().ForEach(k => |
| | | { |
| | | k.FillKeyValues(null); |
| | | }); |
| | | } |
| | | if (count == 0) |
| | | { |
| | | LogAsync(DateTime.Now, $"{snapshotName}取图算法未输出图像", ""); |
| | | keyBindCollection.ForEach(k => k.FillKeyValues(null)); |
| | | return; |
| | | } |
| | | |
| | | //string dir = Path.Combine(Config.ImageSaveFolder, "Clips", $"{DateTime.Now.ToString("yyyyMMdd")}", $"{snapshotName}_{DateTime.Now.ToString("HHmmss")}"); |
| | | //if (!Directory.Exists(dir)) |
| | | //{ |
| | | // Directory.CreateDirectory(dir); |
| | | //} |
| | | var excludeKeys = keys.Where(u => u.ImageSeq > count.I).ToList(); |
| | | if (excludeKeys.Count > 0) |
| | | { |
| | | LogAsync(DateTime.Now, $"{string.Join(" ", excludeKeys.Select(u => u.AliasName))}未在图片获取序列中", ""); |
| | | keyBindCollection.Where(k => excludeKeys.Any(u => u.Key == k.Key)).ToList().ForEach(k => |
| | | { |
| | | k.FillKeyValues(null); |
| | | }); |
| | | } |
| | | |
| | | //Parallel.For(1, count.I + 1, (i) => |
| | | for (int i = 1; i <= count.I; i++) |
| | | { |
| | | HOperatorSet.SelectObj(images, out HObject image, i); |
| | | //string dir = Path.Combine(Config.ImageSaveFolder, "Clips", $"{DateTime.Now.ToString("yyyyMMdd")}", $"{snapshotName}_{DateTime.Now.ToString("HHmmss")}"); |
| | | //if (!Directory.Exists(dir)) |
| | | //{ |
| | | // Directory.CreateDirectory(dir); |
| | | //} |
| | | |
| | | //string fileName = Path.Combine(dir, $"{i}.tif"); |
| | | //using (HImage temp = image.ConvertHObjectToHImage()) |
| | | //{ |
| | | // temp.WriteImage("tiff", 0, fileName); |
| | | //} |
| | | //Parallel.For(1, count.I + 1, (i) => |
| | | for (int i = 1; i <= count.I; i++) |
| | | { |
| | | HOperatorSet.SelectObj(images, out HObject image, i); |
| | | |
| | | keys.Where(u => u.ImageSeq == i).ToList().ForEach(k => |
| | | { |
| | | Dictionary<string, double> resultDict = null; |
| | | //string fileName = Path.Combine(dir, $"{i}.tif"); |
| | | //using (HImage temp = image.ConvertHObjectToHImage()) |
| | | //{ |
| | | // temp.WriteImage("tiff", 0, fileName); |
| | | //} |
| | | |
| | | var keyBindList = keyBindCollection.Where(u => u.Key == k.Key).ToList(); |
| | | keys.Where(u => u.ImageSeq == i).ToList().ForEach(k => |
| | | { |
| | | Dictionary<string, double> resultDict = null; |
| | | |
| | | string keyToolKey = k.AliasName + "|" + k.KeyAlgorithemPath; |
| | | if (!_halconToolDict.ContainsKey(keyToolKey)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测算法未初始化", ""); |
| | | } |
| | | else |
| | | { |
| | | _halconToolDict[keyToolKey].InputImageDic["INPUT_Image"] = image; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_X"] = scanParam.Resolution_X / 1000000.0; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Z"] = scanParam.Resolution_Z / 1000000.0; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_ImageId"] = $"{k.AliasName}_{DateTime.Now.ToString("HHmmssfff")}.tif"; |
| | | if (!_halconToolDict[keyToolKey].RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测算法异常,{error}", ""); |
| | | } |
| | | else |
| | | { |
| | | var results = _halconToolDict[keyToolKey].GetResultTuple("OUTPUT_Results").DArr.ToList(); |
| | | if (results.Count == 0 || results.Any(u => u < 0)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}原始数据异常", ""); |
| | | } |
| | | else |
| | | { |
| | | //LogAsync(DateTime.Now, $"{k.AliasName}原始数据", $"{string.Join(" ", results)}"); |
| | | var keyBindList = keyBindCollection.Where(u => u.Key == k.Key).ToList(); |
| | | |
| | | results = results.Select(u => u - Config.PlanCompensation).ToList(); |
| | | resultDict = k.KeyResultList.ToDictionary(u => u, u => |
| | | { |
| | | int index = k.KeyResultList.IndexOf(u); |
| | | return results[index]; |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | string keyToolKey = k.AliasName + "|" + k.KeyAlgorithemPath; |
| | | if (!_halconToolDict.ContainsKey(keyToolKey)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测算法未初始化", ""); |
| | | } |
| | | else |
| | | { |
| | | _halconToolDict[keyToolKey].InputImageDic["INPUT_Image"] = image; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_X"] = scanParam.Resolution_X / 1000000.0; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Y"] = scanParam.Resolution_Y / 1000000.0; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Z"] = scanParam.Resolution_Z / 1000000.0; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_ImageId"] = $"{k.AliasName}_{DateTime.Now.ToString("HHmmssfff")}.tif"; |
| | | if (!_halconToolDict[keyToolKey].RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测算法异常,{error}", ""); |
| | | } |
| | | else |
| | | { |
| | | var results = _halconToolDict[keyToolKey].GetResultTuple("OUTPUT_Results").DArr.ToList(); |
| | | if (results.Count == 0 || results.Any(u => u < 0)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}原始数据异常", ""); |
| | | } |
| | | else |
| | | { |
| | | //LogAsync(DateTime.Now, $"{k.AliasName}原始数据", $"{string.Join(" ", results)}"); |
| | | |
| | | keyBindList.ForEach(kb => |
| | | { |
| | | kb.KeyImages.Add(image.ConvertHObjectToHImage()); |
| | | kb.FillKeyValues(resultDict); |
| | | }); |
| | | }); |
| | | results = results.Select(u => u - Config.PlanCompensation).ToList(); |
| | | resultDict = k.KeyResultList.ToDictionary(u => u, u => |
| | | { |
| | | int index = k.KeyResultList.IndexOf(u); |
| | | return results[index]; |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | image.Dispose(); |
| | | } |
| | | //); |
| | | keyBindList.ForEach(kb => |
| | | { |
| | | kb.KeyImages.Add(image.ConvertHObjectToHImage()); |
| | | kb.FillKeyValues(resultDict); |
| | | }); |
| | | }); |
| | | |
| | | images.Dispose(); |
| | | //if (count.I != 1) |
| | | //{ |
| | | // hImage?.Dispose(); |
| | | // hImage = null; |
| | | //} |
| | | }); |
| | | image.Dispose(); |
| | | image = null; |
| | | } |
| | | //); |
| | | |
| | | imgSet.HImage.Dispose(); |
| | | imgSet.HImage = null; |
| | | imgSet.Dispose(); |
| | | |
| | | images.Dispose(); |
| | | images = null; |
| | | |
| | | //if (count.I != 1) |
| | | //{ |
| | | // hImage?.Dispose(); |
| | | // hImage = null; |
| | | //} |
| | | }); |
| | | } |
| | | #endregion |
| | | } |