示例#1
0
        /// <summary>
        /// 事件:鼠标点击后事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Slider_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            var vm    = DataContext as MainViewModel;
            var value = (int)(sender as Slider).Value;

            // 计时开始
            vm._watch = Stopwatch.StartNew();

            CVAlgorithms.CvpBlur(OldBmpInfo.data, vm.CurrBmp.Width, vm.CurrBmp.Height, OldBmpInfo.step, value, value, ref CurrImgInfo);

            byte[] imagePixels = new byte[CurrImgInfo.size];
            Marshal.Copy(CurrImgInfo.data, imagePixels, 0, CurrImgInfo.size);
            vm.CurrBitmapImage = ImageEx.ByteToBitmapImage(imagePixels);
            // 释放内存
            CVAlgorithms.ReleaseMemUseFree(CurrImgInfo.data);

            // 计时结束
            vm._watch.Stop();
            vm.StatusText = "Execution time: " + vm._watch.ElapsedMilliseconds + " ms.";
        }
示例#2
0
        /// <summary>
        /// 取消按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_cancel_Click(object sender, RoutedEventArgs e)
        {
            var vm = DataContext as MainViewModel;

            // 计时开始
            vm._watch = Stopwatch.StartNew();

            // 恢复最初图像状态,此处调用0内核blur函数跳过,实现过程看CvpBlur函数实现
            CVAlgorithms.CvpBlur(OldBmpInfo.data, vm.CurrBmp.Width, vm.CurrBmp.Height, OldBmpInfo.step, 0, 0, ref CurrImgInfo);

            byte[] imagePixels = new byte[CurrImgInfo.size];
            Marshal.Copy(CurrImgInfo.data, imagePixels, 0, CurrImgInfo.size);
            vm.CurrBitmapImage = ImageEx.ByteToBitmapImage(imagePixels);
            // 释放内存
            CVAlgorithms.ReleaseMemUseFree(CurrImgInfo.data);

            // 计时结束
            vm._watch.Stop();
            vm.StatusText = "Execution time: " + vm._watch.ElapsedMilliseconds + " ms.";
            Close();
        }
示例#3
0
        /// <summary>
        /// 事件:下拉框选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cb_method_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string item = (e.AddedItems[0] as ComboBoxItem).Content as string;

            Enum.TryParse(item, out CurrThresholdType);
            vm = DataContext as MainViewModel;
            if (null != vm) // 防止第一次加载没初始化视图模型的情况
            {
                // 计时开始
                vm._watch = Stopwatch.StartNew();

                CVAlgorithms.CvpThreshold(OldBmpInfo.data, vm.CurrBmp.Width, vm.CurrBmp.Height, OldBmpInfo.step, CurrThresholdValue, 255, (int)CurrThresholdType, ref CurrImgInfo);
                byte[] imagePixels = new byte[CurrImgInfo.size];
                Marshal.Copy(CurrImgInfo.data, imagePixels, 0, CurrImgInfo.size);
                vm.CurrBitmapImage = ImageEx.ByteToBitmapImage(imagePixels);
                // 释放内存
                CVAlgorithms.ReleaseMemUseFree(CurrImgInfo.data);

                // 计时结束
                vm._watch.Stop();
                vm.StatusText = "Execution time: " + vm._watch.ElapsedMilliseconds + " ms.";
            }
        }