private void AddProcessedFrameToBitmapArray(GreyVideoFrame videoFrame) { try { if (this.processedVideoFramesBitmap == null) this.processedVideoFramesBitmap = new List<BitmapImage>(); if (this.processedVideoFramesBitmapForSave == null) this.processedVideoFramesBitmapForSave = new List<Bitmap>(); if (this.textRegionsDictionary == null) this.textRegionsDictionary = new Dictionary<int, List<TextRegion>>(); this.textRegionsDictionary.Add(videoFrame.FrameNumber, videoFrame.Frame.TextRegions); BitmapConvertor bitmapConvertor = new BitmapConvertor(); BitmapImageConvertor bitmapImageConvertor = new Convertors.BitmapImageConvertor(); Bitmap bitmapFrame = bitmapConvertor.ToBitmap(videoFrame.Frame); Draw.DrawTextBoundingBoxes(bitmapFrame, videoFrame.Frame.TextRegions, new System.Drawing.Pen(System.Drawing.Color.Red, 2)); this.processedVideoFramesBitmapForSave.Add(bitmapFrame); this.processedVideoFramesBitmap.Add(bitmapImageConvertor.BitmapToBitmapImage(bitmapFrame)); } catch (Exception exception) { throw exception; } }
/// <summary> /// Выделение текста на на единичном кадре видео /// </summary> private async void DetectVideoFrameTextFunction() { try { EvristicsWindow evristicsWindow = EvristicsWindow.InitializeEvristicsWindow(); evristicsWindow.capitalText.Text = PARAMETERS_SETTING_STRING; evristicsWindow.ShowDialog(); AlgorithmParametersWindow algorithmParametersWindow = AlgorithmParametersWindow.InitializeAlgorithmParametersWindow(); algorithmParametersWindow.capitalText.Text = PARAMETERS_SETTING_STRING; algorithmParametersWindow.ShowDialog(); EvristicsWindowViewModel evristicsWindowDataContext = (EvristicsWindowViewModel)evristicsWindow.DataContext; AlgorithmParametersViewModel algorithmParametersWindowDataContext = (AlgorithmParametersViewModel)algorithmParametersWindow.DataContext; SWTVideoTextDetection SWTVideoTextDetection = new SWTVideoTextDetection(evristicsWindowDataContext.VarienceAverageSWRation, algorithmParametersWindowDataContext.GaussFilterSize, algorithmParametersWindowDataContext.GaussSigma, algorithmParametersWindowDataContext.CannyLowTreshold, algorithmParametersWindowDataContext.CannyHighTreshold, evristicsWindowDataContext.AspectRatio, evristicsWindowDataContext.DiamiterSWRatio, evristicsWindowDataContext.BbPixelsNumberMinRatio, evristicsWindowDataContext.BbPixelsNumberMaxRatio, evristicsWindowDataContext.ImageRegionHeightRationMin, evristicsWindowDataContext.ImageRegionWidthRatioMin, evristicsWindowDataContext.PairsHeightRatio, evristicsWindowDataContext.PairsIntensityRatio, evristicsWindowDataContext.PairsSWRatio, evristicsWindowDataContext.PairsWidthDistanceSqrRatio, evristicsWindowDataContext.PairsOccupationRatio, evristicsWindowDataContext.MinLettersNumberInTextRegion, evristicsWindowDataContext.MergeByDirectionAndChainEnds, evristicsWindowDataContext.UseAdaptiveSmoothing); this.StartLoader(DETECT_TEXT_VIDEO_FRAME_STRING); await SWTVideoTextDetection.DetectText(this.videoFrame, 4); this.StopLoader(); OkButtonWindow okButtonWindow = OkButtonWindow.InitializeOkButtonWindow(); okButtonWindow.capitalText.Text = FRAME_PROCESS_STRING; okButtonWindow.textInformation.Text = FRAME_PROCESS_SUCCESS_STRING; okButtonWindow.ShowDialog(); BitmapConvertor bitmapConvertor = new BitmapConvertor(); Bitmap bitmapFrame = bitmapConvertor.ToBitmap(this.videoFrame.Frame); Draw.DrawTextBoundingBoxes(bitmapFrame, this.videoFrame.Frame.TextRegions, new System.Drawing.Pen(System.Drawing.Color.Red, 2)); BitmapImageConvertor bitmapImageConvertor = new Convertors.BitmapImageConvertor(); this.ProcessedFrameSource = bitmapImageConvertor.BitmapToBitmapImage(bitmapFrame); this.IsVideoFrameTabSelected = false; this.IsProcessedVideoFramesTabSelected = false; this.IsProcessedVideoFrameTabSelected = true; this.IsVideoTabSelected = false; } catch (Exception exception) { this.StopLoader(); ShowExceptionMessage(exception.Message); } }
/// <summary> /// Загрузка единичного кадра видео /// </summary> private async void LoadVideoFrameFunction() { try { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "JPEG Image (.jpg)|*.jpg"; dialog.ShowDialog(); FrameSizeWindow frameSizeWindow = FrameSizeWindow.InitializeFrameSizeWindow(); frameSizeWindow.capitalText.Text = PARAMETERS_SETTING_STRING; frameSizeWindow.ShowDialog(); FrameSizeViewModel frameSizeViewModel = (FrameSizeViewModel)frameSizeWindow.DataContext; IOData ioData = new IOData() { FileName = dialog.FileName, FrameHeight = frameSizeViewModel.FrameHeight, FrameWidth = frameSizeViewModel.FrameWidth }; VideoLoader.frameLoadedEvent += this.LoadingFramesProcessing; VideoLoader videoLoader = new VideoLoader(); FrameLoader frameLoader = new FrameLoader(); videoFrame = await frameLoader.LoadFrameAsync(ioData); OkButtonWindow okButtonWindow = OkButtonWindow.InitializeOkButtonWindow(); okButtonWindow.textInformation.Text = LOAD_FRAME_SUCCESS_STRING; okButtonWindow.capitalText.Text = LOAD_FRAME_STRING; okButtonWindow.ShowDialog(); Bitmap bitmapFrame = new Bitmap(dialog.FileName); BitmapImageConvertor bitmapImageConvertor = new Convertors.BitmapImageConvertor(); this.FrameSource = bitmapImageConvertor.BitmapToBitmapImage(bitmapFrame); this.ProcessedFrameSource = null; this.IsVideoFrameTabSelected = true; this.IsProcessedVideoFramesTabSelected = false; this.IsProcessedVideoFrameTabSelected = false; this.IsVideoTabSelected = false; } catch (Exception exception) { ShowExceptionMessage(exception.Message); } }
/// <summary> /// Запись обработанных ключевых кадров видео в виде BitmapImage, отрисовка прямоугольников текстовых областей /// </summary> private void CreateBitmapsFromProcessedVideoFrames() { try { this.processedVideoFramesBitmap = new List<BitmapImage>(); BitmapConvertor bitmapConvertor = new BitmapConvertor(); BitmapImageConvertor bitmapImageConvertor = new Convertors.BitmapImageConvertor(); for (int i = 0; i < this.video.Frames.Count; i++) { Bitmap bitmapFrame = bitmapConvertor.ToBitmap(this.video.Frames[i].Frame); Draw.DrawTextBoundingBoxes(bitmapFrame, this.video.Frames[i].Frame.TextRegions, new System.Drawing.Pen(System.Drawing.Color.Red, 2)); this.processedVideoFramesBitmap.Add(bitmapImageConvertor.BitmapToBitmapImage(bitmapFrame)); } } catch (Exception exception) { throw exception; } }