예제 #1
0
        //人脸变换按钮
        private void Trans_face_btn(object sender, RoutedEventArgs e)
        {
            if (flag_source_1 == 0 || flag_source_2 == 0)
            {
                MessageBox.Show("请您先选择图片", "提醒");
                return;
            }
            int a = Get_TPS_polafunction();

            if (Get_TPS_polafunction() == -1)
            {
                MessageBox.Show("请先选择插值方法", "提醒");
                return;
            }
            Matrix   TPS      = new Matrix(initial_TPS_parameter());
            My_cv    my_trans = new My_cv(Image_face_1, Image_face_2);
            DateTime beforDT  = System.DateTime.Now;

            Image_face_resul.Source = BitmaptoImage(my_trans.TPS_face(TPS, Get_TPS_polafunction(), Source_point_1_new));
            flag_changeface         = 1;

            //记录变换用时
            DateTime afterDT  = System.DateTime.Now;
            TimeSpan ts       = afterDT.Subtract(beforDT);
            double   TPS_time = ts.TotalMilliseconds / 1000;

            Functiontime.Content = TPS_time.ToString("0.###");
        }
예제 #2
0
        //进行扭曲变形
        private void Trans_Btn_Click(object sender, RoutedEventArgs e)
        {
            //未传图片时
            if (flag_tochange == 0)
            {
                MessageBox.Show("请先点击原图上传图片", "提醒");
                return;
            }
            //实例化My_cv的对象
            My_cv my_trans      = new My_cv(Image_to_trans);
            int   result_method = combo_change.SelectedIndex;

            if (result_method == 0)
            {
                if (Check_method_clock() == 0)
                {
                    MessageBox.Show("请选择转动方向", "提醒");
                    return;
                }
                if (!Check_legal_rotate())
                {
                    MessageBox.Show("您有非数字的输入", "提醒");
                    return;
                }
                double[] parameter = new double[6];
                parameter = GetParameter_forrotate();
                if (Getpola_function() == -1)
                {
                    MessageBox.Show("请选择插值函数", "提示");
                    return;
                }
                if (parameter[4] < 1 || parameter[4] > Image_to_trans.Width || parameter[5] < 1 || parameter[5] > Image_to_trans.Height)
                {
                    MessageBox.Show("旋转中心超出范围自动帮您调为图片中心", "提醒");
                    parameter[4] = Image_to_trans.Width / 2;
                    parameter[5] = Image_to_trans.Height / 2;
                }
                //可进行旋转操作
                trans_THUImage.Source = BitmaptoImage(my_trans.Rotate_Image(parameter[0], parameter[1], (int)parameter[2], (int)parameter[3], parameter[4], parameter[5]));
                //完成扭曲变形标志
                flag_Distortion = 1;
            }
            else if (result_method == 1)
            {
                if (Check_method_Distortion() == 0)
                {
                    MessageBox.Show("请选择畸变方式", "提醒");
                    return;
                }
                if (!Check_legal_Distortion())
                {
                    MessageBox.Show("您有非数字的输入", "提醒");
                    return;
                }
                double para = double.Parse(radius_2.Text);
                //完成扭曲变形标志
                flag_Distortion       = 1;
                trans_THUImage.Source = BitmaptoImage(my_trans.Distortion_Image(para, Check_method_clock(), Check_method_Distortion()));
            }
            else
            {
                MessageBox.Show("请选择图像变换的方式", "提示");
            }
        }