IImageSet添加图片信息序列化输出
操作配置添加输出信息序列化输出
添加激光扫描参数模型
修改CollectionHImage方法,输出IImageSet
| | |
| | | bool IsAddtionalSaved { get; set; } |
| | | |
| | | event Action<ImageSet> OnImageSetTimeout; |
| | | |
| | | /// <summary> |
| | | /// 序列化操作的图像信息 |
| | | /// </summary> |
| | | string ImageData { get; set; } |
| | | } |
| | | |
| | | public class ImageSet : IImageSet |
| | |
| | | |
| | | public object SaveLock { get; set; } = new object(); |
| | | |
| | | public virtual string ImageData { get; set; } |
| | | |
| | | public event Action<ImageSet> OnImageSetTimeout; |
| | | private Timer autoDisposeTimer = null; |
| | | |
| | |
| | | [Browsable(false)] |
| | | [JsonIgnore] |
| | | public virtual string DeviceId { get; set; } = ""; |
| | | |
| | | [Browsable(false)] |
| | | [JsonIgnore] |
| | | public virtual string OutputData { get; set; } = ""; |
| | | } |
| | | |
| | | public class InitialConfigBase : IInitialConfig |
| | |
| | | <Compile Include="Model\CustomizedPoint.cs" /> |
| | | <Compile Include="Model\CustomizedRectangle.cs" /> |
| | | <Compile Include="Model\DeviceOpBind.cs" /> |
| | | <Compile Include="Model\LaserScanParam.cs" /> |
| | | <Compile Include="Model\ModbusFrame.cs" /> |
| | | <Compile Include="Model\MonitorSet.cs" /> |
| | | <Compile Include="Model\MotionCardRelated.cs" /> |
| | |
| | | TextBox tbox = new TextBox |
| | | { |
| | | Dock = DockStyle.Fill, |
| | | Multiline = true |
| | | Multiline = true, |
| | | ScrollBars = ScrollBars.Both, |
| | | }; |
| | | form.Controls.Add(tbox); |
| | | |
| | |
| | | /// 调用该操作配置的设备Id |
| | | /// </summary> |
| | | string DeviceId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 操作执行后部分输出结果,目前拟采用序列化后的字符串方式保存 |
| | | /// </summary> |
| | | string OutputData { get; set; } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace Bro.Common.Model |
| | | { |
| | | public class LaserScanParam |
| | | { |
| | | public int Resolution_X { get; set; } |
| | | public int Resolution_Y { get; set; } |
| | | public int Resolution_Z { get; set; } |
| | | |
| | | public int Offset_X { get; set; } |
| | | public int Offset_Y { get; set; } |
| | | public int Offset_Z { get; set; } |
| | | |
| | | public int Angle_Z { get; set; } |
| | | } |
| | | } |
| | |
| | | <Reference Include="kApiNet"> |
| | | <HintPath>..\..\libs\gocator\kApiNet.dll</HintPath> |
| | | </Reference> |
| | | <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> |
| | | <HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> |
| | | </Reference> |
| | | <Reference Include="System" /> |
| | | <Reference Include="System.Core" /> |
| | | <Reference Include="System.Drawing" /> |
| | |
| | | <CopyToOutputDirectory>Always</CopyToOutputDirectory> |
| | | </Content> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <None Include="packages.config" /> |
| | | </ItemGroup> |
| | | <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
| | | </Project> |
| | |
| | | using Bro.Common.Base; |
| | | using Bro.Common.Helper; |
| | | using Bro.Common.Interface; |
| | | using Bro.Common.Model; |
| | | using HalconDotNet; |
| | | using Lmi3d.GoSdk; |
| | | using Lmi3d.GoSdk.Messages; |
| | | using Lmi3d.Zen; |
| | | using Lmi3d.Zen.Io; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Drawing; |
| | |
| | | imgSet.HImage_2 = new HImage(); |
| | | imgSet.HImage_2.GenImage1("uint2", (int)width, zoomHeight, zoomPtr); |
| | | |
| | | LaserScanParam para = new LaserScanParam() |
| | | { |
| | | Resolution_X = surfaceMsg.XResolution, |
| | | Resolution_Y = surfaceMsg.YResolution, |
| | | Resolution_Z = surfaceMsg.ZResolution, |
| | | Offset_X = surfaceMsg.XOffset, |
| | | Offset_Y = surfaceMsg.YOffset, |
| | | Offset_Z = surfaceMsg.ZOffset, |
| | | Angle_Z = surfaceMsg.ZAngle, |
| | | }; |
| | | imgSet.ImageData = JsonConvert.SerializeObject(para); |
| | | |
| | | //imgSet.HImage_2 = imgSet.HImage_2.ZoomImageSize((int)width, zoomHeight, "constant"); |
| | | } |
| | | |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <packages> |
| | | <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" /> |
| | | </packages> |
| | |
| | | using Bro.M071.Model; |
| | | using Bro.Process; |
| | | using HalconDotNet; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | |
| | | if (camera == null) |
| | | return; |
| | | |
| | | string imgSetId = ""; |
| | | HImage hImage = null; |
| | | IImageSet set = null; |
| | | try |
| | | { |
| | | hImage = CollectHImage(camera, s.CameraOp.OpConfig, out imgSetId); |
| | | set = CollectHImage(camera, s.CameraOp.OpConfig); |
| | | } |
| | | catch (ProcessException pEx) |
| | | { |
| | |
| | | throw pEx; |
| | | } |
| | | |
| | | if (string.IsNullOrWhiteSpace(imgSetId)) |
| | | if (set == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | RunImageHandle(camera, s.CameraOp.OpConfig, hImage, s.Id, s.Name, pMeasure.Measurements); |
| | | RunImageHandle(camera, s.CameraOp.OpConfig, set, s.Id, s.Name, pMeasure.Measurements); |
| | | }); |
| | | |
| | | BarCode = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | private async void RunImageHandle(CameraBase camera, IOperationConfig opConfig, HImage hImage, string snapshotId, string snapshotName, List<MeasurementUnit> measureList) |
| | | private async void RunImageHandle(CameraBase camera, IOperationConfig opConfig, IImageSet imgSet, string snapshotId, string snapshotName, List<MeasurementUnit> measureList) |
| | | { |
| | | await Task.Run(() => |
| | | { |
| | |
| | | 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 = hImage; |
| | | HObject images = imgSet.HImage; |
| | | LaserScanParam scanParam = JsonConvert.DeserializeObject<LaserScanParam>(imgSet.ImageData); |
| | | |
| | | if (!string.IsNullOrWhiteSpace(toolKey)) |
| | | { |
| | |
| | | return; |
| | | } |
| | | |
| | | _halconToolDict[toolKey].InputImageDic["INPUT_Image"] = hImage; |
| | | _halconToolDict[toolKey].InputImageDic["INPUT_Image"] = imgSet.HImage; |
| | | if (!_halconToolDict[toolKey].RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{snapshotName}取图算法异常,{error}", ""); |
| | |
| | | else |
| | | { |
| | | _halconToolDict[keyToolKey].InputImageDic["INPUT_Image"] = image; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_X"] = scanParam.Resolution_X; |
| | | _halconToolDict[keyToolKey].InputTupleDic["INPUT_Resolution_Z"] = scanParam.Resolution_Z; |
| | | if (!_halconToolDict[keyToolKey].RunProcedure(out string error)) |
| | | { |
| | | LogAsync(DateTime.Now, $"{k.AliasName}检测算法异常,{error}", ""); |
| | |
| | | image.Dispose(); |
| | | }); |
| | | |
| | | if (count.I != 1) |
| | | { |
| | | hImage?.Dispose(); |
| | | hImage = null; |
| | | } |
| | | //if (count.I != 1) |
| | | //{ |
| | | // hImage?.Dispose(); |
| | | // hImage = null; |
| | | //} |
| | | }); |
| | | } |
| | | #endregion |
| | |
| | | #endregion |
| | | |
| | | #region 图像处理 |
| | | protected HImage CollectHImage(CameraBase camera, IOperationConfig opConfig, out string imgSetId, [CallerMemberName]string methodCode = "") |
| | | protected IImageSet CollectHImage(CameraBase camera, IOperationConfig opConfig, [CallerMemberName]string methodCode = "") |
| | | { |
| | | IImageSet set = null; |
| | | |
| | |
| | | TimeRecordCSV(DateTime.Now, camera.Name, methodCode + "采图", (int)sw.ElapsedMilliseconds); |
| | | } |
| | | |
| | | imgSetId = set?.Id; |
| | | return set.HImage; |
| | | return set; |
| | | } |
| | | |
| | | protected async void CameraUpdateImage(CameraBase camera, Bitmap image, string setId) |
| | |
| | | { |
| | | //string imgSetId = ""; |
| | | List<IShapeElement> pointList = new List<IShapeElement>(); |
| | | using (HObject hImage = CollectHImage(camera, config.CameraOpConfig, out string imgSetId)) |
| | | |
| | | IImageSet set = CollectHImage(camera, config.CameraOpConfig); |
| | | if (set == null) |
| | | return; |
| | | |
| | | using (HObject hImage = set.HImage) |
| | | { |
| | | var tool = GetHalconTool(config.CameraOpConfig); |
| | | |
| | |
| | | pointList.Add(new PointIndicator((float)xList[i], (float)yList[i])); |
| | | } |
| | | |
| | | camera.SaveFitImage(pointList, imgSetId); |
| | | camera.SaveFitImage(pointList, set.Id); |
| | | } |
| | | |
| | | config.Results[sequence - 1].ImageMarkPoint = new CustomizedPoint((pointList[0] as PointIndicator).Center); |