private void OnContractZone() { _sequenceDispose?.Dispose(); int stepCount = 100; var context = SynchronizationContext.Current; _sequenceDispose = Sequence.LimitedTimeSequence(stepCount, TimeSpan.FromMilliseconds(40)) .ObserveOn(Scheduler.Default) .Select(step => { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var bitmap = _zoneSimulator.DoContractSteps(stepCount, step); var bitmapSource = BitmapHelper.BitmapToBitmapSource(bitmap); bitmapSource.Freeze(); stopwatch.Stop(); return(new Tuple <int, long, BitmapSource>(step, stopwatch.ElapsedMilliseconds, bitmapSource)); }) .ObserveOn(context) .SubscribeOn(context) .Subscribe(tuple => { MatrixBitmapSource = tuple.Item3; Info = (stepCount - tuple.Item1).ToString(); CalculationTime = tuple.Item2.ToString() + " ms"; }, () => Info = "Done"); }
private void MenuOpen_OnClick(object sender, RoutedEventArgs e) { var openFileDialog = new OpenFileDialog(); { openFileDialog.Filter = "PNG图片|*.png|JPG图片|*.jpg|所有文件|*.*"; } if (openFileDialog.ShowDialog() == true) { mMat = CvInvoke.Imread(openFileDialog.FileName); SourcePic.ImageSource = BitmapHelper.BitmapToBitmapSource(mMat.ToBitmap()); imageProcess = new ImageProcess(mMat, imageMode); if (imageMode) { ImageRchannel.ImageSource = BitmapHelper.BitmapToBitmapSource(imageProcess.rImage.ToBitmap()); ImageGchannel.ImageSource = BitmapHelper.BitmapToBitmapSource(imageProcess.gImage.ToBitmap()); ImageBchannel.ImageSource = BitmapHelper.BitmapToBitmapSource(imageProcess.bImage.ToBitmap()); } else { ImageGchannel.ImageSource = BitmapHelper.BitmapToBitmapSource(imageProcess.grayImage.ToBitmap()); } modeChange(); } else { MessageBox.Show("没有选择图片"); } }
public FortniteZoneSimulatorViewModel() { AddZoneCommand = new DelegateCommand(OnAddZone); ContractZoneCommand = new DelegateCommand(OnContractZone); ResetZoneCommand = new DelegateCommand(OnResetZone); _zoneSimulator = new ZoneSimulator(); MatrixBitmapSource = BitmapHelper.BitmapToBitmapSource(_zoneSimulator.InitialZoneSet); }
private void RgbRadio_OnChecked(object sender, RoutedEventArgs e) { imageMode = true; if (imageProcess != null) { imageProcess.changeMode(true); ImageRchannel.ImageSource = BitmapHelper.BitmapToBitmapSource(imageProcess.rImage.ToBitmap()); ImageBchannel.ImageSource = BitmapHelper.BitmapToBitmapSource(imageProcess.bImage.ToBitmap()); } }
private void OnAddZone() { MatrixBitmapSource = BitmapHelper.BitmapToBitmapSource(_zoneSimulator.GetNextZoneSet()); }
private void OnResetZone() { _zoneSimulator.Reset(); MatrixBitmapSource = BitmapHelper.BitmapToBitmapSource(_zoneSimulator.InitialZoneSet); }
private void modeChange() { if (imageProcess == null) { return; } if (imageMode) { if (mode == 1) { List <string> list = new List <string>(); list = imageProcess.Lsbspy(); TextBoxR.Text = list[0]; TextBoxG.Text = list[1]; TextBoxB.Text = list[2]; } else { TextBoxR.Text = ""; TextBoxG.Text = ""; TextBoxB.Text = ""; } if (mode == 2) { VectorOfMat vector = new VectorOfMat(); vector = imageProcess.Dftspy(); ImageRProcessed.ImageSource = BitmapHelper.BitmapToBitmapSource(vector[0].ToBitmap()); ImageGProcessed.ImageSource = BitmapHelper.BitmapToBitmapSource(vector[1].ToBitmap()); ImageBProcessed.ImageSource = BitmapHelper.BitmapToBitmapSource(vector[2].ToBitmap()); } if (mode == 3) { VectorOfMat vector = new VectorOfMat(); vector = imageProcess.Dctspy(); ImageRProcessed.ImageSource = BitmapHelper.BitmapToBitmapSource(vector[0].ToBitmap()); ImageGProcessed.ImageSource = BitmapHelper.BitmapToBitmapSource(vector[1].ToBitmap()); ImageBProcessed.ImageSource = BitmapHelper.BitmapToBitmapSource(vector[2].ToBitmap()); } } else { if (mode == 1) { List <string> list = imageProcess.Lsbspy(); TextBoxG.Text = list.First(); } else { TextBoxG.Text = ""; } if (mode == 2) { VectorOfMat vector = new VectorOfMat(); vector = imageProcess.Dftspy(); ImageGProcessed.ImageSource = BitmapHelper.BitmapToBitmapSource(vector[0].ToBitmap()); } if (mode == 3) { VectorOfMat vector = new VectorOfMat(); vector = imageProcess.Dctspy(); ImageGProcessed.ImageSource = BitmapHelper.BitmapToBitmapSource(vector[0].ToBitmap()); } } }
private void TestVideoDetection() { Task.Run(() => { // YOLO setting //int yoloWidth = 1920, yoloHeight = 1129; int yoloWidth = 175, yoloHeight = 102; //int yoloWidth = 1000, yoloHeight = 588; var configurationDetector = new ConfigurationDetector(); var config = configurationDetector.Detect(); var yoloWrapper = new YoloWrapper(config); // OpenCV & WPF setting VideoCapture videocapture; Mat image = new Mat(); WriteableBitmap wb = new WriteableBitmap(yoloWidth, yoloHeight, 96, 96, System.Windows.Media.PixelFormats.Bgr24, null); byte[] imageInBytes = new byte[(int)(yoloWidth * yoloHeight * image.Channels())]; // Read a video file and run object detection over it! using (videocapture = new VideoCapture("E:\\WPF Projects\\Automotive_Drones_Analysis_Tool\\Daten_automatisches_Fahren\\DJI_0137.MP4")) { for (int i = 0; i < videocapture.FrameCount; i++) { using (Mat imageOriginal = new Mat()) { // read a single frame and convert the frame into a byte array videocapture.Read(imageOriginal); image = imageOriginal.Resize(new OpenCvSharp.Size(yoloWidth, yoloHeight)); imageInBytes = image.ToBytes(); // conduct object detection and display the result var items = yoloWrapper.Detect(imageInBytes); // We use the image to detect the objects in a very small size - then we draw them onto the // uiImage and scale it up! var uiImage = imageOriginal.Resize(new OpenCvSharp.Size(yoloWidth * 10, yoloHeight * 10)); foreach (var item in items) { var x = item.X * 10; var y = item.Y * 10; var width = item.Width * 10; var height = item.Height * 10; var type = item.Type; // class name of the object // draw a bounding box for the detected object // you can set different colors for different classes Cv2.Rectangle(uiImage, new OpenCvSharp.Rect(x, y, width, height), Scalar.Green, 3); } // display the detection result Application.Current?.Dispatcher?.Invoke(() => { videoViewer.Source = BitmapHelper.BitmapToBitmapSource(BitmapConverter.ToBitmap(uiImage)); }); } i++; } } }); }