private static void connectRoutine_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            Image <Bgr, byte> connecting = new Image <Bgr, byte>(new Bitmap((int)MainWindow.mMainWindow.ibOriginal.Width, (int)MainWindow.mMainWindow.ibOriginal.Height));

            connecting.SetValue(new Bgr(Color.Gray));   // Set background color
            ShapeNDraw.drawString("Connecting", connecting, new System.Drawing.Point(connecting.Width / 3 - 10, connecting.Height / 2 - 10), 1, Color.White);

            Image <Bgr, byte> connected = new Image <Bgr, byte>(new Bitmap((int)MainWindow.mMainWindow.ibOriginal.Width, (int)MainWindow.mMainWindow.ibOriginal.Height));

            connected.SetValue(new Bgr(Color.Black));   // Set background color
            ShapeNDraw.drawString("Connected", connected, new System.Drawing.Point(connected.Width / 3 - 10, connected.Height / 2 - 10), 1, Color.White);


            if (e.ProgressPercentage == 0)
            {
                MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(connecting);
                MainWindow.mMainWindow.Btn_PR.IsEnabled  = false;
            }


            if (e.ProgressPercentage == 100)
            {
                MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(connected);
                MainWindow.mMainWindow.Btn_PR.IsEnabled  = true;
                PreviewRoutine.startPreview(PreviewRoutine._previewFPS);
            }
        }
        private void Img_viewer_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            lbl_imgInfo.Content = $"Mouse Location: [{e.GetPosition(Img_viewer).X : 0}, {e.GetPosition(Img_viewer).Y : 0}]";
            if (currentImage != null)
            {
                System.Drawing.Point p = new System.Drawing.Point();
                p.X = (int)e.GetPosition(Img_viewer).X;
                p.Y = (int)e.GetPosition(Img_viewer).Y;
                if (!selectingArea)
                {
                    return;
                }

                if (((double)p.X / zoomFactor_x) != X0)
                {
                    X1 = ((double)p.X / zoomFactor_x);
                }
                if (((double)p.Y / zoomFactor_y) != Y0)
                {
                    Y1 = ((double)p.Y / zoomFactor_y);
                }

                cropRect = ShapeNDraw.MakeRectangle(X0, Y0, X1, Y1);

                Bitmap bmp = currentImage.Copy().ToBitmap();
                selectedGraphics = Graphics.FromImage(bmp);
                selectedGraphics.FillRectangle(new SolidBrush(Color.FromArgb(128, 72, 145, 220)), cropRect);
                Img_viewer.Source = ImgConverter.ToBitmapSource(bmp);
            }
        }
Example #3
0
 private void Btn_setOCRArea_Click(object sender, RoutedEventArgs e)
 {
     if (GV.mCamera != null && GV.mCamera.IsConnected)
     {
         if (PreviewRoutine.IsCapturing)
         {
             PreviewRoutine.StopPreview();
             BindMngr.GMessage.value = "Select the area and hit set area again to confirm";
         }
         else if (!PreviewRoutine.IsCapturing && ImgCropping.rect.Width * ImgCropping.rect.Height != 0)
         {
             OCR.croppedOCRArea = ImgCropping.rect;
             PreviewRoutine.startPreview(PreviewRoutine._previewFPS);
             BindMngr.GMessage.value = "Area set! Only do OCR inside the red rectangle!";
         }
     }
     else if (!PreviewRoutine.IsCapturing && ImgCropping.rect.Width * ImgCropping.rect.Height != 0)   //crop static picture
     {
         OCR.croppedOCRArea      = ImgCropping.rect;
         BindMngr.GMessage.value = "Area set! Only do OCR inside the red rectangle!";
         MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(GV.imgOriginal);
         Image <Bgr, byte> bm = GV.imgOriginal.Copy();
         bm.Draw(OCR.croppedOCRArea, new Bgr(Color.Red), 2);
         MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(bm);
     }
 }
Example #4
0
        private void Btn_runML_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.mMainWindow.listBox.Items.Clear();
            switch (MLCore.MLModelSelected)
            {
            case MLModel.ResNet:
                ResNet.EvaluationSingleImage(GV.imgOriginal);

                for (int i = 0; i < ResNet.resultList.Count; i++)
                {
                    MainWindow.mMainWindow.listBox.Items.Add(string.Format("{0}: {1}", MLCore.MLSelectedLabels[i], ResNet.resultList[i]));
                }
                BindMngr.GMessage.value = string.Format("This must be a {0}!", ResNet.OutputString, ResNet.OutputProbablility);
                break;

            case MLModel.FastRCNN:
                FastRCNN.EvaluateObjectDetectionModel();
                break;

            case MLModel.Yolo:
                GV.imgProcessed = new Image <Bgr, byte>(mYolo.Detect(GV.imgOriginal.ToBitmap()));
                MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(GV.imgProcessed);
                break;
            }
        }
Example #5
0
        private void ibOriginal_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _mouseDown = true;
            if (GV.imgOriginal != null)
            {
                PreviewRoutine.StopPreview();
                ibOriginal.Cursor = Cursors.Cross;
                System.Drawing.Point p = new System.Drawing.Point();
                p.X = (int)e.GetPosition(ibOriginal).X;
                p.Y = (int)e.GetPosition(ibOriginal).Y;

                if ((bool)Radio_Color.IsChecked && (bool)Chk_multiColorPoints.IsChecked)
                {
                    if (GV._remainColorPoints > 0)
                    {
                        Rectangle bond = new Rectangle(
                            p.X - GV._colorRegionSize / 2, p.Y - GV._colorRegionSize / 2,
                            GV._colorRegionSize, GV._colorRegionSize);

                        GV.imgOriginal.Draw(bond, new Bgr(Color.AliceBlue), 1);

                        MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(GV.imgOriginal);

                        regionImgSet[GV._remainColorPoints - 1] = GV.imgOriginal_pure.Copy(bond);

                        GV._remainColorPoints--;
                    }
                }
                else
                {
                    ImgCropping.WPF_mouseDown(GV.imgOriginal, ibOriginal, p, GV._zoomFactor);
                }
            }
        }
Example #6
0
 private void Btn_staticReset_Click(object sender, RoutedEventArgs e)
 {
     if (GV.imgOriginal_save != null)
     {
         GV.imgOriginal = GV.imgOriginal_save.Copy();
     }
     ibOriginal.Source = ImgConverter.ToBitmapSource(GV.imgOriginal);
 }
Example #7
0
 private void Chk_multiColorPoints_Checked(object sender, RoutedEventArgs e)
 {
     if (PreviewRoutine.IsCapturing)
     {
         PreviewRoutine.StopPreview();
         Thread.Sleep(300);
         if (GV.imgOriginal_pure == null)
         {
             MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(GV.imgOriginal_pure);
         }
     }
 }
Example #8
0
        private void File_loadImg_Click(object sender, RoutedEventArgs e)
        {
            Bitmap loadPic = Tools.loadPicture_withDialog();

            if (loadPic != null)
            {
                GV.imgOriginal_save = ImgStiching.createFixRatioBitmap((new Image <Bgr, byte>(loadPic)).Copy(), 4, 3);
                GV.imgOriginal      = GV.imgOriginal_save.Copy();
                ibOriginal.Source   = ImgConverter.ToBitmapSource(GV.imgOriginal);
                GV.IsPictureLoaded  = true;
                GF.UpdateImgInfo();
            }
        }
 private void DrawRegion(imgInfo imgIn, ref Image <Bgr, byte> image)
 {
     foreach (regionInfo ri in imgIn.regionInfoList)
     {
         Bitmap bmp = image.ToBitmap();
         selectedGraphics = Graphics.FromImage(bmp);
         selectedGraphics.DrawRectangle(new Pen(Color.Red), ri.rect);
         selectedGraphics.DrawString($"{ri.labelIndex}-{labelSet[ri.labelIndex]}"
                                     , new Font("Arial", 9), new SolidBrush(Color.Red), ri.rect.X, ri.rect.Y);
         image = new Image <Bgr, byte>(bmp);
     }
     /// Update final image
     Img_viewer.Source = ImgConverter.ToBitmapSource(image.ToBitmap());
 }
Example #10
0
        private void Btn_setReference_Click(object sender, RoutedEventArgs e)
        {
            if (ImgCropping.rect.Width * ImgCropping.rect.Height != 0)
            {
                Image <Bgr, byte> Img = GV.imgOriginal_pure;
                GV.ref_img         = Img.Copy(ImgCropping.rect).Convert <Bgr, byte>(); //new Image<Gray, Byte>(mCrop.cropBitmap(imgOriginal.ToBitmap(), mCrop.rect));
                ibReference.Source = ImgConverter.ToBitmapSource(GV.ref_img);

                if (GV.mCamera.IsConnected)
                {
                    PreviewRoutine.startPreview(PreviewRoutine._previewFPS);
                }
            }
        }
Example #11
0
        private void Btn_apply_object_Click(object sender, RoutedEventArgs e)
        {
            if (GV.object_img != null && GV.imgOriginal != null)
            {
                //====Processed image==========
                GV.imgProcessed   = NCVFuns.Detection(GV.imgOriginal, DetectionType.Object, out GV._err);
                ibOriginal.Source = ImgConverter.ToBitmapSource(GV.imgProcessed);
            }
            else if (GV.object_img == null)
            {
                GV._err = ErrorCode.No_object_image;
            }

            BindMngr.GMessage.value = GV._err.ToString();
        }
Example #12
0
        private static void decodeRoutine_WorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (loc.Count != 0)
            {
                Image <Bgr, Byte> processed = ImgToDecode;
                //drawDecodeResultInImg(processed);  //can't draw on a roated bitmap...

                MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(processed.Convert <Bgr, Byte>().Rotate(_angle, new Bgr(Color.Black), false));
            }
            else
            {
                MainWindow.mMainWindow.listBox.Items.Add("Fail to find any result");
            }
            s = 0;
        }
        private void LoadImg_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            BindManager.BindMngr.Progress.value       = e.ProgressPercentage;
            BindManager.BindMngr.ProgressString.value = BindManager.BindMngr.Progress.value + "%";

            BindManager.BindMngr.GMessage.value = string.Format("Loading images...({0})", BindManager.BindMngr.ProgressString.value);

            try
            {
                imgThumbList[((imgInfo)e.UserState).index].Source = ImgConverter.ToBitmapSource(((imgInfo)e.UserState).image);
            }
            catch (Exception)
            {; }

            ((imgInfo)e.UserState).image.Dispose();
        }
Example #14
0
 private void ibOriginal_MouseUp(object sender, MouseButtonEventArgs e)
 {
     _mouseDown = false;
     if (GV.imgOriginal != null)
     {
         if ((bool)Radio_Color.IsChecked && (bool)Chk_multiColorPoints.IsChecked)
         {
             if (GV._remainColorPoints == 0)
             {
                 finalColorRegionImg =
                     imageCombine(imageCombine(regionImgSet[0], regionImgSet[1]), regionImgSet[2]);
                 Chk_multiColorPoints.IsChecked         = false;
                 MainWindow.mMainWindow.ibObject.Source = ImgConverter.ToBitmapSource(finalColorRegionImg);
             }
         }
         else
         {
             ibOriginal.Cursor = Cursors.Arrow;
             ImgCropping.WPF_mouseUp(ibOriginal, GV._zoomFactor);
         }
     }
 }
        public static void GUIUpdates()
        {
            // Normal
            MainWindow.mMainWindow.ibOriginal.Source    = ImgConverter.ToBitmapSource(GV.imgProcessed);
            MainWindow.mMainWindow.TB_preveiw_info.Text = videoFPS;

            if (isStopSignDetected && !isBlinking)
            {
                GV.RobotVoice.Volume = 100;         // 0...100
                GV.RobotVoice.Rate   = 0;           // -10...10
                GV.RobotVoice.SpeakAsync("Stop Sign Detected");
                isBlinking = true;
                MainWindow.mMainWindow.Panel_stop.Visibility = System.Windows.Visibility.Visible;
                AniShape.blink(MainWindow.mMainWindow.Panel_stop, true);
            }
            else if (notStopSignCount >= DELAY && isBlinking)
            {
                notStopSignCount = 0;
                isBlinking       = false;
                MainWindow.mMainWindow.Panel_stop.Visibility = System.Windows.Visibility.Collapsed;
                AniShape.blink(MainWindow.mMainWindow.Panel_stop, false);
            }
        }
Example #16
0
        private void Btn_setObject_Click(object sender, RoutedEventArgs e)
        {
            if (finalColorRegionImg != null)
            {
                GV.object_img = finalColorRegionImg.Copy();
                finalColorRegionImg.Dispose();

                if (GV.mCamera.IsConnected)
                {
                    PreviewRoutine.startPreview(PreviewRoutine._previewFPS);
                }
            }
            else if (ImgCropping.rect.Width * ImgCropping.rect.Height != 0)
            {
                Image <Bgr, byte> Img = GV.imgOriginal;
                GV.object_img   = Img.Copy(ImgCropping.rect).Convert <Bgr, byte>(); //new Image<Gray, Byte>(mCrop.cropBitmap(imgOriginal.ToBitmap(), mCrop.rect));
                ibObject.Source = ImgConverter.ToBitmapSource(GV.object_img);

                if (GV.mCamera.IsConnected)
                {
                    PreviewRoutine.startPreview(PreviewRoutine._previewFPS);
                }
            }
        }
Example #17
0
 private static void OCRRoutine_WorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     MainWindow.mMainWindow.ibOriginal.Source = ImgConverter.ToBitmapSource(GV.imgProcessed);
     MainWindow.mMainWindow.lbl_OCR.Content   = detectedOCRString + " [" + timeSpent.ToString("#") + " ms]";
 }