/// <summary> /// Одновременное считывание и обработка кадра видеопотока /// </summary> /// <param name="sWTVideoTextDetection">Детектор текста</param> /// <param name="frameLoader">Загрузчик кадра</param> /// <param name="keyFrameIOInformation">Информация об извлекаемом кадре</param> /// <param name="videoFileName">Имя видеофайла</param> /// <param name="threadsNumber">Число потоков для выделения текста</param> /// <returns></returns> public async static Task LoadDetectTextVideo(SWTVideoTextDetection sWTVideoTextDetection, FrameLoader frameLoader, List<KeyFrameIOInformation> keyFrameIOInformation, string videoFileName, int threadsNumber) { try { if (sWTVideoTextDetection == null) throw new ArgumentNullException("Null sWTVideoTextDetection in LoadDetectTextVideo"); if (frameLoader == null) throw new ArgumentNullException("Null frameLoader in LoadDetectTextVideo"); if (keyFrameIOInformation == null) throw new ArgumentNullException("Null keyFrameIOInformation in LoadDetectTextVideo"); if (videoFileName == null) throw new ArgumentNullException("Null videoFileName in LoadDetectTextVideo"); for (int i = 0; i < keyFrameIOInformation.Count; i++) { GreyVideoFrame frame = await frameLoader.LoadFrameAsync(videoFileName, keyFrameIOInformation[i]); await sWTVideoTextDetection.DetectText(frame, threadsNumber); FrameWasProcessedEvent(frame); } } catch (Exception exception) { throw exception; } }
/// <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> /// Выделение текста на ключевых кадрах видеоролика /// </summary> private async void DetectVideoTextFunction() { try { if (this.keyFrameIOInformation != null) { SWTVideoTextDetection SWTVideoTextDetection = new SWTVideoTextDetection(0.5); FrameLoader frameLoader = new FrameLoader(); this.StartLoader(DETECT_TEXT_VIDEO_STRING); LoadDetectTextVideoMediator.FrameWasProcessedEvent += this.AddProcessedFrameToBitmapArray; await LoadDetectTextVideoMediator.LoadDetectTextVideo(SWTVideoTextDetection, frameLoader, this.keyFrameIOInformation, this.videoFileNameString, 4); this.StopLoader(); } else { 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_STRING); await SWTVideoTextDetection.DetectText(this.video, 4); this.StopLoader(); } OkButtonWindow okButtonWindow = OkButtonWindow.InitializeOkButtonWindow(); okButtonWindow.capitalText.Text = VIDEO_PROCESS_STRING; okButtonWindow.textInformation.Text = VIDEO_PROCESS_SUCCESS_STRING; okButtonWindow.ShowDialog(); if (this.keyFrameIOInformation == null) { this.StartLoader(PROCESS_DATA_FOR_OUTPUT_STRING); this.CreateBitmapsFromProcessedVideoFrames(); this.StopLoader(); } this.InitializeProcessedVideoFramesGallery(); this.IsVideoFrameTabSelected = false; this.IsProcessedVideoFramesTabSelected = true; this.IsProcessedVideoFrameTabSelected = false; this.IsVideoTabSelected = false; } catch (Exception exception) { this.StopLoader(); ShowExceptionMessage(exception.Message); } }