| | |
| | | } |
| | | } |
| | | |
| | | public void ClearImageSet(string imgSetId) |
| | | { |
| | | IImageSet set = _imageSetList[imgSetId]; |
| | | if (set != null) |
| | | ClearImageSet(set); |
| | | } |
| | | //public void ClearImageSet(string imgSetId) |
| | | //{ |
| | | // IImageSet set = _imageSetList[imgSetId]; |
| | | // if (set != null) |
| | | // ClearImageSet(set); |
| | | //} |
| | | |
| | | private void ImageSet_OnImageSetTimeout(ImageSet set) |
| | | { |
| | | ClearImageSet(set); |
| | | } |
| | | //private void ImageSet_OnImageSetTimeout(ImageSet set) |
| | | //{ |
| | | // ClearImageSet(set); |
| | | //} |
| | | |
| | | //private void ClearImageSetPeriodically() |
| | | //{ |
| | |
| | | } |
| | | } |
| | | |
| | | public static Bitmap ConvertHImgaeToBitmap(this HImage hImage) |
| | | public static Bitmap ConvertHImageToBitmap(this HImage hImage) |
| | | { |
| | | try |
| | | { |
| | |
| | | |
| | | return img; |
| | | } |
| | | |
| | | public static Bitmap ConvertHImageTo16GrayBitmap(this HImage originHImage) |
| | | { |
| | | HImage hImage = originHImage.Clone(); |
| | | |
| | | //get_domain(Image, rectangle) |
| | | //* 获取全图中像素灰度值的最大和最小值 |
| | | //min_max_gray(rectangle, Image, 0, Min, Max, range) |
| | | hImage.MinMaxGray(hImage.GetDomain(), 0, out double min, out double max, out double range); |
| | | |
| | | //* 将16位图的灰度值映射到0 - 255上 |
| | | double mult = 255.0 / (max - min); |
| | | double add = -mult * min; |
| | | hImage = hImage.ScaleImage(mult, add); |
| | | |
| | | //* 转换为'byte'类型 |
| | | //convert_image_type(Image_scaled, ImageConverted, 'byte') |
| | | hImage = hImage.ConvertImageType("byte"); |
| | | |
| | | Bitmap showImage = hImage.ConvertHImageToBitmap(); |
| | | |
| | | hImage.Dispose(); |
| | | |
| | | return showImage; |
| | | } |
| | | |
| | | public static Bitmap ConvertSignedHImageTo16GrayBitmap(this HImage originHImage) |
| | | { |
| | | HImage hImage = originHImage.Clone(); |
| | | |
| | | hImage = hImage.ConvertImageType("int4"); |
| | | hImage = hImage.ScaleImage(1.0, 32768); |
| | | hImage = hImage.ConvertImageType("uint2"); |
| | | |
| | | //get_domain(Image, rectangle) |
| | | //* 获取全图中像素灰度值的最大和最小值 |
| | | //min_max_gray(rectangle, Image, 0, Min, Max, range) |
| | | hImage.MinMaxGray(hImage.GetDomain(), 0, out double min, out double max, out double range); |
| | | |
| | | //* 将16位图的灰度值映射到0 - 255上 |
| | | double mult = 255.0 / (max - min); |
| | | double add = -mult * min; |
| | | hImage = hImage.ScaleImage(mult, add); |
| | | |
| | | //* 转换为'byte'类型 |
| | | //convert_image_type(Image_scaled, ImageConverted, 'byte') |
| | | hImage = hImage.ConvertImageType("byte"); |
| | | |
| | | Bitmap showImage = hImage.ConvertHImageToBitmap(); |
| | | |
| | | hImage.Dispose(); |
| | | |
| | | return showImage; |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | [Category("数据位配置")] |
| | | [Description("图像数据位数,2位/4位")] |
| | | [Browsable(false)] |
| | | public GocatorDataByteNums ByteNums { get; set; } = GocatorDataByteNums.Byte2; |
| | | } |
| | | |
| | |
| | | long bufferSize = width * height; |
| | | IntPtr bufferPointer = surfaceMsg.Data; |
| | | |
| | | |
| | | float zoomFactor = (float)((double)surfaceMsg.YResolution / (double)surfaceMsg.XResolution); |
| | | int zoomHeight = (int)(zoomFactor * height); |
| | | |
| | | //IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * 2); |
| | | IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * 2); |
| | | //IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * 4); |
| | | IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * (int)IIConfig.ByteNums); |
| | | //IntPtr zoomPtr = Marshal.AllocHGlobal(zoomHeight * (int)width * (int)IIConfig.ByteNums); |
| | | |
| | | //没有插值,默认0 |
| | | //Parallel.For(0, height, h => |
| | |
| | | // CopyMemory((IntPtr)((long)zoomPtr + width * 2 * Math.Floor(h * zoomFactor)), (IntPtr)((long)bufferPointer + width * 2 * h), width * 2); |
| | | // }); |
| | | |
| | | if (IIConfig.ByteNums == GocatorDataByteNums.Byte2) |
| | | //if (IIConfig.ByteNums == GocatorDataByteNums.Byte2) |
| | | //{ |
| | | //使用上一行原有数据 |
| | | Parallel.For(0, zoomHeight, h => |
| | | { |
| | | //使用上一行原有数据 |
| | | Parallel.For(0, zoomHeight, h => |
| | | { |
| | | int originHeightIndex = (int)Math.Floor((double)height * h / (double)zoomHeight); |
| | | int originHeightIndex = (int)Math.Floor((double)height * h / (double)zoomHeight); |
| | | CopyMemory((IntPtr)((long)zoomPtr + width * 2 * h), (IntPtr)((long)bufferPointer + width * 2 * originHeightIndex), width * 2); |
| | | }); |
| | | //} |
| | | //else |
| | | //{ |
| | | // //使用上一行原有数据 |
| | | // Parallel.For(0, zoomHeight, h => |
| | | // { |
| | | // int originHeightIndex = (int)Math.Floor((double)height * h / (double)zoomHeight); |
| | | |
| | | CopyMemory((IntPtr)((long)zoomPtr + width * 2 * h), (IntPtr)((long)bufferPointer + width * 2 * originHeightIndex), width * 2); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | //使用上一行原有数据 |
| | | Parallel.For(0, zoomHeight, h => |
| | | { |
| | | int originHeightIndex = (int)Math.Floor((double)height * h / (double)zoomHeight); |
| | | // byte[] rowBuffer = new byte[width * 4]; |
| | | // Parallel.For(0, width, w => |
| | | // { |
| | | // rowBuffer[w * 4 + 2] = Marshal.ReadByte(bufferPointer, (int)(width * 2 * originHeightIndex + w * 2)); |
| | | // rowBuffer[w * 4 + 3] = Marshal.ReadByte(bufferPointer, (int)(width * 2 * originHeightIndex + w * 2 + 1)); |
| | | // }); |
| | | |
| | | byte[] rowBuffer = new byte[width * 4]; |
| | | Parallel.For(0, width, w => |
| | | { |
| | | rowBuffer[w * 4 + 2] = Marshal.ReadByte(bufferPointer, (int)(width * 2 * originHeightIndex + w * 2)); |
| | | rowBuffer[w * 4 + 3] = Marshal.ReadByte(bufferPointer, (int)(width * 2 * originHeightIndex + w * 2 + 1)); |
| | | }); |
| | | |
| | | Marshal.Copy(rowBuffer, 0, (IntPtr)((long)zoomPtr + width * 2 * h), rowBuffer.Length); |
| | | }); |
| | | } |
| | | // Marshal.Copy(rowBuffer, 0, (IntPtr)((long)zoomPtr + width * 2 * h), rowBuffer.Length); |
| | | // }); |
| | | //} |
| | | |
| | | if (imgSet != null) |
| | | { |
| | | imgSet.HImage = new HImage(); |
| | | //imgSet.HImage.GenImage1("uint2", (int)width, zoomHeight, zoomPtr); |
| | | //imgSet.HImage.GenImage1("int4", (int)width, zoomHeight, zoomPtr); |
| | | imgSet.HImage.GenImage1(IIConfig.ByteNums == GocatorDataByteNums.Byte2 ? "uint2" : "int4", (int)width, zoomHeight, zoomPtr); |
| | | //imgSet.HImage.GenImage1(IIConfig.ByteNums == GocatorDataByteNums.Byte2 ? "uint2" : "int4", (int)width, zoomHeight, zoomPtr); |
| | | |
| | | //imgSet.HImage_2 = imgSet.HImage.Clone(); |
| | | imgSet.HImage.GenImage1("int2", (int)width, zoomHeight, zoomPtr); |
| | | |
| | | //imgSet.HImage = imgSet.HImage.ConvertImageType("int4"); |
| | | //imgSet.HImage = imgSet.HImage.ScaleImage(1.0, short.MaxValue + 1.0); |
| | | //imgSet.HImage = imgSet.HImage.ConvertImageType("uint2"); |
| | | imgSet.HImage_2 = new HImage(); |
| | | imgSet.HImage_2.GenImage1("int2", (int)width, zoomHeight, zoomPtr); |
| | | //imgSet.HImage_2.GenImage1("uint2", (int)width, zoomHeight, zoomPtr); |
| | | //imgSet.HImage_2.GenImage1("int4", (int)width, zoomHeight, zoomPtr); |
| | | |
| | | imgSet.HImage_2 = new HImage(); |
| | | imgSet.HImage_2.GenImage1(IIConfig.ByteNums == GocatorDataByteNums.Byte2 ? "uint2" : "int4", (int)width, zoomHeight, zoomPtr); |
| | | //imgSet.HImage_2 = new HImage(); |
| | | //imgSet.HImage_2.GenImage1(IIConfig.ByteNums == GocatorDataByteNums.Byte2 ? "uint2" : "int4", (int)width, zoomHeight, zoomPtr); |
| | | |
| | | LaserScanParam para = new LaserScanParam() |
| | | { |
| | |
| | | //imgSet.HImage_2 = imgSet.HImage_2.ZoomImageSize((int)width, zoomHeight, "constant"); |
| | | } |
| | | |
| | | //var showImage = imgSet.HImage_2.ConvertSignedHImageTo16GrayBitmap(); |
| | | //showImage.Save($@"D:\SI\{DateTime.Now.ToString("yyyyMMddHHmmss")}.tif", System.Drawing.Imaging.ImageFormat.Tiff); |
| | | |
| | | //SaveOriginImage(null, showImage, imgSet.Id); |
| | | |
| | | //Marshal.FreeHGlobal(zoomPtr); |
| | | Generate16GrayImageByPointer((int)width, zoomHeight, zoomPtr, imgSet?.Id).ContinueWith(t => |
| | | { |
| | | Marshal.FreeHGlobal(zoomPtr); |
| | |
| | | { |
| | | if (opConfig.IsOpenConnection) |
| | | { |
| | | while (sensor.State != GoState.Ready) |
| | | { |
| | | Thread.Sleep(10); |
| | | } |
| | | |
| | | do |
| | | { |
| | | try |
| | | { |
| | | sensor.Start(); |
| | | LogAsync(DateTime.Now, $"传感器状态:{sensor.State.ToString()}", ""); |
| | | if (sensor.State != GoState.Running) |
| | | { |
| | | Thread.Sleep(100); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, $"开启异常:{ex.GetExceptionMessage()}", ""); |
| | | Thread.Sleep(100); |
| | | } |
| | | } while (true); |
| | | |
| | | LogAsync(DateTime.Now, $"传感器启动成功", ""); |
| | | StartSensor(); |
| | | } |
| | | |
| | | if (!opConfig.IsSnapshotAction) |
| | |
| | | if (!_snapHandle.WaitOne(IIConfig.SnapshotTimeout)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{Name}获取图像超时", ""); |
| | | return null; |
| | | return imgSet; |
| | | } |
| | | |
| | | dataSet = _currentData; |
| | | |
| | | //dataSet = system.ReceiveData(IIConfig.SnapshotTimeout); |
| | | } |
| | | } |
| | | else |
| | |
| | | { |
| | | if (!opConfig.IsOpenConnection) |
| | | { |
| | | while (sensor.State == GoState.Busy) |
| | | { |
| | | Thread.Sleep(100); |
| | | } |
| | | |
| | | do |
| | | { |
| | | try |
| | | { |
| | | sensor.Stop(); |
| | | |
| | | LogAsync(DateTime.Now, $"传感器状态:{sensor.State.ToString()}", ""); |
| | | if (sensor.State != GoState.Ready) |
| | | { |
| | | Thread.Sleep(100); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, $"关闭异常:{ex.GetExceptionMessage()}", ""); |
| | | Thread.Sleep(100); |
| | | } |
| | | } while (true); |
| | | LogAsync(DateTime.Now, $"传感器关闭成功", ""); |
| | | StopSensor(); |
| | | } |
| | | } |
| | | |
| | | sensor.Flush(); |
| | | |
| | | if (dataSet != null) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | sensor.Flush(); |
| | | return imgSet; |
| | | } |
| | | |
| | | private void StopSensor() |
| | | { |
| | | while (sensor.State == GoState.Busy) |
| | | { |
| | | Thread.Sleep(100); |
| | | } |
| | | |
| | | do |
| | | { |
| | | try |
| | | { |
| | | sensor.Stop(); |
| | | |
| | | LogAsync(DateTime.Now, $"传感器状态:{sensor.State.ToString()}", ""); |
| | | if (sensor.State != GoState.Ready) |
| | | { |
| | | Thread.Sleep(100); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, $"关闭异常:{ex.GetExceptionMessage()}", ""); |
| | | Thread.Sleep(100); |
| | | } |
| | | } while (true); |
| | | LogAsync(DateTime.Now, $"传感器关闭成功", ""); |
| | | } |
| | | |
| | | private void StartSensor() |
| | | { |
| | | while (sensor.State != GoState.Ready) |
| | | { |
| | | Thread.Sleep(10); |
| | | } |
| | | |
| | | do |
| | | { |
| | | try |
| | | { |
| | | sensor.Start(); |
| | | LogAsync(DateTime.Now, $"传感器状态:{sensor.State.ToString()}", ""); |
| | | if (sensor.State != GoState.Running) |
| | | { |
| | | Thread.Sleep(100); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, $"开启异常:{ex.GetExceptionMessage()}", ""); |
| | | Thread.Sleep(100); |
| | | } |
| | | } while (true); |
| | | |
| | | LogAsync(DateTime.Now, $"传感器启动成功", ""); |
| | | } |
| | | |
| | | float _currentExposure = 0; |
| | |
| | | |
| | | system.EnableData(true); |
| | | |
| | | |
| | | if (IIConfig.IsAsyncMode) |
| | | { |
| | | system.SetDataHandler(onData); |
| | |
| | | { |
| | | base.Start(); |
| | | |
| | | if (sensor.State != GoState.Ready) |
| | | { |
| | | system.Start(); |
| | | } |
| | | //if (sensor.State != GoState.Ready) |
| | | //{ |
| | | // system.Start(); |
| | | //} |
| | | |
| | | if (IIConfig.IsAsyncMode) |
| | | { |
| | | sensor.Start(); |
| | | //sensor.Start(); |
| | | |
| | | StartSensor(); |
| | | } |
| | | else |
| | | { |
| | | //if (sensor.State == GoState.Ready) |
| | | { |
| | | sensor.Stop(); |
| | | } |
| | | } |
| | | //else |
| | | //{ |
| | | // //if (sensor.State == GoState.Ready) |
| | | // //{ |
| | | // // sensor.Stop(); |
| | | // //} |
| | | |
| | | // StopSensor(); |
| | | //} |
| | | } |
| | | |
| | | protected override void Stop() |
| | |
| | | base.Stop(); |
| | | |
| | | if (IIConfig.IsAsyncMode) |
| | | system.Stop(); |
| | | { |
| | | StopSensor(); |
| | | } |
| | | |
| | | if (IIConfig.IsUseAccelerator) |
| | | { |
| | |
| | | } |
| | | |
| | | volatile bool _snapFlag = false; |
| | | readonly ManualResetEvent _snapHandle = new ManualResetEvent(false); |
| | | readonly AutoResetEvent _snapHandle = new AutoResetEvent(false); |
| | | |
| | | GoDataSet _currentData = null; |
| | | /// <summary> |
| | |
| | | /// <param name="data"></param> |
| | | private void onData(KObject data) |
| | | { |
| | | LogAsync(DateTime.Now, $"扫描图像输出", ""); |
| | | GoDataSet dataSet = (GoDataSet)data; |
| | | |
| | | if (IIConfig.IsHardwareTrigger) |
| | |
| | | } |
| | | else |
| | | { |
| | | if (_snapFlag) |
| | | //if (_snapFlag) |
| | | { |
| | | _snapFlag = false; |
| | | |
| | | _currentData = dataSet.Clone<GoDataSet>(); |
| | | |
| | | _currentData = dataSet; |
| | | _snapHandle.Set(); |
| | | } |
| | | } |
| | |
| | | if (set == null) |
| | | return; |
| | | |
| | | set.Image = map; |
| | | |
| | | await Task.Run(() => |
| | | { |
| | | lock (set.SaveLock) |
| | |
| | | //SaveImageByNameAndType(map, set.Id, set.ImageSaveOption.ImageFormat, imgDir); |
| | | string filePath = Path.Combine(imgDir, $"{set.Id}.tif"); |
| | | set.HImage_2.WriteImage("tiff", 0, filePath); |
| | | set.HImage_2.Dispose(); |
| | | set.HImage_2 = null; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | if (set.ImageSaveOption.AddtionalSaveType.Contains(prefix) && !set.IsAddtionalSaved) |
| | | { |
| | | string imgDir = CheckImageDirectory(set.ImageSaveOption.ImageSaveSubDirectory, prefix); |
| | | |
| | | while (set.Image == null) |
| | | { |
| | | Thread.Sleep(50); |
| | | } |
| | | |
| | | try |
| | | { |
| | |
| | | |
| | | public override void Dispose() |
| | | { |
| | | base.Dispose(); |
| | | //HImage_2?.Dispose(); |
| | | //HImage_2 = null; |
| | | |
| | | HImage_2?.Dispose(); |
| | | HImage_2 = null; |
| | | base.Dispose(); |
| | | } |
| | | } |
| | | } |
| | |
| | | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 |
| | | //通过使用 "*",如下所示: |
| | | // [assembly: AssemblyVersion("1.0.*")] |
| | | [assembly: AssemblyVersion("1.0.2.0")] |
| | | [assembly: AssemblyFileVersion("1.0.2.0")] |
| | | [assembly: AssemblyVersion("1.0.3.0")] |
| | | [assembly: AssemblyFileVersion("1.0.3.0")] |
| | |
| | | } |
| | | } |
| | | |
| | | [Device("ManualTest", "手动测试操作配置", EnumHelper.DeviceAttributeType.OperationConfig)] |
| | | public class ManualTestOperationConfig : OperationConfigBase |
| | | { |
| | | [Category("手动测试配置")] |
| | | [Description("手动测试重复次数")] |
| | | public int RepeatTimes { get; set; } = 1; |
| | | } |
| | | |
| | | public class OperationCombination : IComplexDisplay, IHalconToolPath |
| | | { |
| | | [Category("运动机构配置")] |
| | |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | AutoResetEvent _jobDoneHandle = new AutoResetEvent(false); |
| | | [ProcessMethod("ManualTest", "ManualTest", "手动测试", InvokeType.TestInvoke)] |
| | | public ProcessResponse ManualTest(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | if (config is ManualTestOperationConfig opConfig) |
| | | { |
| | | Task.Run(async () => |
| | | { |
| | | for (int i = 0; i < opConfig.RepeatTimes; i++) |
| | | { |
| | | BarCode = $"Test_{i + 1}"; |
| | | StartJob(null, null, null); |
| | | |
| | | if (_jobDoneHandle.WaitOne(20000)) |
| | | { |
| | | LogAsync(DateTime.Now, $"第{i + 1}次任务完成", ""); |
| | | await Task.Delay(500); |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, $"第{i + 1}次任务超时", ""); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | return new ProcessResponse(true); |
| | | } |
| | | |
| | | object productionLock = new object(); |
| | | List<ProductionMeasurement> productionList = new List<ProductionMeasurement>(); |
| | | |
| | |
| | | |
| | | private void StartCheck() |
| | | { |
| | | |
| | | if (isRightStart && isLeftStart) |
| | | { |
| | | if (_isdoing) |
| | |
| | | } |
| | | } |
| | | |
| | | _jobDoneHandle.Set(); |
| | | |
| | | var measurementUnitResultAndKeyUnitDataSet = GetMeasurementUnitResultAndKeyUnitData(pMeasure); |
| | | |
| | | if (pMeasure.PResult != "NA") |
| | |
| | | //} |
| | | |
| | | static object excelExportLock = new object(); |
| | | string fileName = ""; |
| | | private async void ExportProductionInColumns(ProductionMeasurementUnitResultAndKeyUnitDataSet exportData) |
| | | { |
| | | if (!Config.IsCSVOutputEnabled) |
| | |
| | | { |
| | | Directory.CreateDirectory(Config.LogPath); |
| | | } |
| | | var fileName = Path.Combine(Config.LogPath, $"LDSData_{DateTime.Now.ToString("yyyyMMdd")}.xlsx"); |
| | | |
| | | if (string.IsNullOrWhiteSpace(fileName)) |
| | | { |
| | | fileName = Path.Combine(Config.LogPath, $"LDSData_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.xlsx"); |
| | | } |
| | | |
| | | try |
| | | { |
| | |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(DateTime.Now, "Excel日志异常", ex.GetExceptionMessage()); |
| | | string bkFileName = Path.Combine(Config.LogPath, $"{Path.GetFileNameWithoutExtension(fileName)}_bk_{DateTime.Now.ToString("HHmmss")}.xlsx"); |
| | | File.Copy(fileName, bkFileName); |
| | | File.Delete(fileName); |
| | | fileName = Path.Combine(Config.LogPath, $"LDSData_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.xlsx"); |
| | | //string bkFileName = Path.Combine(Config.LogPath, $"{Path.GetFileNameWithoutExtension(fileName)}_bk_{DateTime.Now.ToString("HHmmss")}.xlsx"); |
| | | //File.Copy(fileName, bkFileName); |
| | | //File.Delete(fileName); |
| | | } |
| | | } |
| | | }); |
| | |
| | | } |
| | | #endregion |
| | | |
| | | static object _resultCalcLock = new object(); |
| | | |
| | | private async void RunImageHandle(IOperationConfig opConfig, IImageSet imgSet, string snapshotId, string snapshotName, List<MeasurementUnit> measureList) |
| | | { |
| | | await Task.Run(() => |
| | |
| | | // Directory.CreateDirectory(dir); |
| | | //} |
| | | |
| | | //Parallel.For(1, count.I + 1, (i) => |
| | | for (int i = 1; i <= count.I; i++) |
| | | lock (_resultCalcLock) |
| | | { |
| | | HOperatorSet.SelectObj(images, out HObject image, i); |
| | | |
| | | //string fileName = Path.Combine(dir, $"{i}.tif"); |
| | | //using (HImage temp = image.ConvertHObjectToHImage()) |
| | | //{ |
| | | // temp.WriteImage("tiff", 0, fileName); |
| | | //} |
| | | |
| | | keys.Where(u => u.ImageSeq == i).ToList().ForEach(k => |
| | | //Parallel.For(1, count.I + 1, (i) => |
| | | for (int i = 1; i <= count.I; i++) |
| | | { |
| | | Dictionary<string, double> resultDict = null; |
| | | HOperatorSet.SelectObj(images, out HObject image, i); |
| | | |
| | | var keyBindList = keyBindCollection.Where(u => u.Key == k.Key).ToList(); |
| | | //string fileName = Path.Combine(dir, $"{i}.tif"); |
| | | //using (HImage temp = image.ConvertHObjectToHImage()) |
| | | //{ |
| | | // temp.WriteImage("tiff", 0, fileName); |
| | | //} |
| | | |
| | | string keyToolKey = k.AliasName + "|" + k.KeyAlgorithemPath; |
| | | if (!_halconToolDict.ContainsKey(keyToolKey)) |
| | | keys.Where(u => u.ImageSeq == i).ToList().ForEach(k => |
| | | { |
| | | 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)) |
| | | Dictionary<string, double> resultDict = null; |
| | | |
| | | var keyBindList = keyBindCollection.Where(u => u.Key == k.Key).ToList(); |
| | | |
| | | string keyToolKey = k.AliasName + "|" + k.KeyAlgorithemPath; |
| | | if (!_halconToolDict.ContainsKey(keyToolKey)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测算法异常,{error}", ""); |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测算法未初始化", ""); |
| | | } |
| | | else |
| | | { |
| | | var results = _halconToolDict[keyToolKey].GetResultTuple("OUTPUT_Results").DArr.ToList(); |
| | | if (results.Count == 0 || results.Any(u => u < 0)) |
| | | _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}原始数据异常", ""); |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测算法异常,{error}", ""); |
| | | } |
| | | else |
| | | { |
| | | //LogAsync(DateTime.Now, $"{k.AliasName}原始数据", $"{string.Join(" ", results)}"); |
| | | |
| | | results = results.Select(u => u - Config.PlanCompensation).ToList(); |
| | | resultDict = k.KeyResultList.ToDictionary(u => u, u => |
| | | var results = _halconToolDict[keyToolKey].GetResultTuple("OUTPUT_Results").DArr.ToList(); |
| | | if (results.Count == 0 || results.Any(u => u < 0)) |
| | | { |
| | | int index = k.KeyResultList.IndexOf(u); |
| | | return results[index]; |
| | | }); |
| | | LogAsync(DateTime.Now, $"{k.AliasName}原始数据异常", ""); |
| | | } |
| | | else |
| | | { |
| | | //LogAsync(DateTime.Now, $"{k.AliasName}原始数据", $"{string.Join(" ", results)}"); |
| | | |
| | | results = results.Select(u => u - Config.PlanCompensation).ToList(); |
| | | resultDict = k.KeyResultList.ToDictionary(u => u, u => |
| | | { |
| | | int index = k.KeyResultList.IndexOf(u); |
| | | return results[index]; |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | keyBindList.ForEach(kb => |
| | | { |
| | | kb.KeyImages.Add(image.ConvertHObjectToHImage()); |
| | | kb.FillKeyValues(resultDict); |
| | | keyBindList.ForEach(kb => |
| | | { |
| | | kb.KeyImages.Add(image.ConvertHObjectToHImage()); |
| | | kb.FillKeyValues(resultDict); |
| | | }); |
| | | }); |
| | | }); |
| | | |
| | | image.Dispose(); |
| | | image = null; |
| | | image.Dispose(); |
| | | image = null; |
| | | } |
| | | //); |
| | | } |
| | | //); |
| | | |
| | | imgSet.HImage.Dispose(); |
| | | imgSet.HImage = null; |
| | |
| | | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 |
| | | //通过使用 "*",如下所示: |
| | | // [assembly: AssemblyVersion("1.0.*")] |
| | | [assembly: AssemblyVersion("1.0.4.1")] |
| | | [assembly: AssemblyFileVersion("1.0.4.1")] |
| | | [assembly: AssemblyVersion("1.0.5.0")] |
| | | [assembly: AssemblyFileVersion("1.0.5.0")] |
| | |
| | | this.lblOperator = new System.Windows.Forms.Label(); |
| | | this.stStripHint = new System.Windows.Forms.StatusStrip(); |
| | | this.tsslError = new System.Windows.Forms.ToolStripStatusLabel(); |
| | | this.button1 = new System.Windows.Forms.Button(); |
| | | this.contextMenuStrip1.SuspendLayout(); |
| | | this.plImage.SuspendLayout(); |
| | | this.tscEditLocation.ContentPanel.SuspendLayout(); |
| | |
| | | this.tsslError.Size = new System.Drawing.Size(131, 17); |
| | | this.tsslError.Text = "toolStripStatusLabel1"; |
| | | // |
| | | // button1 |
| | | // |
| | | this.button1.Location = new System.Drawing.Point(591, 13); |
| | | this.button1.Name = "button1"; |
| | | this.button1.Size = new System.Drawing.Size(75, 23); |
| | | this.button1.TabIndex = 8; |
| | | this.button1.Text = "button1"; |
| | | this.button1.UseVisualStyleBackColor = true; |
| | | this.button1.Visible = false; |
| | | this.button1.Click += new System.EventHandler(this.button1_Click); |
| | | // |
| | | // M071_MainForm |
| | | // |
| | | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
| | | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
| | | this.ClientSize = new System.Drawing.Size(1069, 351); |
| | | this.Controls.Add(this.button1); |
| | | this.Controls.Add(this.stStripHint); |
| | | this.Controls.Add(this.lblOperator); |
| | | this.Controls.Add(this.btnReset); |
| | |
| | | private System.Windows.Forms.Label lblOperator; |
| | | private System.Windows.Forms.StatusStrip stStripHint; |
| | | private System.Windows.Forms.ToolStripStatusLabel tsslError; |
| | | private System.Windows.Forms.Button button1; |
| | | } |
| | | } |
| | |
| | | M071Config Config => Process?.IConfig as M071Config; |
| | | M071Process Process_M071 => Process as M071Process; |
| | | |
| | | System.Threading.Timer _refreshUITimer = null; |
| | | |
| | | |
| | | public M071_MainForm() |
| | | { |
| | | InitializeComponent(); |
| | |
| | | |
| | | tscEditLocation.Visible = tsmiShowEditor.Checked = false; |
| | | |
| | | _refreshUITimer = new System.Threading.Timer(OnRefreshUI, null, -1, -1); |
| | | this.Load += async (s, e) => |
| | | { |
| | | await Task.Delay(300); |
| | |
| | | cvImage.OnElementChangedHandle -= CvImage_OnElementChangedHandle; |
| | | cvImage.OnElementChangedHandle += CvImage_OnElementChangedHandle; |
| | | |
| | | timer1.Enabled = true; |
| | | //timer1.Enabled = true; |
| | | |
| | | btnReset.Text = $"复位(长按{Config.FullResetRequiredDuration}秒大复位)"; |
| | | |
| | |
| | | #endregion |
| | | |
| | | #region 标签结果显示 |
| | | |
| | | private void OnRefreshUI(object state) |
| | | { |
| | | cvImage.Invoke(new Action(() => Refresh())); |
| | | } |
| | | |
| | | private async void Process_M071_OnElementUpdated(Common.Interface.IShapeElement obj) |
| | | { |
| | | //this.Invoke(new Action(() => |
| | |
| | | (ele as KeyIndicator).Text = keyIndicator.Text; |
| | | (ele as KeyIndicator).ResultState = keyIndicator.ResultState; |
| | | |
| | | this.Invalidate(); |
| | | //this.Invalidate(); |
| | | _refreshUITimer.Change(1000, -1); |
| | | })); |
| | | } |
| | | |
| | |
| | | |
| | | private void timer1_Tick(object sender, EventArgs e) |
| | | { |
| | | cvImage.Refresh(); |
| | | //cvImage.Refresh(); |
| | | } |
| | | |
| | | private void lblOperator_DoubleClick(object sender, EventArgs e) |
| | |
| | | })); |
| | | }); |
| | | } |
| | | |
| | | bool isStart = true; |
| | | private void button1_Click(object sender, EventArgs e) |
| | | { |
| | | Task.Run(async () => |
| | | { |
| | | try |
| | | { |
| | | for (int j = 0; j < 10000; j++) |
| | | { |
| | | int i = 0; |
| | | |
| | | if (isStart) |
| | | { |
| | | cvImage.Elements.ToList().ForEach(ele => |
| | | { |
| | | if (ele is KeyIndicator indicator) |
| | | { |
| | | indicator.Text = ""; |
| | | indicator.ResultState = null; |
| | | } |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | cvImage.Elements.ToList().ForEach(ele => |
| | | { |
| | | if (ele is KeyIndicator indicator) |
| | | { |
| | | indicator.Text = (i++).ToString(); |
| | | indicator.ResultState = true; |
| | | } |
| | | }); |
| | | } |
| | | isStart = !isStart; |
| | | cvImage.BeginInvoke(new Action(() => Refresh())); |
| | | LogAsync(DateTime.Now, $"UI Refresh {j}", ""); |
| | | await Task.Delay(300); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | |
| | | }); |
| | | } |
| | | } |
| | | } |
| | |
| | | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 |
| | | //通过使用 "*",如下所示: |
| | | // [assembly: AssemblyVersion("1.0.*")] |
| | | [assembly: AssemblyVersion("1.0.0.0")] |
| | | [assembly: AssemblyFileVersion("1.0.0.0")] |
| | | [assembly: AssemblyVersion("1.0.1.0")] |
| | | [assembly: AssemblyFileVersion("1.0.1.0")] |
| | |
| | | #endregion |
| | | |
| | | #region 重绘 |
| | | volatile bool _isInRepaint = false; |
| | | object _isInRepaintLock = new object(); |
| | | protected override void OnPaint(PaintEventArgs e) |
| | | { |
| | | //if (_isInRepaint) |
| | | // return; |
| | | |
| | | //lock (_isInRepaintLock) |
| | | //{ |
| | | // if (_isInRepaint) |
| | | // return; |
| | | //} |
| | | |
| | | //_isInRepaint = true; |
| | | |
| | | try |
| | | { |
| | | Rectangle rect = ClientRectangle; |
| | |
| | | Graphics g = myBuffer.Graphics; |
| | | g.SmoothingMode = SmoothingMode.HighSpeed; |
| | | g.PixelOffsetMode = PixelOffsetMode.HighSpeed; |
| | | g.InterpolationMode = InterpolationMode.Low; |
| | | g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; |
| | | g.CompositingQuality = CompositingQuality.HighSpeed; |
| | | g.Clear(BackColor); |
| | | |
| | | g.MultiplyTransform(Matrix); |
| | |
| | | catch (Exception) |
| | | { |
| | | } |
| | | |
| | | _isInRepaint = false; |
| | | } |
| | | |
| | | private void halfTransparent() |