【Halcon联合C#】选择路径加载图片并且处理

简介

本Demo采用Halcon联合C#编程实现加载图片显示第一个显示窗口,并进行处理,将处理结果显示在第二个窗口上。

窗体界面设计

界面摆放两个HWindowControl显示控件和两个按钮控件,第一个按钮负责加载图片将图片显示在第一个显示控件上,第二个按钮负责进行图像处理并且将结果显示在第二个显示控件上。
在这里插入图片描述

程序源码

using HalconDotNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace ShowProcessing
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        HObject OriginImage= new HObject();
        private void LoadImage_Click(object sender, EventArgs e)
        {
            HOperatorSet.GenEmptyObj(out OriginImage);
            using(OpenFileDialog ofg = new OpenFileDialog())
            {
                ofg.Title = "图片";
                ofg.Multiselect = false;
                ofg.Filter = "图像|*.png;*.bmp;*.jpg";
                if(ofg.ShowDialog() == DialogResult.OK)
                {
                    HOperatorSet.ReadImage(out OriginImage, ofg.FileName);
                    HOperatorSet.GetImageSize(OriginImage,out HTuple OriginImageWith, out HTuple OriginImageHeight);
                    hWindowControl1.HalconWindow.SetPart(0, 0, (int)(OriginImageHeight - 1), (int)(OriginImageWith - 1));
                    hWindowControl1.HalconWindow.DispObj(OriginImage);

                }
            }

        }

        private void ThresholdSegmentation_Click(object sender, EventArgs e)
        {
            HOperatorSet.Rgb1ToGray(OriginImage, out HObject GrayImage);
            HOperatorSet.Threshold(OriginImage, out HObject Region, 50, 138);
            HOperatorSet.PaintRegion(Region, OriginImage,out HObject ImageResult, ((new HTuple(0)).TupleConcat(
        0)).TupleConcat(255), "margin");
            hWindowControl2.HalconWindow.DispObj(ImageResult);
        }
    }
}

实现效果

在这里插入图片描述

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值