示例#1
0
 private void Rotate(ImageFactory imageFactory, ProcessingParameters parameters)
 {
     if (parameters.RotationAngle == 0)
     {
         return;
     }
     imageFactory.Rotate(parameters.RotationAngle);
 }
示例#2
0
        private void Resize(ImageFactory imageFactory, ProcessingParameters parameters)
        {
            if (parameters.ScaleX == 1 && parameters.ScaleY == 1)
            {
                return;
            }
            var size        = new Size((int)(imageFactory.Image.Width * parameters.ScaleX), (int)(imageFactory.Image.Height * parameters.ScaleY));
            var resizeLayer = new ResizeLayer(size, ResizeMode.Stretch);

            imageFactory.Resize(resizeLayer);
        }
示例#3
0
 public Bitmap ProcessImage(Bitmap image, ProcessingParameters parameters)
 {
     using (var imageFactory = new ImageFactory(preserveExifData: true))
     {
         using (var stream = new MemoryStream())
         {
             image.Save(stream, ImageFormat.Png);
             imageFactory.Load(stream);
             Resize(imageFactory, parameters);
             Crop(imageFactory, parameters);
             Rotate(imageFactory, parameters);
             imageFactory.Save(stream);
             var result = new Bitmap(stream);
             return(result);
         }
     }
 }
示例#4
0
        /// <summary>
        /// Выполняет один тест чтения скрываемого текста при искажении с указанными параметрами и возвращает его результат
        /// </summary>
        /// <param name="sourceImagePath">Путь к исходному изображению</param>
        /// <param name="fullContainer">Заполненный контейнер</param>
        /// <param name="hiddenText"></param>
        /// <param name="encoder"></param>
        /// <param name="parameters"></param>
        /// <param name="saveProcessed"></param>
        /// <returns></returns>
        private RobustnessTestResult RunSingleTest(string sourceImagePath, Bitmap fullContainer, string hiddenText, IEncoder encoder, ProcessingParameters parameters, bool saveProcessed = true)
        {
            var processedImage = processor.ProcessImage(fullContainer, parameters);
            var result         = new RobustnessTestResult()
            {
                Parameters      = parameters,
                SourceImagePath = sourceImagePath
            };

            if (saveProcessed)
            {
                var processedPath = Path.Combine(
                    Path.GetDirectoryName(sourceImagePath),
                    "Processed",
                    string.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(sourceImagePath), GetTimeStamp(), Path.GetExtension(sourceImagePath))
                    );
                processedImage.Save(processedPath);
                result.ProcessedImagePath = processedPath;
            }
            result.ErrorRateTransformed = errorEstimator.EstimateBitErrorRate(hiddenText, processedImage, encoder);
            return(result);
        }