Merge branch 'master' into feature/HR_Camera
| | |
| | | |
| | | Name = "AllProcessesPage"; |
| | | Text = "主界面"; |
| | | //this.Font = new Font("Microsoft YaHei UI", 16F, FontStyle.Regular, GraphicsUnit.Point, 0); |
| | | this.BackColor = Color.FromArgb(32, 41, 50); |
| | | |
| | | InitVisionUI(); |
| | |
| | | |
| | | public void InitVisionUI() |
| | | { |
| | | this.controlsPanel.Dock = DockStyle.Fill; |
| | | List<string> keys = dicProcessControls.Keys.ToList(); |
| | | |
| | | foreach (var title in keys) |
| | |
| | | foreach (var layout in GlobalVar.dicLayout.Values) |
| | | { |
| | | if (GlobalVar.dicProcesses.ContainsKey(layout.ProcessName)) |
| | | { |
| | | enableLayout++; |
| | | } |
| | | } |
| | | |
| | | int index = 0; |
| | |
| | | ProcessControl processControl = dicProcessControls[title]; |
| | | processControl.Size |
| | | = new Size(this.controlsPanel.Size.Width / enableLayout |
| | | , this.controlsPanel.Size.Height-40); |
| | | , this.controlsPanel.Size.Height); |
| | | processControl.Location |
| | | = new Point(processControl.Size.Width * index, 0); |
| | | |
| | | if (GlobalVar.dicProcesses[name].GetImage(GlobalVar.dicLayout[i], out _, out HObject RecordImage)) |
| | | { |
| | | dicProcessControls[title].ShowHoImage(RecordImage); |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | this.controlsPanel.Controls.Add(processControl); |
| | | |
| | | if (GlobalVar.dicProcesses[name].GetImage(GlobalVar.dicLayout[i], out _, out HObject RecordImage)) |
| | | { |
| | | dicProcessControls[title].ShowHoImage(RecordImage); |
| | | } |
| | | } |
| | | index++; |
| | | } |
| | |
| | | })); |
| | | } |
| | | else |
| | | { |
| | | UserHSmartWindowControl.ClearObj(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | })); |
| | | } |
| | | else |
| | | { |
| | | this.label1.Text = $"总数:{ProcessRunBll.total}"; |
| | | } |
| | | } |
| | | |
| | | public bool Run(out string msg) |
| | |
| | | } |
| | | |
| | | if (isCircleRuning || ProcessRunBll.bRuning) |
| | | { |
| | | ProcessRunBll.LogInfo($"{ProcessRunBll.Name}正在运行", LogInfoType.ERROR); |
| | | } |
| | | |
| | | ProcessRunBll.Run(); |
| | | |
| | |
| | | try |
| | | { |
| | | if (ProcessRunBll == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | ProcessRunBll.LogInfo(string.Format("流程[{0}]开始运行", this.ProcessRunBll.Name), LogInfoType.INFO); |
| | | |
| | |
| | | result = Run(out msg); |
| | | |
| | | if (ProcessRunBll.GetImage(_Layout, out _, out HObject RecordImage)) |
| | | { |
| | | ShowHoImage(RecordImage); |
| | | } |
| | | } |
| | | catch { msg = "运行出现了异常"; } |
| | | |
| | |
| | | else |
| | | { |
| | | isCircleRuning = false; |
| | | //threadCircleRun.Abort(); |
| | | threadCircleRun.Abort(); |
| | | } |
| | | } |
| | | catch { } |
| | |
| | | , result ? LogInfoType.PASS : LogInfoType.ERROR); |
| | | |
| | | if (ProcessRunBll.GetImage(_Layout, out _, out HObject RecordImage)) |
| | | { |
| | | ShowHoImage(RecordImage); |
| | | } |
| | | } |
| | | catch { } |
| | | //})); |
| | | |
| | | Thread.Sleep(33); |
| | | Thread.Sleep(100); |
| | | } |
| | | } |
| | | |
| | |
| | | return res; |
| | | } |
| | | |
| | | public bool GetImage(Layout layout, out HImage InputImage, out HObject RecordImage) |
| | | public bool GetImage(Layout layout, out HObject InputImage, out HObject RecordImage) |
| | | { |
| | | InputImage = null; RecordImage = null; |
| | | try |
| | |
| | | IndexValueName = arrOutputs[2]; |
| | | |
| | | object o_InputImage = ((IProcess)dicContext[IndexProcessName]).OutputImage; |
| | | if (o_InputImage != null && o_InputImage is HImage ho_image && ho_image.IsInitialized()) |
| | | { |
| | | InputImage = ho_image.Clone(); |
| | | ho_image.Dispose(); |
| | | } |
| | | else if (o_InputImage != null && o_InputImage is Bitmap) |
| | | if (o_InputImage is HObject ho_image && ho_image.IsInitialized()) |
| | | InputImage = ho_image; |
| | | else if (o_InputImage is Bitmap) |
| | | { |
| | | //将Mat转换为HObject |
| | | using (HImage ho_RecordImage = TAlgorithm.Bitmap2HObject((Bitmap)o_InputImage)) |
| | | { |
| | | if (ho_RecordImage != null) |
| | | { |
| | | InputImage = ho_RecordImage.Clone(); |
| | | TAlgorithm.Bitmap2HObject((Bitmap)o_InputImage, out HObject ho_RecordImage); |
| | | InputImage = ho_RecordImage; |
| | | } |
| | | } |
| | | } |
| | | else if (o_InputImage != null && o_InputImage is Mat) |
| | | else if (o_InputImage is Mat) |
| | | { |
| | | //将Mat转换为HObject |
| | | using (HImage ho_RecordImage = TAlgorithm.Mat2HObject((Mat)o_InputImage)) |
| | | { |
| | | if (ho_RecordImage != null) |
| | | { |
| | | InputImage = ho_RecordImage.Clone(); |
| | | } |
| | | } |
| | | TAlgorithm.Mat2HObject((Mat)o_InputImage, out HObject ho_RecordImage); |
| | | InputImage = ho_RecordImage; |
| | | } |
| | | |
| | | if (InputImage != null && InputImage.IsInitialized()) |
| | | { |
| | | InputImage.GetImageSize(out ho_ImageWidth, out ho_ImageHeight); |
| | | HOperatorSet.GetImageSize(InputImage, out ho_ImageWidth, out ho_ImageHeight); |
| | | |
| | | //图片尺寸变化才更新窗口尺寸[提高速度] |
| | | if ((ho_ImageWidth.Length > 0 && ho_ImageWidth.TupleInt() != hWindowControl.Size.Width) |
| | |
| | | if (dicContext.TryGetValue(ProcessName, out IProcess obj) |
| | | && obj is IProcess process) |
| | | { |
| | | if (process.InputImage != null) |
| | | { |
| | | if (process.InputImage is HObject) |
| | | { |
| | | ((HObject)process.InputImage).Dispose(); |
| | | } |
| | | else if (process.InputImage is Mat) |
| | | { |
| | | ((Mat)process.InputImage).Dispose(); |
| | | } |
| | | else if (process.InputImage is Bitmap) |
| | | { |
| | | ((Bitmap)process.InputImage).Dispose(); |
| | | } |
| | | process.InputImage = null; |
| | | } |
| | | if (process.OutputImage != null) |
| | | { |
| | | if (process.OutputImage is HObject) |
| | | { |
| | | ((HObject)process.OutputImage).Dispose(); |
| | | } |
| | | else if (process.OutputImage is Mat) |
| | | { |
| | | ((Mat)process.OutputImage).Dispose(); |
| | | } |
| | | else if (process.OutputImage is Bitmap) |
| | | { |
| | | ((Bitmap)process.OutputImage).Dispose(); |
| | | } |
| | | process.OutputImage = null; |
| | | } |
| | | UpdateInputs(process); |
| | | |
| | | // 不同节点跳过的方式不同 |
| | |
| | | [Node("相机取图", "取像工具", "Basic", "相机取图")] |
| | | public void 相机取图(FlowNode node) { RunNodeAsync(node); } |
| | | |
| | | [Node("Halcon2D斑点工具", "Halcon2D工具", "Basic", "Halcon2D斑点工具")] |
| | | [Node("Halcon2D斑点工具", "Haclon2D工具", "Basic", "Halcon2D斑点工具")] |
| | | public void Halcon2D斑点工具(FlowNode node) { RunNodeAsync(node); } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | |
| | |
| | | /// </summary> |
| | | public double RunTime = 0; |
| | | |
| | | public bool GetImage(Forms.Pages.SettingPage.Layout layout, out HImage InputImage, out HObject RecordImage) |
| | | public bool GetImage(Forms.Pages.SettingPage.Layout layout, out HObject InputImage, out HObject RecordImage) |
| | | { |
| | | return ProcessContext.GetImage(layout, out InputImage, out RecordImage); |
| | | } |
| | | |
| | | public bool GetImage(out HImage InputImage, out HObject RecordImage) |
| | | public bool GetImage(out HObject InputImage, out HObject RecordImage) |
| | | { |
| | | InputImage = null; |
| | | RecordImage = null; |
| | |
| | | catch { } |
| | | } |
| | | // 生成图片并显示到控件中 |
| | | HImage InputImage = null; |
| | | HObject InputImage = null; |
| | | HObject RecordImage = null; |
| | | |
| | | foreach (var layout in GlobalVar.dicLayout.Values |
| | |
| | | using HalconDotNet; |
| | | using Sunny.UI.Win32; |
| | | using System.Diagnostics; |
| | | |
| | | namespace LB_VisionControl |
| | |
| | | context.CurrentBranchName = $"{currentNode.Text}-Branch{currentNode.BranchIndex}"; |
| | | bool result = Context.ExecuteNode(currentNode); |
| | | #if DEBUG |
| | | Debug.WriteLine($"执行节点[{currentNode.Text}],结果为{result}"); |
| | | Debug.WriteLine(DateTime.Now.ToString("[yyyy:MM:dd:HH:mm:ss:fff] ") + $"执行节点[{currentNode.Text}],结果为{result}"); |
| | | #endif |
| | | context.BranchResults.TryAdd(context.CurrentBranchName, currentNode.Result); |
| | | currentNode.Result = result; |
| | |
| | | /// <summary> |
| | | /// 读写锁 |
| | | /// </summary> |
| | | public readonly object lockObj = new object(); |
| | | public static readonly object lockObj = new object(); |
| | | |
| | | /// <summary> |
| | | /// 裁切图片为hoDomainImage(保留原坐标系,其余填充为空) |
| | |
| | | { |
| | | if (InputImage is Bitmap) |
| | | { |
| | | Bitmap2Mat((Bitmap)InputImage, out Mat src); |
| | | TAlgorithm.Bitmap2Mat((Bitmap)InputImage, out Mat src); |
| | | |
| | | if (Params.Fixture == null) |
| | | Params.Fixture = new Fixture(); |
| | |
| | | |
| | | // 4. 创建与原图大小相同的Mat,并初始化无效值 |
| | | image = new Mat(src.Size(), src.Type()); |
| | | ((Mat)image).SetTo(GetInvalidValueForMat(src)); // 全部初始化为无效值 |
| | | ((Mat)image).SetTo(TAlgorithm.GetInvalidValueForMat(src)); // 全部初始化为无效值 |
| | | |
| | | // 5. 创建遮罩:在result上绘制旋转矩形(白色填充) |
| | | using (Mat cropped = new Mat(src, boundingRect)) |
| | |
| | | |
| | | // 2. 创建与原图大小相同的Mat,并初始化无效值 |
| | | image = new Mat(src.Size(), src.Type()); |
| | | ((Mat)image).SetTo(GetInvalidValueForMat(src)); // 全部初始化为无效值 |
| | | ((Mat)image).SetTo(TAlgorithm.GetInvalidValueForMat(src)); // 全部初始化为无效值 |
| | | |
| | | // 3. 创建圆形遮罩 |
| | | using (Mat mask = Mat.Zeros(src.Rows, src.Cols, MatType.CV_8UC1)) |
| | |
| | | image = ((Bitmap)InputImage)?.Clone(); |
| | | return true; |
| | | } |
| | | Mat2Bitmap((Mat)image, out Bitmap bmp); |
| | | TAlgorithm.Mat2Bitmap((Mat)image, out Bitmap bmp); |
| | | image = bmp; |
| | | return true; |
| | | } |
| | | else if (InputImage is HObject ho_image) |
| | | { |
| | | if (!ho_image.IsInitialized()) |
| | | return false; |
| | | |
| | | if (Params.Fixture == null) |
| | | Params.Fixture = new Fixture(); |
| | | |
| | | HObject hoDomainImage = null; |
| | | |
| | | switch (Params.ROI?.GetType().Name) |
| | | { |
| | | case "HRectangle2": |
| | | HOperatorSet.GenRectangle2(out HObject hRectangle2, (HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column) |
| | | , (HTuple)(Params.ROI.Phi + Params.Fixture.Phi), (HTuple)((HRectangle2)Params.ROI).SemiLength1, (HTuple)((HRectangle2)Params.ROI).SemiLength2); |
| | | HOperatorSet.ReduceDomain(ho_image, hRectangle2, out hoDomainImage); |
| | | break; |
| | | case "HCircle": |
| | | HOperatorSet.GenCircle(out HObject hCircle, (HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column) |
| | | , (HTuple)((HCircle)Params.ROI).Radius); |
| | | HOperatorSet.ReduceDomain(ho_image, hCircle, out hoDomainImage); |
| | | break; |
| | | case "ROI": |
| | | default: |
| | | image = ho_image.CopyObj(1, -1); |
| | | return true; |
| | | } |
| | | |
| | | image = hoDomainImage; |
| | | return true; |
| | | } |
| | | else if (InputImage is Mat) |
| | |
| | | |
| | | // 4. 创建与原图大小相同的Mat,并初始化无效值 |
| | | image = new Mat(src.Size(), src.Type()); |
| | | ((Mat)image).SetTo(GetInvalidValueForMat(src)); // 全部初始化为无效值 |
| | | ((Mat)image).SetTo(TAlgorithm.GetInvalidValueForMat(src)); // 全部初始化为无效值 |
| | | |
| | | // 5. 创建遮罩:在result上绘制旋转矩形(白色填充) |
| | | using (Mat cropped = new Mat(src, boundingRect)) |
| | |
| | | |
| | | // 2. 创建与原图大小相同的Mat,并初始化无效值 |
| | | image = new Mat(src.Size(), src.Type()); |
| | | ((Mat)image).SetTo(GetInvalidValueForMat(src)); // 全部初始化为无效值 |
| | | ((Mat)image).SetTo(TAlgorithm.GetInvalidValueForMat(src)); // 全部初始化为无效值 |
| | | |
| | | // 3. 创建圆形遮罩 |
| | | using (Mat mask = Mat.Zeros(src.Rows, src.Cols, MatType.CV_8UC1)) |
| | |
| | | } |
| | | } |
| | | |
| | | public virtual bool ReduceDomainImage(object InputImage, ref HImage image) |
| | | { |
| | | image = null; |
| | | if (InputImage == null) |
| | | { |
| | | image = null; |
| | | Msg = "输入图片为空"; |
| | | Result = false; |
| | | return false; |
| | | } |
| | | |
| | | lock (InputImage) |
| | | { |
| | | try |
| | | { |
| | | if (InputImage is HImage ho_image) |
| | | { |
| | | if (!ho_image.IsInitialized()) |
| | | return false; |
| | | |
| | | if (Params.Fixture == null) |
| | | Params.Fixture = new Fixture(); |
| | | |
| | | HImage hoDomainImage = null; |
| | | |
| | | switch (Params.ROI?.GetType().Name) |
| | | { |
| | | case "HRectangle2": |
| | | using (HRegion hRectangle2 = new HRegion()) |
| | | { |
| | | hRectangle2.GenRectangle2((HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column) |
| | | , (HTuple)(Params.ROI.Phi + Params.Fixture.Phi), (HTuple)((HRectangle2)Params.ROI).SemiLength1, (HTuple)((HRectangle2)Params.ROI).SemiLength2); |
| | | hoDomainImage = ho_image.ReduceDomain(hRectangle2); |
| | | } |
| | | break; |
| | | case "HCircle": |
| | | using (HRegion hCircle = new HRegion()) |
| | | { |
| | | hCircle.GenCircle((HTuple)(Params.ROI.Row + Params.Fixture.Row), (HTuple)(Params.ROI.Column + Params.Fixture.Column) |
| | | , (HTuple)((HCircle)Params.ROI).Radius); |
| | | hoDomainImage = ho_image.ReduceDomain(hCircle); |
| | | } |
| | | break; |
| | | case "ROI": |
| | | default: |
| | | image = ho_image.CopyObj(1, -1); |
| | | return true; |
| | | } |
| | | |
| | | image = hoDomainImage; |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | image = null; |
| | | Msg = $"输入格式不正确{InputImage.GetType()}"; |
| | | Result = false; |
| | | return false; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | image = null; |
| | | Msg = $"裁剪区域失败,原因是:{ex.ToString()}"; |
| | | Result = false; |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public override void Dispose() |
| | | { |
| | | if (InputImage != null) |
| | | { |
| | | if (InputImage is HObject) |
| | | { |
| | | ((HObject)InputImage).Dispose(); |
| | | } |
| | | else if (InputImage is Mat) |
| | | { |
| | | ((Mat)InputImage).Dispose(); |
| | | } |
| | | else if (InputImage is Bitmap) |
| | | { |
| | | ((Bitmap)InputImage).Dispose(); |
| | | } |
| | | |
| | | InputImage = null; |
| | | } |
| | | |
| | | if (OutputImage != null) |
| | | { |
| | | if (OutputImage is HObject) |
| | | { |
| | | ((HObject)OutputImage).Dispose(); |
| | | } |
| | | else if (OutputImage is Mat) |
| | | { |
| | | ((Mat)OutputImage).Dispose(); |
| | | } |
| | | else if (OutputImage is Bitmap) |
| | | { |
| | | ((Bitmap)OutputImage).Dispose(); |
| | | } |
| | | |
| | | OutputImage = null; |
| | | } |
| | | |
| | | if (Record != null) |
| | | { |
| | | Record.Dispose(); |
| | |
| | | if (InputImage != null) |
| | | { |
| | | if (InputImage is HObject ho_image && ho_image.IsInitialized()) |
| | | { |
| | | obj.InputImage = ho_image.CopyObj(1, -1); |
| | | } |
| | | else if (InputImage is Mat mat && !mat.Empty()) |
| | | { |
| | | obj.InputImage = mat.Clone(); |
| | | } |
| | | else if (InputImage is Bitmap bitmap) |
| | | { |
| | | obj.InputImage = bitmap.Clone(); |
| | | } |
| | | } |
| | | |
| | | return obj; |
| | | } |
| | | catch { return (TAlgorithm)MemberwiseClone(); } |
| | |
| | | { |
| | | Result = true; |
| | | bCompleted = false; |
| | | Msg = string.Empty; |
| | | //if (InputImage != null) |
| | | //{ |
| | | // if (InputImage is HObject) |
| | | // { |
| | | // ((HObject)InputImage).Dispose(); |
| | | // } |
| | | // else if (InputImage is Mat) |
| | | // { |
| | | // ((Mat)InputImage).Dispose(); |
| | | // } |
| | | // else if (InputImage is Bitmap) |
| | | // { |
| | | // ((Bitmap)InputImage).Dispose(); |
| | | // } |
| | | // InputImage = null; |
| | | //} |
| | | Msg = ""; |
| | | OutputImage = null; |
| | | |
| | | if (Record != null) |
| | | { |
| | | Record.Dispose(); |
| | | } |
| | | } |
| | | |
| | | public override bool Run() |
| | | { |
| | | DateTime StartTime = DateTime.Now; |
| | | |
| | | InitRunParams(); |
| | | HOperatorSet.GenEmptyObj(out HObject EmptyObj); |
| | | OutputImage = EmptyObj; |
| | |
| | | |
| | | Thread.Sleep(30); |
| | | } |
| | | |
| | | Msg = "运行超时"; |
| | | Result = false; |
| | | RunTime = (DateTime.Now - StartTime).TotalMilliseconds; |
| | |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(fullPath)) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if (!fullPath.Contains(".json")) |
| | | { |
| | | Debug.WriteLine("文件路径不完整"); |
| | |
| | | Debug.WriteLine("文件路径不完整"); |
| | | return false; |
| | | } |
| | | |
| | | // 获取不带文件名的目录路径 |
| | | string directoryPath = Path.GetDirectoryName(fullPath); |
| | | strProcessName = Path.GetFileNameWithoutExtension(fullPath); |
| | |
| | | Save(directoryPath); |
| | | return true; |
| | | } |
| | | |
| | | string strJson = string.Empty; |
| | | using (StreamReader streamReader = new StreamReader(fullPath, Encoding.UTF8)) |
| | | { |
| | |
| | | } |
| | | Params = JsonConvert.DeserializeObject<ProcessParams>(strJson); |
| | | if (Params == null) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | Params.FixDeserializedData(); |
| | | return true; |
| | | } |
| | |
| | | return value; |
| | | } |
| | | |
| | | public static HImage Bitmap2HObject(Bitmap bmp) |
| | | public static void Bitmap2HObject(Bitmap bmp, out HObject image) |
| | | { |
| | | BitmapData srcBmpData; |
| | | HImage image = null; |
| | | |
| | | try |
| | | { |
| | | if (bmp.Tag != null && bmp == null || bmp.Width == 0 || bmp.Height == 0) |
| | | if (bmp == null || bmp.Width == 0 || bmp.Height == 0) |
| | | { |
| | | image = null; |
| | | return image; |
| | | return; |
| | | } |
| | | |
| | | lock (bmp) |
| | | { |
| | | image = new HImage(); |
| | | switch (bmp.PixelFormat) |
| | | { |
| | | case PixelFormat.Format24bppRgb: |
| | |
| | | int width = bmp.Width; |
| | | int height = bmp.Height; |
| | | int stride = srcBmpData.Stride; |
| | | |
| | | if (stride == width * 3) |
| | | { |
| | | image.GenImageInterleaved(srcBmpData.Scan0, "bgr", bmp.Width, bmp.Height, 0, "byte", 0, 0, 0, 0, -1, 0); |
| | | } |
| | | HOperatorSet.GenImageInterleaved(out image, srcBmpData.Scan0, "bgr", bmp.Width, bmp.Height, 0, "byte", 0, 0, 0, 0, -1, 0); |
| | | else |
| | | { |
| | | image = HandleStrideAlignmentBest(srcBmpData.Scan0, width, height, stride); |
| | | } |
| | | |
| | | bmp.UnlockBits(srcBmpData); |
| | | break; |
| | | default: |
| | | srcBmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed); |
| | | image.GenImage1("byte", bmp.Width, bmp.Height, srcBmpData.Scan0); |
| | | HOperatorSet.GenImage1(out image, "byte", bmp.Width, bmp.Height, srcBmpData.Scan0); |
| | | bmp.UnlockBits(srcBmpData); |
| | | break; |
| | | } |
| | | } |
| | | return image; |
| | | return; |
| | | } |
| | | catch |
| | | { |
| | | if (image != null) |
| | | { |
| | | image.Dispose(); |
| | | } |
| | | image = null; |
| | | return image; |
| | | return; |
| | | } |
| | | } |
| | | |
| | | private static HImage HandleStrideAlignmentBest(IntPtr scan0, int width, int height, int stride) |
| | | private static HObject HandleStrideAlignmentBest(IntPtr scan0, int width, int height, int stride) |
| | | { |
| | | int expectedStride = width * 3; |
| | | byte[] alignedData = new byte[width * height * 3]; |
| | | HImage image = new HImage(); |
| | | |
| | | unsafe |
| | | { |
| | | byte* srcPtr = (byte*)scan0; |
| | |
| | | expectedStride |
| | | ); |
| | | } |
| | | image.GenImageInterleaved(new IntPtr(dstPtr), "bgr", width, height, 0, "byte", width, height, 0, 0, -1, 0); |
| | | return image; |
| | | HOperatorSet.GenImageInterleaved(out HObject ho_img, new IntPtr(dstPtr), "bgr", width, height, 0, "byte", width, height, 0, 0, -1, 0); |
| | | return ho_img; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static unsafe void HObject2Bitmap(HImage hImage, out Bitmap bmp) |
| | | public static unsafe void HObject2Bitmap(HObject hObject, out Bitmap bmp) |
| | | { |
| | | try |
| | | { |
| | | if (hImage == null || !hImage.IsInitialized()) |
| | | if (hObject == null || !hObject.IsInitialized()) |
| | | { |
| | | bmp = null; |
| | | return; |
| | | } |
| | | |
| | | // 获取图像信息 |
| | | hImage.GetImageSize(out HTuple width, out HTuple height); |
| | | HTuple channels = hImage.CountChannels(); |
| | | HOperatorSet.GetImageSize(hObject, out HTuple width, out HTuple height); |
| | | HOperatorSet.CountChannels(hObject, out HTuple channels); |
| | | |
| | | if (channels.I == 1) |
| | | { |
| | | // 灰度图处理 |
| | | HTuple ptr, type; |
| | | ptr = hImage.GetImagePointer1(out type, out width, out height); |
| | | HOperatorSet.GetImagePointer1(hObject, out ptr, out type, out width, out height); |
| | | |
| | | bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed); |
| | | |
| | |
| | | { |
| | | // 彩色图处理(BGR顺序) |
| | | HTuple ptrR, ptrG, ptrB, type; |
| | | hImage.GetImagePointer3(out ptrR, out ptrG, out ptrB, out type, out width, out height); |
| | | HOperatorSet.GetImagePointer3(hObject, out ptrR, out ptrG, out ptrB, out type, out width, out height); |
| | | |
| | | bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb); |
| | | BitmapData bmpData = bmp.LockBits( |
| | |
| | | } |
| | | } |
| | | |
| | | public static HImage Mat2HObject(Mat mat) |
| | | public static void Mat2HObject(Mat mat, out HObject image) |
| | | { |
| | | HImage image = null; |
| | | try |
| | | { |
| | | if (mat == null || mat.Empty()) |
| | | { |
| | | return image; |
| | | image = null; |
| | | return; |
| | | } |
| | | |
| | | if (mat.Type() == MatType.CV_8UC3) // 彩色图像 (BGR) |
| | | { |
| | | image = new HImage(); |
| | | image.GenImageInterleaved( |
| | | HOperatorSet.GenImageInterleaved( |
| | | out image, |
| | | mat.Data, |
| | | "bgr", |
| | | mat.Width, |
| | |
| | | } |
| | | else if (mat.Type() == MatType.CV_8UC1) // 灰度图像 |
| | | { |
| | | image = new HImage(); |
| | | image.GenImage1( |
| | | HOperatorSet.GenImage1( |
| | | out image, |
| | | "byte", |
| | | mat.Width, |
| | | mat.Height, |
| | |
| | | else |
| | | { |
| | | throw new ArgumentException($"Mat2HObject不支持的图像格式:{mat.Type()}"); |
| | | return; |
| | | } |
| | | return image; |
| | | return; |
| | | } |
| | | catch |
| | | { |
| | | image = null; |
| | | return image; |
| | | return; |
| | | } |
| | | } |
| | | |
| | |
| | | HOperatorSet.GenImageConst(out image, "real", hv_xMax + 1, hv_yMax + 1); |
| | | HOperatorSet.SetGrayval(image, hv_y, hv_x, hv_z); |
| | | |
| | | //hoperatorset.getimagesize(ho_image, out htuple hv_width, out htuple hv_height); |
| | | //hoperatorset.genrectangle1(out hobject ho_rectangle, 0, 0, hv_height - 1, hv_width - 1); |
| | | //hoperatorset.getregionpoints(ho_rectangle, out htuple hv_rows, out htuple hv_columns); |
| | | //hoperatorset.getgrayval(ho_image, hv_rows, hv_columns, out htuple hv_z); |
| | | //HOperatorSet.GetImageSize(ho_Image, out HTuple hv_Width, out HTuple hv_Height); |
| | | //HOperatorSet.GenRectangle1(out HObject ho_Rectangle, 0, 0, hv_Height - 1, hv_Width - 1); |
| | | //HOperatorSet.GetRegionPoints(ho_Rectangle, out HTuple hv_Rows, out HTuple hv_Columns); |
| | | //HOperatorSet.GetGrayval(ho_Image, hv_Rows, hv_Columns, out HTuple hv_Z); |
| | | } |
| | | catch { image = null; } |
| | | } |
| | |
| | | /// <param name="startPoint"></param> |
| | | /// <param name="endPoint"></param> |
| | | /// <returns></returns> |
| | | public double GetDistanceP2P(HPoint startPoint, HPoint endPoint) |
| | | public static double GetDistanceP2P(HPoint startPoint, HPoint endPoint) |
| | | { |
| | | try |
| | | { |
| | |
| | | catch { return 9994; } |
| | | } |
| | | |
| | | public double GetDistanceP2P(Point startPoint, Point endPoint) |
| | | public static double GetDistanceP2P(Point startPoint, Point endPoint) |
| | | { |
| | | return GetDistanceP2P(new HPoint(startPoint), new HPoint(endPoint)); |
| | | } |
| | | |
| | | public double DistanceP2P(double startX, double startY, double endX, double endY) |
| | | public static double DistanceP2P(double startX, double startY, double endX, double endY) |
| | | { |
| | | return GetDistanceP2P(new HPoint(startX, startY), new HPoint(endX, endY)); |
| | | } |
| | |
| | | /// <param name="startPoint"></param> |
| | | /// <param name="endPoint"></param> |
| | | /// <returns></returns> |
| | | public HPoint GetMidPoint(HPoint startPoint, HPoint endPoint) |
| | | public static HPoint GetMidPoint(HPoint startPoint, HPoint endPoint) |
| | | { |
| | | return new HPoint((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2); |
| | | } |
| | | |
| | | public Point GetMidPoint(Point startPoint, Point endPoint) |
| | | public static Point GetMidPoint(Point startPoint, Point endPoint) |
| | | { |
| | | return new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2); |
| | | } |
| | | |
| | | public System.Drawing.Point GetMidPoint(System.Drawing.Point startPoint, System.Drawing.Point endPoint) |
| | | public static System.Drawing.Point GetMidPoint(System.Drawing.Point startPoint, System.Drawing.Point endPoint) |
| | | { |
| | | return new System.Drawing.Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2); |
| | | } |
| | |
| | | /// <param name="point"></param> |
| | | /// <param name="segment"></param> |
| | | /// <returns></returns> |
| | | public bool IsPointOnSegment(HPoint pt, HSegment segment, double tolerance = 1e-3) |
| | | public static bool IsPointOnSegment(HPoint pt, HSegment segment, double tolerance = 1e-3) |
| | | { |
| | | // 计算直线方程的系数 |
| | | double A = segment.EndY - segment.StartX; |
| | |
| | | return false; |
| | | } |
| | | |
| | | public bool IsPointOnSegment(double px, double py, double x1, double y1, double x2, double y2) |
| | | public static bool IsPointOnSegment(double px, double py, double x1, double y1, double x2, double y2) |
| | | { |
| | | return IsPointOnSegment(new HPoint(px, py), new HSegment(x1, y1, x2, y2)); |
| | | } |
| | |
| | | catch { return false; } |
| | | } |
| | | |
| | | public bool IsPointNearRectangleSilde(HPoint pt, HRectangle2 rect, double tolerance = 100) |
| | | public static bool IsPointNearRectangleSilde(HPoint pt, HRectangle2 rect, double tolerance = 100) |
| | | { |
| | | return IsPointNearRectangleSilde(new System.Drawing.Point((int)pt.X, (int)pt.Y), new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), tolerance); |
| | | } |
| | |
| | | /// <param name="pt2"></param> |
| | | /// <param name="tolerance"></param> |
| | | /// <returns></returns> |
| | | public bool IsPointNearPoint(HPoint pt1, HPoint pt2, double tolerance = 100) |
| | | public static bool IsPointNearPoint(HPoint pt1, HPoint pt2, double tolerance = 100) |
| | | { |
| | | if (GetDistanceP2P(pt1, pt2) <= tolerance) |
| | | return true; |
| | | return false; |
| | | } |
| | | |
| | | public bool IsPointNearPoint(Point pt1, Point pt2, double tolerance = 100) |
| | | public static bool IsPointNearPoint(Point pt1, Point pt2, double tolerance = 100) |
| | | { |
| | | if (GetDistanceP2P(pt1, pt2) <= tolerance) |
| | | return true; |
| | | return false; |
| | | } |
| | | |
| | | public bool IsPointNearPoint(double x1, double y1, double x2, double y2, int tolerance = 100) |
| | | public static bool IsPointNearPoint(double x1, double y1, double x2, double y2, int tolerance = 100) |
| | | { |
| | | return IsPointNearPoint(new HPoint(x1, y1), new HPoint(x2, y2), tolerance); |
| | | } |
| | |
| | | /// <param name="corner"></param> |
| | | /// <param name="tolerance"></param> |
| | | /// <returns></returns> |
| | | public bool IsPointNearRectangleCorner(Point pt, Rectangle rect, out string corner, double tolerance = 10) |
| | | public static bool IsPointNearRectangleCorner(Point pt, Rectangle rect, out string corner, double tolerance = 10) |
| | | { |
| | | try |
| | | { |
| | |
| | | catch { corner = ""; return false; } |
| | | } |
| | | |
| | | public bool IsPointNearRectangleCorner(HPoint pt, HRectangle2 rect, out string corner, double tolerance = 10) |
| | | public static bool IsPointNearRectangleCorner(HPoint pt, HRectangle2 rect, out string corner, double tolerance = 10) |
| | | { |
| | | try |
| | | { |
| | |
| | | /// <param name="p3">线2起始点</param> |
| | | /// <param name="p4"></param> |
| | | /// <returns></returns> |
| | | public Point2d? GetLineIntersection(Point2d p1, Point2d p2, Point2d p3, Point2d p4, bool bOnSegment = false) |
| | | public static Point2d? GetLineIntersection(Point2d p1, Point2d p2, Point2d p3, Point2d p4, bool bOnSegment = false) |
| | | { |
| | | // 直线1的向量 |
| | | double x1 = p1.X, y1 = p1.Y; |
| | |
| | | #region Halcon |
| | | // Chapter: Graphics / Output |
| | | // Short Description: Display 3D object models |
| | | public void visualize_object_model_3d(HTuple hv_WindowHandle, HTuple hv_ObjectModel3D, |
| | | public static void visualize_object_model_3d(HTuple hv_WindowHandle, HTuple hv_ObjectModel3D, |
| | | HTuple hv_CamParam, HTuple hv_PoseIn, HTuple hv_GenParamName, HTuple hv_GenParamValue, |
| | | HTuple hv_Title, HTuple hv_Label, HTuple hv_Information, out HTuple hv_PoseOut) |
| | | { |
| | |
| | | |
| | | // Chapter: Calibration / Camera Parameters |
| | | // Short Description: Set the value of a specified camera parameter in the camera parameter tuple. |
| | | public void set_cam_par_data(HTuple hv_CameraParamIn, HTuple hv_ParamName, HTuple hv_ParamValue, |
| | | public static void set_cam_par_data(HTuple hv_CameraParamIn, HTuple hv_ParamName, HTuple hv_ParamValue, |
| | | out HTuple hv_CameraParamOut) |
| | | { |
| | | // Local iconic variables |
| | |
| | | } |
| | | } |
| | | |
| | | public void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1, |
| | | public static void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1, |
| | | HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth) |
| | | { |
| | | // Stack for temporary objects |
| | |
| | | } |
| | | } |
| | | |
| | | public void get_rect2_vertex(HTuple hv_Row, HTuple hv_Column, HTuple hv_Phi, HTuple hv_Length1, |
| | | public static void get_rect2_vertex(HTuple hv_Row, HTuple hv_Column, HTuple hv_Phi, HTuple hv_Length1, |
| | | HTuple hv_Length2, out HTuple hv_TopLeft_Row, out HTuple hv_TopLeft_Col, out HTuple hv_TopRight_Row, |
| | | out HTuple hv_TopRight_Col, out HTuple hv_LowLeft_Row, out HTuple hv_LowLeft_Col, |
| | | out HTuple hv_LowRight_Row, out HTuple hv_LowRight_Col) |
| | |
| | | } |
| | | } |
| | | |
| | | public void pts_to_best_line(out HObject ho_LineXld, HTuple hv_Rows, HTuple hv_Columns, |
| | | public static void pts_to_best_line(out HObject ho_LineXld, HTuple hv_Rows, HTuple hv_Columns, |
| | | HTuple hv_IgnoreNum, out HTuple hv_Row1, out HTuple hv_Column1, out HTuple hv_Row2, |
| | | out HTuple hv_Column2) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | public (double, double) CalculateTailValues(HTuple minValue, HTuple maxValue, HTuple mean, HTuple deviation, double tailPercentage = 0.3) |
| | | public static (double, double) CalculateTailValues(HTuple minValue, HTuple maxValue, HTuple mean, HTuple deviation, double tailPercentage = 0.3) |
| | | { |
| | | // 计算低尾灰度值 |
| | | double lowTailValue = minValue.TupleReal() + (mean.TupleReal() - minValue.TupleReal()) * tailPercentage; |
| | |
| | | /// <param name="hv_Column2">结束横坐标</param> |
| | | /// <param name="hv_ResultRow">结果点集合纵坐标</param> |
| | | /// <param name="hv_ResultColumn">结果点集合横坐标</param> |
| | | public void Rake(HObject ho_Image, out HObject ho_Regions, HTuple hv_Elements, |
| | | public static void Rake(HObject ho_Image, out HObject ho_Regions, HTuple hv_Elements, |
| | | HTuple hv_DetectHeight, HTuple hv_DetectWidth, HTuple hv_Sigma, HTuple hv_Threshold, |
| | | HTuple hv_Transition, HTuple hv_Select, HTuple hv_Row1, HTuple hv_Column1, HTuple hv_Row2, |
| | | HTuple hv_Column2, out HTuple hv_ResultRow, out HTuple hv_ResultColumn) |
| | |
| | | catch { } |
| | | } |
| | | |
| | | public void scale_gray_map(HObject ho_Image, out HObject ho_Image1, HTuple hv_Min, HTuple hv_Max) |
| | | public static void scale_gray_map(HObject ho_Image, out HObject ho_Image1, HTuple hv_Min, HTuple hv_Max) |
| | | { |
| | | HTuple hv_Mult = new HTuple(), hv_Add = new HTuple(); |
| | | HOperatorSet.GenEmptyObj(out ho_Image1); |
| | |
| | | |
| | | #region OpenCVSharp |
| | | // 根据Mat类型返回对应的无效值 |
| | | public Scalar GetInvalidValueForMat(Mat mat) |
| | | public static Scalar GetInvalidValueForMat(Mat mat) |
| | | { |
| | | MatType type = mat.Type(); |
| | | if (type == MatType.CV_8UC1 || type == MatType.CV_8UC3) |
| | |
| | | return new Scalar(0); // 对于8位无符号类型,0是安全的无效值 |
| | | } |
| | | |
| | | public void RGB2XYZ(double sR, double sG, double sB, out double X, out double Y, out double Z) |
| | | public static void RGB2XYZ(double sR, double sG, double sB, out double X, out double Y, out double Z) |
| | | { |
| | | // 输入的颜色值 (sR, sG, sB) 应为 0 到 255 之间的值 |
| | | |
| | |
| | | Z = Math.Round(var_Z / (var_X + var_Y + var_Z), 3); |
| | | } |
| | | |
| | | public void ExtractFrames(string videoPath, string outputDir) |
| | | public static void ExtractFrames(string videoPath, string outputDir) |
| | | { |
| | | // 检查视频文件是否存在 |
| | | if (!File.Exists(videoPath)) |
| | |
| | | get |
| | | { |
| | | if (Subject == null) |
| | | { |
| | | return null; |
| | | } |
| | | return Subject.InputImage; |
| | | } |
| | | set |
| | | { |
| | | Subject.InputImage = value; |
| | | |
| | | if (InputImage == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (InputImage is HObject) |
| | | { |
| | | inputImageHSmartWindowControl.ShowHoImage((HObject)value); |
| | | } |
| | | else if (InputImage is Bitmap) |
| | | { |
| | | using (HImage image = TAlgorithm.Bitmap2HObject((Bitmap)value)) |
| | | { |
| | | TAlgorithm.Bitmap2HObject((Bitmap)value, out HObject image); |
| | | inputImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | } |
| | | else if (InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)value)) |
| | | { |
| | | TAlgorithm.Mat2HObject((Mat)value, out HObject image); |
| | | inputImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | if (Subject.OutputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.OutputImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject((Mat)Subject.OutputImage, out HObject image); |
| | | recordImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | } |
| | | else if (Subject.OutputImage is Bitmap) |
| | | { |
| | | using (HImage image = TAlgorithm.Bitmap2HObject((Bitmap)Subject.OutputImage)) |
| | | { |
| | | TAlgorithm.Bitmap2HObject((Bitmap)Subject.OutputImage, out HObject image); |
| | | recordImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | } |
| | | else if (Subject.OutputImage is HObject) |
| | | { |
| | |
| | | BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb); |
| | | hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0); |
| | | ((Bitmap)InputImage).UnlockBits(srcBmpData); |
| | | ((Bitmap)InputImage).Dispose(); |
| | | InputImage = null; |
| | | InputImage = hImage.Clone(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Msg = "转图出错:" + ex.Message; |
| | | Result = false; |
| | | return; |
| | | } |
| | | } |
| | | if (!(InputImage is HObject)) |
| | |
| | | } |
| | | |
| | | #region 裁剪区域 |
| | | HImage DomainImage = null; |
| | | object DomainImage = null; |
| | | if (!ReduceDomainImage(InputImage, ref DomainImage)) |
| | | { |
| | | Msg = "裁剪区域失败"; |
| | |
| | | // |
| | | // HBlobToolEdit |
| | | // |
| | | AutoScaleDimensions = new SizeF(96F, 96F); |
| | | AutoScaleMode = AutoScaleMode.Dpi; |
| | | AutoScaleDimensions = new SizeF(7F, 17F); |
| | | AutoScaleMode = AutoScaleMode.Font; |
| | | Controls.Add(splitContainer1); |
| | | Controls.Add(BtmStatusStrip); |
| | | Controls.Add(TopToolStrip); |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Drawing; |
| | | using System.Drawing.Imaging; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | |
| | | Msg = "输入图片为空"; |
| | | Result = false; |
| | | return; |
| | | } |
| | | if (InputImage is Bitmap) |
| | | { |
| | | try |
| | | { |
| | | using (HImage hImage = new HImage()) |
| | | { |
| | | Rectangle rect = new Rectangle(0, 0, ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height); |
| | | BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb); |
| | | hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0); |
| | | ((Bitmap)InputImage).UnlockBits(srcBmpData); |
| | | ((Bitmap)InputImage).Dispose(); |
| | | InputImage = hImage.Clone(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Msg = "转图出错:" + ex.Message; |
| | | Result = false; |
| | | return; |
| | | } |
| | | } |
| | | if (!(InputImage is HObject)) |
| | | { |
| | |
| | | // |
| | | // HFindCode2dToolEdit |
| | | // |
| | | AutoScaleDimensions = new SizeF(96F, 96F); |
| | | AutoScaleMode = AutoScaleMode.Dpi; |
| | | AutoScaleDimensions = new SizeF(7F, 17F); |
| | | AutoScaleMode = AutoScaleMode.Font; |
| | | Controls.Add(MainTableLayoutPanel); |
| | | Controls.Add(BtmStatusStrip); |
| | | Controls.Add(TopToolStrip); |
| | |
| | | <resheader name="writer"> |
| | | <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
| | | </resheader> |
| | | <metadata name="lblMsgToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
| | | <metadata name="TopToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
| | | <value>17, 17</value> |
| | | </metadata> |
| | | <metadata name="TopToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
| | | <value>156, 17</value> |
| | | </metadata> |
| | | <metadata name="BtmStatusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
| | | <value>287, 17</value> |
| | | <value>148, 17</value> |
| | | </metadata> |
| | | </root> |
| | |
| | | using LB_VisionProcesses.Alogrithms.Halcon; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Drawing.Imaging; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | |
| | | Result = false; |
| | | return; |
| | | } |
| | | if (InputImage is Bitmap) |
| | | { |
| | | try |
| | | { |
| | | using (HImage hImage = new HImage()) |
| | | { |
| | | Rectangle rect = new Rectangle(0, 0, ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height); |
| | | BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb); |
| | | hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0); |
| | | ((Bitmap)InputImage).UnlockBits(srcBmpData); |
| | | ((Bitmap)InputImage).Dispose(); |
| | | InputImage = hImage.Clone(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Msg = "转图出错:" + ex.Message; |
| | | Result = false; |
| | | return; |
| | | } |
| | | } |
| | | if (!(InputImage is HObject)) |
| | | { |
| | | Msg = "输入图片格式不为Mat"; |
| | | Result = false; |
| | | return; |
| | | } |
| | | |
| | | #region 裁剪区域 |
| | | if (!(Params.ROI is HSegment)) |
| | | { |
| | |
| | | label13 = new Label(); |
| | | cmbTransition = new ComboBox(); |
| | | cmbSelect = new ComboBox(); |
| | | btnShowROI = new Button(); |
| | | pnlInputImage = new Panel(); |
| | | TopToolStrip = new ToolStrip(); |
| | | btnRun = new ToolStripButton(); |
| | |
| | | tabPageInputImage = new TabPage(); |
| | | tabPageRecordImage = new TabPage(); |
| | | pnlRecordImage = new Panel(); |
| | | btnShowROI = new Button(); |
| | | tablePanelParas.SuspendLayout(); |
| | | TopToolStrip.SuspendLayout(); |
| | | BtmStatusStrip.SuspendLayout(); |
| | |
| | | cmbSelect.Name = "cmbSelect"; |
| | | cmbSelect.Size = new Size(103, 25); |
| | | cmbSelect.TabIndex = 14; |
| | | // |
| | | // btnShowROI |
| | | // |
| | | btnShowROI.Dock = DockStyle.Fill; |
| | | btnShowROI.Location = new Point(3, 207); |
| | | btnShowROI.Name = "btnShowROI"; |
| | | btnShowROI.Size = new Size(84, 45); |
| | | btnShowROI.TabIndex = 15; |
| | | btnShowROI.Text = "显示找线区域"; |
| | | btnShowROI.UseVisualStyleBackColor = true; |
| | | btnShowROI.Click += btnShowROI_Click; |
| | | // |
| | | // pnlInputImage |
| | | // |
| | |
| | | pnlRecordImage.Size = new Size(607, 510); |
| | | pnlRecordImage.TabIndex = 45; |
| | | // |
| | | // btnShowROI |
| | | // |
| | | btnShowROI.Dock = DockStyle.Fill; |
| | | btnShowROI.Location = new Point(3, 207); |
| | | btnShowROI.Name = "btnShowROI"; |
| | | btnShowROI.Size = new Size(84, 45); |
| | | btnShowROI.TabIndex = 15; |
| | | btnShowROI.Text = "显示找线区域"; |
| | | btnShowROI.UseVisualStyleBackColor = true; |
| | | btnShowROI.Click += btnShowROI_Click; |
| | | // |
| | | // HFindLineToolEdit |
| | | // |
| | | AutoScaleDimensions = new SizeF(96F, 96F); |
| | | AutoScaleMode = AutoScaleMode.Dpi; |
| | | AutoScaleDimensions = new SizeF(7F, 17F); |
| | | AutoScaleMode = AutoScaleMode.Font; |
| | | Controls.Add(MainTableLayoutPanel); |
| | | Controls.Add(BtmStatusStrip); |
| | | Controls.Add(TopToolStrip); |
| | |
| | | <resheader name="writer"> |
| | | <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
| | | </resheader> |
| | | <metadata name="lblMsgToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
| | | <metadata name="TopToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
| | | <value>17, 17</value> |
| | | </metadata> |
| | | <metadata name="TopToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
| | | <value>156, 17</value> |
| | | </metadata> |
| | | <metadata name="BtmStatusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> |
| | | <value>287, 17</value> |
| | | <value>129, 17</value> |
| | | </metadata> |
| | | </root> |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics; |
| | | using System.Drawing.Imaging; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | |
| | | Msg = "输入图片为空"; |
| | | Result = false; |
| | | return; |
| | | } |
| | | if (InputImage is Bitmap) |
| | | { |
| | | try |
| | | { |
| | | using (HImage hImage = new HImage()) |
| | | { |
| | | Rectangle rect = new Rectangle(0, 0, ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height); |
| | | BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb); |
| | | hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0); |
| | | ((Bitmap)InputImage).UnlockBits(srcBmpData); |
| | | ((Bitmap)InputImage).Dispose(); |
| | | InputImage = hImage.Clone(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Msg = "转图出错:" + ex.Message; |
| | | Result = false; |
| | | return; |
| | | } |
| | | } |
| | | if (!(InputImage is HObject)) |
| | | { |
| | |
| | | // |
| | | // HFindModelToolEdit |
| | | // |
| | | AutoScaleDimensions = new SizeF(96F, 96F); |
| | | AutoScaleMode = AutoScaleMode.Dpi; |
| | | AutoScaleDimensions = new SizeF(7F, 17F); |
| | | AutoScaleMode = AutoScaleMode.Font; |
| | | Controls.Add(MainTableLayoutPanel); |
| | | Controls.Add(BtmStatusStrip); |
| | | Controls.Add(TopToolStrip); |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics; |
| | | using System.Drawing.Imaging; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | |
| | | Msg = "输入图片为空"; |
| | | Result = false; |
| | | return; |
| | | } |
| | | if (InputImage is Bitmap) |
| | | { |
| | | try |
| | | { |
| | | using (HImage hImage = new HImage()) |
| | | { |
| | | Rectangle rect = new Rectangle(0, 0, ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height); |
| | | BitmapData srcBmpData = ((Bitmap)InputImage).LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb); |
| | | hImage.GenImageInterleaved(srcBmpData.Scan0, "rgbx", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, "byte", ((Bitmap)InputImage).Width, ((Bitmap)InputImage).Height, 0, 0, -1, 0); |
| | | ((Bitmap)InputImage).UnlockBits(srcBmpData); |
| | | ((Bitmap)InputImage).Dispose(); |
| | | InputImage = hImage.Clone(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Msg = "转图出错:"+ ex.Message; |
| | | Result = false; |
| | | return; |
| | | } |
| | | } |
| | | if (!(InputImage is HObject)) |
| | | { |
| | |
| | | tabPage1.Controls.Add(splitContainer1); |
| | | tabPage1.Location = new Point(4, 26); |
| | | tabPage1.Name = "tabPage1"; |
| | | tabPage1.Padding = new Padding(3); |
| | | tabPage1.Padding = new Padding(3, 3, 3, 3); |
| | | tabPage1.Size = new Size(403, 516); |
| | | tabPage1.TabIndex = 0; |
| | | tabPage1.Text = "输入参数"; |
| | |
| | | tabPage2.Controls.Add(tableLayoutResults); |
| | | tabPage2.Location = new Point(4, 26); |
| | | tabPage2.Name = "tabPage2"; |
| | | tabPage2.Padding = new Padding(3); |
| | | tabPage2.Size = new Size(403, 516); |
| | | tabPage2.Padding = new Padding(3, 3, 3, 3); |
| | | tabPage2.Size = new Size(404, 519); |
| | | tabPage2.TabIndex = 1; |
| | | tabPage2.Text = "输出结果"; |
| | | tabPage2.UseVisualStyleBackColor = true; |
| | |
| | | tableLayoutResults.RowStyles.Add(new RowStyle(SizeType.Percent, 10F)); |
| | | tableLayoutResults.RowStyles.Add(new RowStyle(SizeType.Percent, 10F)); |
| | | tableLayoutResults.RowStyles.Add(new RowStyle(SizeType.Percent, 10F)); |
| | | tableLayoutResults.Size = new Size(397, 510); |
| | | tableLayoutResults.Size = new Size(398, 513); |
| | | tableLayoutResults.TabIndex = 1; |
| | | // |
| | | // label5 |
| | |
| | | dtxtCenterX.Margin = new Padding(2, 3, 2, 3); |
| | | dtxtCenterX.Name = "dtxtCenterX"; |
| | | dtxtCenterX.ReadOnly = true; |
| | | dtxtCenterX.Size = new Size(293, 23); |
| | | dtxtCenterX.Size = new Size(294, 23); |
| | | dtxtCenterX.TabIndex = 5; |
| | | // |
| | | // dtxtCenterY |
| | |
| | | dtxtCenterY.Margin = new Padding(2, 3, 2, 3); |
| | | dtxtCenterY.Name = "dtxtCenterY"; |
| | | dtxtCenterY.ReadOnly = true; |
| | | dtxtCenterY.Size = new Size(293, 23); |
| | | dtxtCenterY.Size = new Size(294, 23); |
| | | dtxtCenterY.TabIndex = 6; |
| | | // |
| | | // dtxtAngle |
| | |
| | | dtxtAngle.Margin = new Padding(2, 3, 2, 3); |
| | | dtxtAngle.Name = "dtxtAngle"; |
| | | dtxtAngle.ReadOnly = true; |
| | | dtxtAngle.Size = new Size(293, 23); |
| | | dtxtAngle.Size = new Size(294, 23); |
| | | dtxtAngle.TabIndex = 7; |
| | | // |
| | | // label8 |
| | |
| | | dtxtScore.Location = new Point(103, 156); |
| | | dtxtScore.Name = "dtxtScore"; |
| | | dtxtScore.ReadOnly = true; |
| | | dtxtScore.Size = new Size(291, 23); |
| | | dtxtScore.Size = new Size(292, 23); |
| | | dtxtScore.TabIndex = 9; |
| | | // |
| | | // dtxtCount |
| | |
| | | tabPageInputImage.Controls.Add(pnlInputImage); |
| | | tabPageInputImage.Location = new Point(4, 26); |
| | | tabPageInputImage.Name = "tabPageInputImage"; |
| | | tabPageInputImage.Padding = new Padding(3); |
| | | tabPageInputImage.Padding = new Padding(3, 3, 3, 3); |
| | | tabPageInputImage.Size = new Size(613, 516); |
| | | tabPageInputImage.TabIndex = 0; |
| | | tabPageInputImage.Text = "输入图像"; |
| | |
| | | // |
| | | pnlInputImage.Dock = DockStyle.Fill; |
| | | pnlInputImage.Location = new Point(3, 3); |
| | | pnlInputImage.Margin = new Padding(4); |
| | | pnlInputImage.Margin = new Padding(4, 4, 4, 4); |
| | | pnlInputImage.Name = "pnlInputImage"; |
| | | pnlInputImage.Size = new Size(607, 510); |
| | | pnlInputImage.TabIndex = 44; |
| | |
| | | tabPageRecordImage.Controls.Add(pnlRecordImage); |
| | | tabPageRecordImage.Location = new Point(4, 26); |
| | | tabPageRecordImage.Name = "tabPageRecordImage"; |
| | | tabPageRecordImage.Padding = new Padding(3); |
| | | tabPageRecordImage.Size = new Size(613, 516); |
| | | tabPageRecordImage.Padding = new Padding(3, 3, 3, 3); |
| | | tabPageRecordImage.Size = new Size(613, 519); |
| | | tabPageRecordImage.TabIndex = 1; |
| | | tabPageRecordImage.Text = "结果图像"; |
| | | tabPageRecordImage.UseVisualStyleBackColor = true; |
| | |
| | | // |
| | | pnlRecordImage.Dock = DockStyle.Fill; |
| | | pnlRecordImage.Location = new Point(3, 3); |
| | | pnlRecordImage.Margin = new Padding(4); |
| | | pnlRecordImage.Margin = new Padding(4, 4, 4, 4); |
| | | pnlRecordImage.Name = "pnlRecordImage"; |
| | | pnlRecordImage.Size = new Size(607, 510); |
| | | pnlRecordImage.Size = new Size(607, 513); |
| | | pnlRecordImage.TabIndex = 45; |
| | | // |
| | | // HFindMultiModelToolEdit |
| | | // |
| | | AutoScaleDimensions = new SizeF(96F, 96F); |
| | | AutoScaleMode = AutoScaleMode.Dpi; |
| | | AutoScaleDimensions = new SizeF(7F, 17F); |
| | | AutoScaleMode = AutoScaleMode.Font; |
| | | Controls.Add(MainTableLayoutPanel); |
| | | Controls.Add(BtmStatusStrip); |
| | | Controls.Add(TopToolStrip); |
| | |
| | | // |
| | | // HMulitModelControl |
| | | // |
| | | AutoScaleDimensions = new SizeF(96F, 96F); |
| | | AutoScaleMode = AutoScaleMode.Dpi; |
| | | AutoScaleDimensions = new SizeF(7F, 17F); |
| | | AutoScaleMode = AutoScaleMode.Font; |
| | | Controls.Add(tableLayoutPanel1); |
| | | Name = "HMulitModelControl"; |
| | | Size = new Size(399, 157); |
| | |
| | | |
| | | if (Subject.InputImage != null && Subject.InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image); |
| | | inputImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | } |
| | | |
| | | Type type = Subject.Params.ROI?.GetType(); |
| | | if (Subject.Params.ROI != null) |
| | | { |
| | |
| | | |
| | | if (Subject.InputImage != null && Subject.InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image); |
| | | HOperatorSet.GetImageSize(image, out HTuple ho_ImageWidth, out HTuple ho_ImageHeight); |
| | | recordImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | } |
| | | |
| | | //先判断子类再判断父类 |
| | |
| | | { |
| | | recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_OK, true); |
| | | recordImageHSmartWindowControl.DispObj(msgRecord.RecordObject_NG, false); |
| | | |
| | | for (int i = 0; i < msgRecord.Msg.Length; i++) |
| | | { |
| | | recordImageHSmartWindowControl.ShowMsg(msgRecord.Msg[i] |
| | | , 1 == msgRecord.Result[i] ? true : false, msgRecord.Column[i], msgRecord.Row[i]); |
| | | } |
| | | } |
| | | else if (Subject.Record != null && Subject.Record is ObjectRecord objRecord) |
| | | { |
| | |
| | | HTuple hv_imageHeight = 0; |
| | | if (InputImage != null && InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)InputImage)) |
| | | { |
| | | image.GetImageSize(out hv_imageWidth, out hv_imageHeight); |
| | | TAlgorithm.Mat2HObject((Mat)InputImage, out HObject image); |
| | | HOperatorSet.GetImageSize(image, out hv_imageWidth, out hv_imageHeight); |
| | | } |
| | | switch (type) |
| | | { |
| | | case RoiType.Rectangle2: |
| | |
| | | default: |
| | | inputImageHSmartWindowControl.oRoi = null; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | if (Subject.InputImage != null && Subject.InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image); |
| | | inputImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | |
| | | Type type = Subject.Params.ROI?.GetType(); |
| | | if (Subject.Params.ROI != null) |
| | | { |
| | |
| | | default: |
| | | inputImageHSmartWindowControl.oRoi = null; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | })); |
| | | } |
| | |
| | | |
| | | if (Subject.InputImage != null && Subject.InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage)) |
| | | { |
| | | image.GetImageSize(out HTuple ho_ImageWidth, out HTuple ho_ImageHeight); |
| | | TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image); |
| | | HOperatorSet.GetImageSize(image, out HTuple ho_ImageWidth, out HTuple ho_ImageHeight); |
| | | recordImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | |
| | | //先判断子类再判断父类 |
| | | if (Subject.Record != null && Subject.Record is MsgRecord msgRecord) |
| | | { |
| | |
| | | recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_OK, true); |
| | | recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_NG, false); |
| | | } |
| | | } |
| | | } |
| | | |
| | | GC.Collect(); |
| | | })); |
| | | } |
| | |
| | | HTuple hv_imageHeight = 0; |
| | | if (InputImage != null && InputImage is Mat) |
| | | { |
| | | using (HImage image=TAlgorithm.Mat2HObject((Mat)InputImage)) |
| | | { |
| | | image.GetImageSize(out hv_imageWidth, out hv_imageHeight); |
| | | TAlgorithm.Mat2HObject((Mat)InputImage, out HObject image); |
| | | HOperatorSet.GetImageSize(image, out hv_imageWidth, out hv_imageHeight); |
| | | } |
| | | switch (type) |
| | | { |
| | | case RoiType.Rectangle2: |
| | |
| | | default: |
| | | inputImageHSmartWindowControl.oRoi = null; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | if (InputImage != null && InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)InputImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject((Mat)InputImage, out HObject image); |
| | | inputImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | |
| | | int hv_Elements = Convert.ToInt16(itxtCaliperCount.Text); |
| | | double hv_DetectHeight = Convert.ToDouble(dtxtCaliperHeight.Text); |
| | | double hv_DetectWidth = Convert.ToDouble(dtxtCaliperWidth.Text); |
| | |
| | | , out HTuple hv_ResultRow, out HTuple hv_ResultColumn); |
| | | |
| | | inputImageHSmartWindowControl.DispObj(ho_Regions); |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | | })); |
| | |
| | | |
| | | if (Subject.InputImage != null && Subject.InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image); |
| | | inputImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | |
| | | Type type = Subject.Params.ROI?.GetType(); |
| | | if (Subject.Params.ROI != null) |
| | | { |
| | |
| | | } |
| | | |
| | | ShowModel(((FindModelTool)Subject).ModelID); |
| | | |
| | | } |
| | | } |
| | | })); |
| | | } |
| | | |
| | |
| | | |
| | | if (Subject.InputImage != null && Subject.InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage)) |
| | | { |
| | | image.GetImageSize(out HTuple ho_ImageWidth, out HTuple ho_ImageHeight); |
| | | TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image); |
| | | HOperatorSet.GetImageSize(image, out HTuple ho_ImageWidth, out HTuple ho_ImageHeight); |
| | | recordImageHSmartWindowControl.ShowHoImage(image); |
| | | } |
| | | |
| | | //先判断子类再判断父类 |
| | | if (Subject.Record != null && Subject.Record is MsgRecord msgRecord) |
| | | { |
| | |
| | | { |
| | | recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_OK, true); |
| | | recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_NG, false); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | GC.Collect(); |
| | |
| | | HTuple hv_imageHeight = 0; |
| | | if (InputImage != null && InputImage is Mat) |
| | | { |
| | | using (HImage image = TAlgorithm.Mat2HObject((Mat)InputImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject((Mat)InputImage, out HObject image); |
| | | HOperatorSet.GetImageSize(image, out hv_imageWidth, out hv_imageHeight); |
| | | } |
| | | switch (type) |
| | | { |
| | | case RoiType.Rectangle2: |
| | |
| | | default: |
| | | inputImageHSmartWindowControl.oRoi = null; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | if (InputImage != null && InputImage is Mat) |
| | | { |
| | | imgTabControl.SelectedTab = tabPageModelImage; |
| | | using (HImage hoDomainImage = TAlgorithm.Mat2HObject((Mat)InputImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject((Mat)InputImage, out HObject hoDomainImage); |
| | | |
| | | HOperatorSet.GetImageSize(hoDomainImage, out HTuple hv_imageWidth, out HTuple hv_imageHeight); |
| | | createModelImageHSmartWindowControl.ShowHoImage((HObject)hoDomainImage); |
| | | createModelImageHSmartWindowControl.bAollowDraw = true; |
| | | createModelImageHSmartWindowControl.oRoi = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2 |
| | | , 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if (InputImage != null && InputImage is Mat) |
| | | { |
| | | double result = 0; |
| | | |
| | | if (Enum.TryParse(cmbModelType.Text, out ModelType modelType)) |
| | | { |
| | | string NumLevels = this.dtxtModelParam1.Text; |
| | |
| | | string Contrast = this.dtxtModelParam11.Text; |
| | | int MinContrast = Convert.ToInt16(this.dtxtModelParam12.Text); |
| | | HRectangle2 ROI = (HRectangle2)createModelImageHSmartWindowControl.oRoi; |
| | | using (HRegion hRectangle = new HRegion()) |
| | | { |
| | | hRectangle.GenRectangle2(ROI.Row, ROI.Column, ROI.Phi, ROI.SemiLength1, ROI.SemiLength2); |
| | | using (HImage hoDomainImage = TAlgorithm.Mat2HObject((Mat)InputImage)) |
| | | { |
| | | |
| | | HOperatorSet.GenRectangle2(out HObject hRectangle, ROI.Row, ROI.Column, ROI.Phi, ROI.SemiLength1, ROI.SemiLength2); |
| | | TAlgorithm.Mat2HObject((Mat)InputImage, out HObject hoDomainImage); |
| | | HTuple hv_Channels = new HTuple(); |
| | | //判断是否为灰度图 |
| | | using (HDevDisposeHelper dh = new HDevDisposeHelper()) |
| | | { |
| | | try |
| | | { |
| | | //hv_Channels = hoDomainImage.CountChannels(); |
| | | //if (hv_Channels.TupleInt() != 1) |
| | | // HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage); |
| | | HOperatorSet.CountChannels(hoDomainImage, out hv_Channels); |
| | | if (hv_Channels.TupleInt() != 1) |
| | | HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage); |
| | | |
| | | ////转换后再次检查是否为灰度图 |
| | | //HOperatorSet.CountChannels(hoDomainImage, out hv_Channels); |
| | | //if (hv_Channels.TupleInt() != 1) |
| | | // HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage); |
| | | //转换后再次检查是否为灰度图 |
| | | HOperatorSet.CountChannels(hoDomainImage, out hv_Channels); |
| | | if (hv_Channels.TupleInt() != 1) |
| | | HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage); |
| | | } |
| | | catch { } |
| | | } |
| | | HObject hoImageReduced = hoDomainImage.Rgb1ToGray().ReduceDomain(hRectangle); |
| | | HOperatorSet.ReduceDomain(hoDomainImage, hRectangle, out HObject hoImageReduced); |
| | | HOperatorSet.CropDomain(hoImageReduced, out hoImageReduced); |
| | | TAlgorithm.HObject2Mat(hoImageReduced, out Mat hoModelImage); |
| | | bool bCreateModel = false; |
| | |
| | | |
| | | if (bCreateModel) |
| | | { |
| | | using (HObject ho_ModelContours = new HObject()) |
| | | { |
| | | HObject ho_ModelContours = new HObject(); |
| | | //switch (((FindModelTool)Subject).ModelID.Type) |
| | | //{ |
| | | // case ModelType.局部变形模板: |
| | |
| | | //建模成功导航到子页 |
| | | parasTabControl.SelectedTab = tabPageRunParas; |
| | | //modelImageHSmartWindowControl.ShowHoImage(((HFindModelTool)Subject).ModelID.hoImage); |
| | | using (HImage modelImage = TAlgorithm.Mat2HObject(((FindModelTool)Subject).ModelID.hoImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject(((FindModelTool)Subject).ModelID.hoImage, out HObject modelImage); |
| | | modelImageHSmartWindowControl.ShowHoImage(modelImage); |
| | | modelImageHSmartWindowControl.DispObj(ho_ModelContours, false); |
| | | modelImageHSmartWindowControl.ShowMsg("创建模板成功", true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | if (ModelID != null && ModelID.Width > 0) |
| | | { |
| | | //HOperatorSet.GenEmptyObj(out HObject ho_ModelContours); |
| | | using (HRegion ho_ModelContours = new HRegion()) |
| | | { |
| | | HOperatorSet.GenEmptyObj(out HObject ho_ModelContours); |
| | | //switch (ModelID.Type) |
| | | //{ |
| | | // case ModelType.各向异形模板: |
| | |
| | | //HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_ModelContours, hv_HomMat2D); |
| | | |
| | | modelImageHSmartWindowControl.ClearObj(); |
| | | using (HImage hoImage = TAlgorithm.Mat2HObject(ModelID.hoImage)) |
| | | { |
| | | TAlgorithm.Mat2HObject(ModelID.hoImage, out HObject hoImage); |
| | | //modelImageHSmartWindowControl.ShowHoImage(ModelID.hoImage); |
| | | modelImageHSmartWindowControl.ShowHoImage(hoImage); |
| | | modelImageHSmartWindowControl.DispObj(ho_ModelContours, false); |
| | | modelImageHSmartWindowControl.ShowMsg("创建模板成功", true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch { } |
| | |
| | | /// <summary> |
| | | /// 输入图片 |
| | | /// </summary> |
| | | public object InputImage; |
| | | public object InputImage = null; |
| | | |
| | | /// <summary> |
| | | /// 输出图片 |
| | | /// </summary> |
| | | public object OutputImage; |
| | | public object OutputImage = null; |
| | | |
| | | /// <summary> |
| | | /// 结果区域 |
| | |
| | | DateTime StartTime = DateTime.Now; |
| | | |
| | | InitRunParams(); |
| | | HOperatorSet.GenEmptyObj(out HObject EmptyObj); |
| | | OutputImage = EmptyObj; |
| | | //HOperatorSet.GenEmptyObj(out HObject EmptyObj); |
| | | //OutputImage = EmptyObj; |
| | | |
| | | #region 运行逻辑 |
| | | |