private void okButton_Click(object sender, RoutedEventArgs e)
        {
            if (_imageChanged)
            {
                //double scale = image.Source.Width / image.ActualWidth;
                //int left = -(int)(image.Margin.Left / scale);
                //int top = -(int)(image.Margin.Top / scale);
                //int size = (int)(96 / scale);

                //BitmapImage img = new BitmapImage(_imageSource);
                //CroppedBitmap cropped = new CroppedBitmap(img, new Int32Rect(left, top, size, size));
                //TransformedBitmap scaled = new TransformedBitmap(cropped, new ScaleTransform(1 / scale, 1 / scale));
                //ImageSource = scaled;

                if (_isDefault)
                {
                    ImageSource = null;
                }
                else
                {
                    ImageSource = ImageProc.GetImage(border);
                }

                DialogResult = true;
            }
            else
            {
                DialogResult = false;
            }
        }
        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            if (!_allowTransition)
            {
                return;
            }

            prevButton.IsEnabled = true;

            if (_slideLocation < slideContainer.Children.Count - 2)
            {
                _allowTransition = false;

                screenshot.Source = ImageProc.GetImage(slideContainer.Children[_slideLocation]);
                slideContainer.Children[_slideLocation].Visibility = Visibility.Collapsed;
                AnimationHelpers.SlideDisplay slide = new AnimationHelpers.SlideDisplay((Grid)slideContainer.Children[_slideLocation + 1], screenshot);
                slide.OnAnimationCompletedEvent += slide_OnAnimationCompletedEvent;
                slide.SwitchViews(AnimationHelpers.SlideDirection.Right);
                _slideLocation++;

                if (_slideLocation == slideContainer.Children.Count - 2)
                {
                    nextButton.IsEnabled = false;
                }
            }
        }
        private async void changeLocation_Close(object sender, RoutedEventArgs e)
        {
            changeLocation.IsHitTestVisible = false;
            grid.IsHitTestVisible           = true;

            if (changeLocation.Location != null)
            {
                string loc = changeLocation.Location;

                if (!loc.Equals(Location, StringComparison.InvariantCultureIgnoreCase))
                {
                    Location = loc;
                    string[] split = Location.Split(',');
                    locationTextBox.Text = split[0] + "," + split[1];

                    Reset();
                    await Load();
                }
            }

            Panel.SetZIndex(changeLocation, 0);
            Panel.SetZIndex(grid, 1);

            if (Settings.AnimationsEnabled)
            {
                screenshot.Source         = ImageProc.GetImage(changeLocation);
                changeLocation.Visibility = Visibility.Collapsed;
                new AnimationHelpers.SlideDisplay(grid, screenshot).SwitchViews(AnimationHelpers.SlideDirection.Right);
            }
            else
            {
                changeLocation.Visibility = Visibility.Collapsed;
                grid.Visibility           = Visibility.Visible;
            }
        }
Beispiel #4
0
        private void _optionsControl_OnThemeChangedEvent(object sender, ThemeChangedEventArgs e)
        {
            if (Settings.AnimationsEnabled)
            {
                copyWindowImg.Source     = ImageProc.GetImage(mainGrid);
                copyWindowImg.Visibility = Visibility.Visible;
            }

            BackstageEvents.StaticUpdater.InvokeThemeChanged(sender, e);

            if (Settings.AnimationsEnabled)
            {
                DoubleAnimation fadeThemeOut = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromMilliseconds(750)), FillBehavior.Stop);

                fadeThemeOut.Completed += (anim, args) =>
                {
                    copyWindowImg.Source     = null;
                    copyWindowImg.Visibility = Visibility.Collapsed;

                    mainGrid.IsHitTestVisible = true;
                };

                mainGrid.IsHitTestVisible = false;
                copyWindowImg.BeginAnimation(OpacityProperty, fadeThemeOut);
            }
        }
Beispiel #5
0
 private void OnImageGray(object sender, EventArgs e)
 {
     if (ImageProc.Grayscale(this._ProcImage, this._ImageData))
     {
         this.UpdateViewImage(this._ProcImage);
         this.UpdateView();
     }
 }
Beispiel #6
0
        Tuple <List <Matrix>, List <Matrix> > ReadMNISTTrainingData()
        {
            String trainDir = "C:\\Users\\ivans_000\\Desktop\\MASTER\\Spring2019\\Deep_Learning\\Assignment2_Sangines\\Data\\Training1000\\";
            //string trainDir = @"D:\csharp2018\DataSets\MNIST\MNISTBMP\Training1000";
            //string trainDir = @"D:\csharp2016\DeepLearning\MNIST\data\TrainingAll60000";
            //string trainDir = @"D:\csharp2018\DataSets\MNIST\MNISTBMP\data\TrainingAll60000";
            int           numFiles         = 0;
            int           dataIndex        = 0;
            DirectoryInfo dinfo            = new DirectoryInfo(trainDir);
            List <Matrix> InputDataList    = new List <Matrix>();
            List <Matrix> OutputLabelsList = new List <Matrix>();

            //count the number of files
            foreach (FileInfo fi in dinfo.GetFiles())
            {
                numFiles++;
            }

            foreach (FileInfo fi in dinfo.GetFiles())
            {
                Matrix Img   = new Matrix(28, 28);
                String fname = fi.FullName;
                Bitmap bmp   = new Bitmap(Image.FromFile(fname));
                if (ImageProc.IsGrayScale(bmp) == false) //make sure it is grayscale
                {
                    ImageProc.ConvertToGray(bmp);
                }
                for (int i = 0; i < bmp.Width; i++)
                {
                    for (int j = 0; j < bmp.Height; j++)
                    {   // rescale between 0 and 1
                        Img.D[i][j] = bmp.GetPixel(i, j).R / 255.0;
                    }
                }
                InputDataList.Add(Img);
                Matrix outputLabel = new Matrix(10, 1);
                String s1          = fi.Name;
                Char   output      = s1[0];
                int    classLabel  = (Convert.ToInt16(output) - 48); //will only work with numbers 0-9
                outputLabel.D[classLabel][0] = 1;                    // others are 0 by default
                OutputLabelsList.Add(outputLabel);

                dataIndex++;
                if ((dataIndex % 500) == 0)
                {
                    Console.WriteLine("iter: " + dataIndex);
                }
            }
            return(new Tuple <List <Matrix>, List <Matrix> >(InputDataList, OutputLabelsList));
        }
Beispiel #7
0
        Matrix ReadOneImage(string fname)
        {
            Matrix Img = new Matrix(28, 28);
            Bitmap bmp = new Bitmap(Image.FromFile(fname));

            if (ImageProc.IsGrayScale(bmp) == false) //make sure it is grayscale
            {
                ImageProc.ConvertToGray(bmp);
            }
            for (int i = 0; i < bmp.Width; i++)
            {
                for (int j = 0; j < bmp.Height; j++)
                {   // rescale between 0 and 1
                    Img.D[i][j] = bmp.GetPixel(i, j).R / 255.0;
                }
            }
            return(Img);
        }
        private void PreviousSlide()
        {
            counter -= 2;
            object prev = Slides[counter++];

            image.Source    = ImageProc.GetImage(content);
            content.Content = prev;
            content.SlideDisplay(image, Extensions.SlideDirection.Left);

            if (counter > 1)
            {
                prevButton.FadeIn();
                prevButton.IsEnabled = true;
            }
            else
            {
                prevButton.FadeOut();
                floatingLogo.FadeOut();
            }
        }
        private void PreviousSlide()
        {
            CurrentSlidePosition -= 2;
            object prev = Slides[CurrentSlidePosition++];

            image.Source    = ImageProc.GetImage(content);
            content.Content = prev;
            content.SlideDisplay(image, Setup.Extensions.SlideDirection.Left);

            if (CurrentSlidePosition > 1)
            {
                prevButton.FadeIn();
                prevButton.IsEnabled = true;
            }
            else
            {
                prevButton.FadeOut();
                floatingLogo.FadeOut();
            }
        }
        private void NextSlide()
        {
            if (CurrentSlidePosition < Slides.Length)
            {
                object next = Slides[CurrentSlidePosition++];

                image.Source = ImageProc.GetImage(content);

                if (next is CEIP)
                {
                    nextButton.IsEnabled = true;
                    floatingLogo.FadeIn();
                }
                else if (next is Personalize)
                {
                    Settings.JoinedCEIP  = (content.Content as CEIP).joinCEIP.IsChecked == true;
                    nextButton.IsEnabled = true;
                }
                else if (next is Complete)
                {
                    Complete             = true;
                    nextButton.IsEnabled = true;
                    nextButton.Content   = "_All Done!";
                    nextButton.IsDefault = true;

                    prevButton.FadeOut();
                    floatingLogo.FadeOut();
                }

                content.Content = next;
                content.UpdateLayout();
                content.SlideDisplay(image, Setup.Extensions.SlideDirection.Right);
            }
            else
            {
                Close();
            }
        }
        public void ChangeLocation()
        {
            if (!changeLocation.IsHitTestVisible)
            {
                changeLocation.Load();
                changeLocation.IsHitTestVisible = true;
                grid.IsHitTestVisible           = false;

                Panel.SetZIndex(grid, 0);
                Panel.SetZIndex(changeLocation, 1);

                if (Settings.AnimationsEnabled)
                {
                    screenshot.Source = ImageProc.GetImage(grid);
                    grid.Visibility   = Visibility.Collapsed;
                    new AnimationHelpers.SlideDisplay(changeLocation, screenshot).SwitchViews(AnimationHelpers.SlideDirection.Left);
                }
                else
                {
                    grid.Visibility           = Visibility.Collapsed;
                    changeLocation.Visibility = Visibility.Visible;
                }
            }
        }
Beispiel #12
0
        private static void SaveScreenshot(Window owner, StatusStrip statusStrip, UIElement source, string filename)
        {
            try
            {
                RenderTargetBitmap img   = ImageProc.GetImage(source, Brushes.White);
                BitmapFrame        frame = BitmapFrame.Create(img);

                FileStream fStream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);

                switch (Path.GetExtension(filename).ToLower())
                {
                case ".jpg":
                case ".jpeg":
                case ".jpe":
                case ".jfif":
                    JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder();
                    jpgEncoder.QualityLevel = 100;
                    jpgEncoder.Frames.Add(frame);
                    jpgEncoder.Save(fStream);
                    break;

                case ".png":
                    PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
                    pngEncoder.Interlace = PngInterlaceOption.On;
                    pngEncoder.Frames.Add(frame);
                    pngEncoder.Save(fStream);
                    break;

                case ".bmp":
                    BmpBitmapEncoder bmpEncoder = new BmpBitmapEncoder();
                    bmpEncoder.Frames.Add(frame);
                    bmpEncoder.Save(fStream);
                    break;

                case ".gif":
                    GifBitmapEncoder gifEncoder = new GifBitmapEncoder();
                    gifEncoder.Frames.Add(frame);
                    gifEncoder.Save(fStream);
                    break;

                default:
                    TaskDialog dialog = new TaskDialog(owner, "Error Saving File",
                                                       "The requested file type is not available.",
                                                       MessageType.Error);
                    dialog.ShowDialog();
                    break;
                }

                fStream.Close();

                statusStrip.UpdateMainStatus("EXPORT SUCCESSFUL");
            }
            catch (Exception exc)
            {
                statusStrip.UpdateMainStatus("ERROR: " + exc.Message.ToUpper());

                TaskDialog dialog = new TaskDialog(owner, "Error Saving File", exc.Message, MessageType.Error);
                dialog.ShowDialog();

                ExportScreenshot(owner, statusStrip, source, filename, Path.GetDirectoryName(saveDialog.SelectedFile));
            }
        }
        private void NextSlide()
        {
            if (counter > 0)
            {
                floatingLogo.FadeIn();
            }

            if (counter < Slides.Length)
            {
                object next = Slides[counter++];

                image.Source = ImageProc.GetImage(content);

                //
                // Install
                //
                if (next is CEIP)
                {
                    nextButton.IsEnabled = true;
                }
                else if (next is ProductKey)
                {
                    InstallerData.JoinedCEIP = (content.Content as CEIP).joinCEIP.IsChecked == true;

                    ProductKey _next = next as ProductKey;

                    _next.OptionSelected   -= ProductKey_OptionSelected;
                    _next.OptionDeselected -= ProductKey_OptionDeselected;
                    _next.OptionSelected   += ProductKey_OptionSelected;
                    _next.OptionDeselected += ProductKey_OptionDeselected;

                    if (_next.freeTrial.IsChecked == true || InstallerData.ProductKey != null)
                    {
                        nextButton.IsEnabled = true;
                    }
                }
                else if (next is License)
                {
                    // In case of upgrade, the product key slide will never be shown.
                    if (content.Content is CEIP)
                    {
                        InstallerData.JoinedCEIP = (content.Content as CEIP).joinCEIP.IsChecked == true;
                    }

                    License _next = next as License;

                    _next.Agreed    -= License_Agreed;
                    _next.Disagreed -= License_Disagreed;
                    _next.Agreed    += License_Agreed;
                    _next.Disagreed += License_Disagreed;

                    if (InstallerData.AcceptedAgreement)
                    {
                        nextButton.IsEnabled = true;
                    }

                    //	nextButton.Content = "_Install";
                }
                else if (next is Personalize)
                {
                    nextButton.IsEnabled = true;
                    nextButton.Content   = "_Install";
                }
                //else if (next is InstallLocation)
                //{
                //	nextButton.IsEnabled = true;
                //	nextButton.Content = "_Install";
                //}
                else if (next is InstallProgress)
                {
                    prevButton.FadeOut();
                    prevButton.IsEnabled = false;

                    nextButton.Content = "_Working...";

                    //InstallerData.InstallLocation = (content.Content as InstallLocation).installLocation.Text;

                    if (!InstallerData.InstallLocation.EndsWith("\\" + InstallerData.DisplayName))
                    {
                        InstallerData.InstallLocation += "\\" + InstallerData.DisplayName;
                    }

                    (next as InstallProgress).Error     += Install_Error;
                    (next as InstallProgress).Completed += Install_Completed;
                }

                //
                // Uninstall
                //
                if (next is Uninstall.UninstallOptions)
                {
                    nextButton.IsEnabled = true;
                    nextButton.Content   = "_Uninstall";
                }
                else if (next is Uninstall.UninstallProgress)
                {
                    prevButton.FadeOut();
                    prevButton.IsEnabled = false;

                    nextButton.Content = "_Working...";

                    Uninstall.UninstallOptions optns = content.Content as Uninstall.UninstallOptions;

                    InstallerData.DeleteDatabase   = (bool)optns.deleteDatabase.IsChecked;
                    InstallerData.DeleteAccounts   = (bool)optns.deleteAccounts.IsChecked;
                    InstallerData.DeleteSettings   = (bool)optns.deleteSettings.IsChecked;
                    InstallerData.DeleteDictionary = (bool)optns.deleteDictionary.IsChecked;

                    (next as Uninstall.UninstallProgress).Error     += Uninstall_Error;
                    (next as Uninstall.UninstallProgress).Completed += Uninstall_Completed;
                }

                content.Content = next;
                content.UpdateLayout();
                content.SlideDisplay(image, Extensions.SlideDirection.Right);
            }
            else
            {
                Close();
            }
        }
Beispiel #14
0
        /// <summary>
        /// 显示图片
        /// </summary>
        /// <param name="Index"></param>
        private void ShowImage(int Index)
        {
            //当无图片则返回
            if (CarImages.Count == 0)
            {
                return;
            }

            //笔刷
            Graphics g;

            //载入图片
            Bitmap tempImage = new Bitmap(CarImages[Index]);

            //载入处理图片数据
            ImageProc tempImageProc;

            if (checkedListBox_ShownOptions.GetItemChecked(7))
            {
                tempImageProc = new ImageProc(tempImage);
            }
            else
            {
                tempImageProc = new ImageProc();
            }

            //显示底图
            if (checkedListBox_ShownOptions.GetItemChecked(0) == false)
            {
                g = Graphics.FromImage(tempImage);
                g.Clear(ShowImageColor.Back);
            }
            //显示左边线
            if (checkedListBox_ShownOptions.GetItemChecked(4) == true)
            {
                if (tempImageProc.LeftLine != null)
                {
                    for (int n = 0; n < tempImageProc.LeftLineCnt; n++)
                    {
                        tempImage.SetPixel(
                            tempImageProc.LeftLine[n], RealSize.Height - 1 - n,
                            ShowImageColor.LeftLine);
                    }
                }
            }
            //显示右边线
            if (checkedListBox_ShownOptions.GetItemChecked(5) == true)
            {
                if (tempImageProc.RightLine != null)
                {
                    for (int n = 0; n < tempImageProc.RightLineCnt; n++)
                    {
                        tempImage.SetPixel(
                            tempImageProc.RightLine[n], RealSize.Height - 1 - n,
                            ShowImageColor.RightLine);
                    }
                }
            }
            //显示中线
            if (checkedListBox_ShownOptions.GetItemChecked(6) == true)
            {
                if (tempImageProc.MiddleLine != null)
                {
                    for (int n = 0; n < tempImageProc.MiddleLineCnt; n++)
                    {
                        tempImage.SetPixel(
                            tempImageProc.MiddleLine[n], RealSize.Height - 1 - n,
                            ShowImageColor.MiddleLine);
                    }
                }
            }

            //显示图片矢量放大
            Bitmap ImageToShow = new Bitmap(
                pictureBox_Preview.Width,
                pictureBox_Preview.Height);

            g = Graphics.FromImage(ImageToShow);
            //显示图片对应捕获图片一个像素尺寸
            Size PixelSize = new Size(
                pictureBox_Preview.Width / RealSize.Width,
                pictureBox_Preview.Height / RealSize.Height);

            //填充色块
            for (int y = 0; y < RealSize.Height; y++)
            {
                for (int x = 0; x < RealSize.Width; x++)
                {
                    g.FillRectangle(
                        new SolidBrush(tempImage.GetPixel(x, y)),
                        new Rectangle(
                            new Point(x * PixelSize.Width, y * PixelSize.Height),
                            PixelSize));
                }
            }

            label_CarRodeType.Text = "赛道类型:" + tempImageProc.RodeType.ToString();

            //更新序列
            curCarImageIndex = Index;
            //更新显示图片
            pictureBox_Preview.Image = ImageToShow;
            //更新列表
            listBox_ImageList.SelectedIndex = curCarImageIndex;

            //内存回收
            GC.Collect();
        }
Beispiel #15
0
        /// <summary>
        /// 显示图片
        /// </summary>
        /// <param name="Index"></param>
        private void ShowImage(int Index)
        {
            //当无图片则返回
            if (CarImages.Count == 0)
            {
                return;
            }

            //笔刷
            Graphics g;
            //载入图片
            Bitmap tempImage = new Bitmap(CarImages[Index]);

            //载入处理图片数据
            ImageProc tempImageProc;

            if (checkedListBox_ShownOptions.GetItemChecked(7))
            {
                tempImageProc = new ImageProc(tempImage);
            }
            else
            {
                tempImageProc = new ImageProc();
            }

            //显示底图
            if (checkedListBox_ShownOptions.GetItemChecked(0) == false)
            {
                g = Graphics.FromImage(tempImage);
                g.Clear(ShowImageColor.Back);
            }
            //显示左边线
            if (checkedListBox_ShownOptions.GetItemChecked(4) == true)
            {
                if (tempImageProc.LeftLine != null)
                {
                    for (int n = 0; n <= tempImageProc.LeftLineCnt; n++)
                    {
                        tempImage.SetPixel(
                            tempImageProc.LeftLine[n], RealSize.Height - 1 - n,
                            ShowImageColor.LeftLine);
                    }
                }
            }
            //显示右边线
            if (checkedListBox_ShownOptions.GetItemChecked(5) == true)
            {
                if (tempImageProc.RightLine != null)
                {
                    for (int n = 0; n <= tempImageProc.RightLineCnt; n++)
                    {
                        tempImage.SetPixel(
                            tempImageProc.RightLine[n], RealSize.Height - 1 - n,
                            ShowImageColor.RightLine);
                    }
                }
            }
            //显示中线
            if (checkedListBox_ShownOptions.GetItemChecked(6) == true)
            {
                if (tempImageProc.MiddleLine != null)
                {
                    for (int n = 0; n <= tempImageProc.MiddleLineCnt; n++)
                    {
                        tempImage.SetPixel(
                            tempImageProc.MiddleLine[n], RealSize.Height - 1 - n,
                            ShowImageColor.MiddleLine);
                    }
                }
            }

            //显示图片矢量放大
            Bitmap ImageToShow = new Bitmap(
                labal_pictureBox_Preview.Width,
                labal_pictureBox_Preview.Height);

            g = Graphics.FromImage(ImageToShow);
            //显示图片对应捕获图片一个像素尺寸
            Size PixelSize = new Size(
                labal_pictureBox_Preview.Width / RealSize.Width,
                labal_pictureBox_Preview.Height / RealSize.Height);

            //填充色块
            for (int y = 0; y < RealSize.Height; y++)
            {
                for (int x = 0; x < RealSize.Width; x++)
                {
                    g.FillRectangle(
                        new SolidBrush(tempImage.GetPixel(x, y)),
                        new Rectangle(
                            new Point(x * PixelSize.Width, y * PixelSize.Height),
                            PixelSize));
                }
            }
            label_CarRodeType.Text = "赛道类型:" + tempImageProc.RodeType.ToString();
            label_CarBattVol.Text  = "处理行:" + tempImageProc.MiddleLineCnt.ToString();
//           label_up_bias.Text = "标准行:" + tempImageProc.normline.ToString();
//            label_CarAimSpeed.Text = "中线偏差:" + tempImageProc.MiddleBias.ToString();
//            label_down_bias.Text = "是否加速:" + tempImageProc.steepup.ToString();
//            label_Middle_K.Text = "1_中线斜率:" + tempImageProc.Middle_K.ToString();
            StripStatusLabel1_codition.Text = "判断条件:" + tempImageProc.retcond.ToString();
//            label_Left_K.Text = "2_中线斜率:" + tempImageProc.Left_K.ToString();
//            label_Right_K.Text = "3_中线斜率:" + tempImageProc.Right_K.ToString();
            //更新序列
            curCarImageIndex = Index;
            //更新显示图片
            labal_pictureBox_Preview.Image = ImageToShow;
            //更新列表
            listBox_ImageList.SelectedIndex = curCarImageIndex;

            //内存回收
            GC.Collect();
        }
Beispiel #16
0
 private void PrepareScreenshot()
 {
     PART_ContentScreenshot.Source  = ImageProc.GetImage(PART_Content);
     PART_ContentScreenshot.Opacity = 1;
 }