机器视觉通用平台之点仿射变换UI

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 CvBase;
using HalconDotNet;
using CWindowTool;

namespace CvImageTool
{
    public partial class AffineTransPoint2DForm : Form
    {
        private int ProcessIndex { set; get; }
        private int ImageOptIndex { set; get; }
        private string Description { set; get; }
        private AffineTransPoint2DTool affineTransPoint2DTool;

        private List<BaseProcess> processes;
        private CWindows[] cCWindows;

        public AffineTransPoint2DForm()
        {
            InitializeComponent();
        }

        public AffineTransPoint2DForm(int processIndex, int imageOptIndex,
            string cProcessSettingFilePath, string cImageOptSettingFilePath, string cDescription,
            List<BaseProcess> baseProcesses, CWindows[] cWindows)
        {
            this.StartPosition = FormStartPosition.CenterParent;
            InitializeComponent();
            this.ProcessIndex = processIndex;
            this.ImageOptIndex = imageOptIndex;
            this.Description = cDescription;
            this.processes = baseProcesses;
            this.cCWindows = cWindows;
            affineTransPoint2DTool = new AffineTransPoint2DTool(processIndex, imageOptIndex, cProcessSettingFilePath, cImageOptSettingFilePath, processes, cWindows);
        }

        private void AffineTransPoint2DForm_Load(object sender, EventArgs e)
        {
            this.Text = processes[ProcessIndex].Name + "#" + Description;
            Affine_OptNameCMBox.Items.Clear();
            for (int i = 0; i < ImageOptIndex; i++)
            {
                string cDes = processes[ProcessIndex].BaseImageOpts[i].Description;
                Affine_OptNameCMBox.Items.Add(cDes);
            }

            if (affineTransPoint2DTool.ReadFile(Description))
            {
                string[] values = affineTransPoint2DTool.AffinePositSelect.Split('_');
                if (values.Length == 2)
                {
                    Affine_OptNameCMBox.Text = values[0];
                    Affine_ParamNameCMBox.Text = values[1];
                }
                else if (values.Length == 1)
                {
                    Affine_OptNameCMBox.Text = values[0];
                }

                values = affineTransPoint2DTool.affinMatrixSelect.Split('_');
                if (values.Length == 2)
                {
                    Matrix_OptNameCMBox.Text = values[0];
                    Matrix_ParamNameCMBox.Text = values[1];
                }
                else if (values.Length == 1)
                {
                    Matrix_OptNameCMBox.Text = values[0];
                }
            }
        }

        private void Affine_OptNameCMBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Affine_OptNameCMBox.SelectedIndex >= 0)
            {
                Affine_ParamNameCMBox.Items.Clear();
                foreach (string value in processes[ProcessIndex].BaseImageOutParams[Affine_OptNameCMBox.SelectedIndex].OutputHTupleNames)
                    Affine_ParamNameCMBox.Items.Add(value);
            }
        }

        private void SaveBtn_Click(object sender, EventArgs e)
        {
            affineTransPoint2DTool.AffinePositSelect = Affine_OptNameCMBox.Text + "_" + Affine_ParamNameCMBox.Text;
            affineTransPoint2DTool.affinMatrixSelect = Matrix_OptNameCMBox.Text + "_" + Matrix_ParamNameCMBox.Text;
            affineTransPoint2DTool.WriteFile(Description);
        }

        private void RunBtn_Click(object sender, EventArgs e)
        {
            affineTransPoint2DTool.ReadFile(Description);
            affineTransPoint2DTool.Running(out HTuple x, out HTuple y);
            if (x.Length > 0)
            {
                for (int i = 0; i < x.Length; i++)
                {
                    dataGridView1.Rows[i].Cells[0].Value = (i + 1).ToString();
                    dataGridView1.Rows[i].Cells[1].Value = x.D.ToString();
                    dataGridView1.Rows[i].Cells[2].Value = y.D.ToString();
                }
            }
        }
    }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值