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

            // 计时开始
            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.";
        }
Ejemplo n.º 2
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.";
            }
        }