public void TestSobelFilter3() { //arrange EdgeDetectionFilter sobel = new SobelFilter(); GreyImage image = new GreyImage(2, 3); //act sobel.Apply(image); }
public void TestSobelFilter4() { //arrange EdgeDetectionFilter sobel = new SobelFilter(); GreyImage image = new GreyImage(3, 3); image.Pixels[0, 0].Color.Data = 50; image.Pixels[0, 1].Color.Data = 125; image.Pixels[0, 2].Color.Data = 22; image.Pixels[1, 0].Color.Data = 12; image.Pixels[1, 1].Color.Data = 17; image.Pixels[1, 2].Color.Data = 187; image.Pixels[2, 0].Color.Data = 201; image.Pixels[2, 1].Color.Data = 100; image.Pixels[2, 2].Color.Data = 45; GreyImage patternImage = new GreyImage(3, 3); patternImage.Pixels[0, 0].Color.Data = 50; patternImage.Pixels[0, 1].Color.Data = 125; patternImage.Pixels[0, 2].Color.Data = 22; patternImage.Pixels[1, 0].Color.Data = 12; patternImage.Pixels[1, 1].Color.Data = (byte) ColorBase.MIN_COLOR_VALUE; patternImage.Pixels[1, 1].BorderType = DigitalImageProcessingLib.BorderType.Border.STRONG; patternImage.Pixels[1, 2].Color.Data = 187; patternImage.Pixels[2, 0].Color.Data = 201; patternImage.Pixels[2, 1].Color.Data = 100; patternImage.Pixels[2, 2].Color.Data = 45; patternImage.Pixels[1, 1].Gradient.Angle = -36; patternImage.Pixels[1, 1].Gradient.Strength = 207; //act sobel.Apply(image); //assert Assert.IsTrue(image.IsEqual(patternImage)); }
public void TestSobelFilter5() { //arrange EdgeDetectionFilter sobel = new SobelFilter(); GreyImage image = new GreyImage(5, 4); image.Pixels[0, 0].Color.Data = 50; image.Pixels[0, 1].Color.Data = 125; image.Pixels[0, 2].Color.Data = 22; image.Pixels[0, 3].Color.Data = 11; image.Pixels[0, 4].Color.Data = 104; image.Pixels[1, 0].Color.Data = 12; image.Pixels[1, 1].Color.Data = 17; image.Pixels[1, 2].Color.Data = 187; image.Pixels[1, 3].Color.Data = 0; image.Pixels[1, 4].Color.Data = 15; image.Pixels[2, 0].Color.Data = 201; image.Pixels[2, 1].Color.Data = 100; image.Pixels[2, 2].Color.Data = 45; image.Pixels[2, 3].Color.Data = 91; image.Pixels[2, 4].Color.Data = 17; image.Pixels[3, 0].Color.Data = 100; image.Pixels[3, 1].Color.Data = 15; image.Pixels[3, 2].Color.Data = 18; image.Pixels[3, 3].Color.Data = 205; image.Pixels[3, 4].Color.Data = 194; GreyImage patternImage = new GreyImage(5, 4); patternImage.Pixels[0, 0].Color.Data = 50; patternImage.Pixels[0, 1].Color.Data = 125; patternImage.Pixels[0, 2].Color.Data = 22; patternImage.Pixels[0, 3].Color.Data = 11; patternImage.Pixels[0, 4].Color.Data = 104; patternImage.Pixels[1, 0].Color.Data = 12; patternImage.Pixels[1, 1].Color.Data = (byte) ColorBase.MIN_COLOR_VALUE; patternImage.Pixels[1, 2].Color.Data = (byte)ColorBase.MIN_COLOR_VALUE; patternImage.Pixels[1, 3].Color.Data = (byte)ColorBase.MIN_COLOR_VALUE; patternImage.Pixels[1, 1].BorderType = DigitalImageProcessingLib.BorderType.Border.STRONG; patternImage.Pixels[1, 2].BorderType = DigitalImageProcessingLib.BorderType.Border.STRONG; patternImage.Pixels[1, 3].BorderType = DigitalImageProcessingLib.BorderType.Border.STRONG; patternImage.Pixels[1, 4].Color.Data = 15; patternImage.Pixels[2, 0].Color.Data = 201; patternImage.Pixels[2, 1].Color.Data = (byte)ColorBase.MIN_COLOR_VALUE; patternImage.Pixels[2, 2].Color.Data = (byte)ColorBase.MIN_COLOR_VALUE; patternImage.Pixels[2, 3].Color.Data = (byte)ColorBase.MIN_COLOR_VALUE; patternImage.Pixels[2, 1].BorderType = DigitalImageProcessingLib.BorderType.Border.STRONG; patternImage.Pixels[2, 2].BorderType = DigitalImageProcessingLib.BorderType.Border.STRONG; patternImage.Pixels[2, 3].BorderType = DigitalImageProcessingLib.BorderType.Border.STRONG; patternImage.Pixels[2, 4].Color.Data = 17; patternImage.Pixels[3, 0].Color.Data = 100; patternImage.Pixels[3, 1].Color.Data = 15; patternImage.Pixels[3, 2].Color.Data = 18; patternImage.Pixels[3, 3].Color.Data = 205; patternImage.Pixels[3, 4].Color.Data = 194; patternImage.Pixels[1, 1].Gradient.Strength = 207; patternImage.Pixels[1, 1].Gradient.Angle = -36; patternImage.Pixels[1, 2].Gradient.Strength = 186; patternImage.Pixels[1, 2].Gradient.Angle = 32; patternImage.Pixels[1, 3].Gradient.Strength = 305; patternImage.Pixels[1, 3].Gradient.Angle = 18; patternImage.Pixels[2, 1].Gradient.Strength = 234; patternImage.Pixels[2, 1].Gradient.Angle = -21; patternImage.Pixels[2, 2].Gradient.Strength = 205; patternImage.Pixels[2, 2].Gradient.Angle = 41; patternImage.Pixels[2, 3].Gradient.Strength = 423; patternImage.Pixels[2, 3].Gradient.Angle = 82; //act image = sobel.Apply(image, 4); //assert Assert.IsTrue(image.IsEqual(patternImage)); }
/// <summary> /// Выделение текста на единичном кадре видеопотока /// </summary> /// <param name="videoFrame">Кадр видео</param> /// <returns>true</returns> public Task<bool> DetectText(GreyVideoFrame videoFrame, int threadsNumber) { try { if (videoFrame == null || videoFrame.Frame == null) throw new ArgumentNullException("Null frame in DetectText"); return Task.Run(() => { if (videoFrame.NeedProcess) { EdgeDetectionFilter sobel = new SobelFilter(); GradientFilter gradientFiler = new SimpleGradientFilter(); SmoothingFilter gauss = null; //new GaussFilter(this.GaussFilterSize, this.GaussFilterSigma); SmoothingFilter gaussForCanny = null; SWTTextDetection sWTTextDetection = null; if (ParametersUndefined(videoFrame)) { if (this.UseAdaptiveSmoothing) gaussForCanny = new AdaptiveGaussFilter(this.GaussFilterSigma); else gaussForCanny = new GaussFilter(this.GaussFilterSize, this.GaussFilterSigma); gauss = new GaussFilter(this.GaussFilterSize, this.GaussFilterSigma); CannyEdgeDetection canny = new CannyEdgeDetection(gaussForCanny, sobel, this.CannyLowTreshold, this.CannyHighTreshold); sWTTextDetection = new SWTTextDetection(canny, gauss, gradientFiler, this.VarienceAverageSWRation, this.AspectRatio, this.DiamiterSWRatio, this.BbPixelsNumberMinRatio, this.BbPixelsNumberMaxRatio, this.ImageRegionHeightRationMin, this.ImageRegionWidthRatioMin, this.PairsHeightRatio, this.PairsIntensityRatio, this.PairsSWRatio, this.PairsWidthDistanceSqrRatio, this.PairsOccupationRatio, this.MinLettersNumberInTextRegion, this.MergeByDirectionAndChainEnds); } else { if (videoFrame.UseAdaptiveSmoothing) gaussForCanny = new AdaptiveGaussFilter(videoFrame.GaussFilterSigma); else gaussForCanny = new GaussFilter(videoFrame.GaussFilterSize, videoFrame.GaussFilterSigma); gauss = new GaussFilter(videoFrame.GaussFilterSize, videoFrame.GaussFilterSigma); CannyEdgeDetection canny = new CannyEdgeDetection(gaussForCanny, sobel, videoFrame.CannyLowTreshold, videoFrame.CannyHighTreshold); sWTTextDetection = new SWTTextDetection(canny, gauss, gradientFiler, videoFrame.VarienceAverageSWRation, videoFrame.AspectRatio, videoFrame.DiamiterSWRatio, videoFrame.BbPixelsNumberMinRatio, videoFrame.BbPixelsNumberMaxRatio, videoFrame.ImageRegionHeightRationMin, videoFrame.ImageRegionWidthRatioMin, videoFrame.PairsHeightRatio, videoFrame.PairsIntensityRatio, videoFrame.PairsSWRatio, videoFrame.PairsWidthDistanceSqrRatio, videoFrame.PairsOccupationRatio, videoFrame.MinLettersNumberInTextRegion, videoFrame.MergeByDirectionAndChainEnds); } sWTTextDetection.DetectText(videoFrame.Frame, threadsNumber); } return true; }); } catch (Exception exception) { throw exception; } }
/// <summary> /// Выделение текста на кд\лючевых кадрах видеоролика /// </summary> /// <param name="video">Видеоролик</param> /// <returns>true</returns> public Task<bool> DetectText(GreyVideo video, int threadsNumber) { try { if (video == null) throw new ArgumentNullException("Null video in DetectText"); if (video.Frames == null) throw new ArgumentNullException("Null video frames in DetectText"); return Task.Run(() => { for (int i = 0; i < video.Frames.Count; i++) if (video.Frames[i].NeedProcess) { EdgeDetectionFilter sobel = new SobelFilter(); SmoothingFilter gauss = new GaussFilter(this.GaussFilterSize, this.GaussFilterSigma); GradientFilter gradientFiler = new SimpleGradientFilter(); CannyEdgeDetection canny = new CannyEdgeDetection(gauss, sobel, this.CannyLowTreshold, this.CannyHighTreshold); SWTTextDetection SWTTextDetection = new SWTTextDetection(canny, null, gradientFiler, this.VarienceAverageSWRation, this.AspectRatio, this.DiamiterSWRatio, this.BbPixelsNumberMinRatio, this.BbPixelsNumberMaxRatio, this.ImageRegionHeightRationMin, this.ImageRegionWidthRatioMin, this.PairsHeightRatio, this.PairsIntensityRatio, this.PairsSWRatio, this.PairsWidthDistanceSqrRatio, this.PairsOccupationRatio, this.MinLettersNumberInTextRegion, this.MergeByDirectionAndChainEnds); SWTTextDetection.DetectText(video.Frames[i].Frame, threadsNumber); } return true; }); } catch (Exception exception) { throw exception; } }