public void OpenStream(ImageType imageType, ImageResolution resolution) { HRESULT res = NuiImageStreamOpen(imageType, resolution, 0, 2, IntPtr.Zero, ref streamHandle); if (res != HRESULT.S_OK) throw new Exception("Failed to open stream, return value:" + res.ToString()); }
static ImageResolution GetResolution(this Image image) { if (image == null) { throw new InvalidOperationException(); } var resultResolution = new ImageResolution(); resultResolution.Height = image.Height; resultResolution.Width = image.Width; try { if (Optimization.IsEnable && (image.Width > Optimization.MaximumResolution.Width || image.Height > Optimization.MaximumResolution.Height)) { if (image.Height > image.Width) { resultResolution.Width = Optimization.MaximumResolution.Width; resultResolution.Height = resultResolution.Width / image.Width * resultResolution.Height; } else { resultResolution.Height = Optimization.MaximumResolution.Height; resultResolution.Width = resultResolution.Height / image.Height * resultResolution.Width; } } return(resultResolution); } catch (ArgumentException) { throw new ArgumentException(); } }
public static void ResizeImage(string imagePath, ImageResolution newSize) { // https://stackoverflow.com/questions/1922040/resize-an-image-c-sharp var destImage = new Bitmap(newSize.WidthInt, newSize.HeightInt); using (var image = Image.FromFile(imagePath)) { var destRect = new Rectangle(0, 0, newSize.WidthInt, newSize.HeightInt); destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (var graphics = Graphics.FromImage(destImage)) { graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var wrapMode = new ImageAttributes()) { wrapMode.SetWrapMode(WrapMode.TileFlipXY); graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode); } } } destImage.Save(imagePath); }
public void Load(System.Data.DataRow row) { ImageResolution mainResolution = ImageResolution.R_Undefined; Enum.TryParse <ImageResolution>(row["MainResolution"].ToString(), out mainResolution); ImageResolution subResolution = ImageResolution.R_Undefined; Enum.TryParse <ImageResolution>(row["SubResolution"].ToString(), out subResolution); StreamType strType = Config.StreamType.mainStream; Enum.TryParse <StreamType>(row["StreamType"].ToString(), out strType); _id = row["Id"] != null ? new Guid(row["Id"].ToString()) : System.Guid.NewGuid(); _guid = row["Guid"] != null?Convert.ToInt32(row["Guid"]) : 0; _nvrID = row["NvrID"] != null?Convert.ToInt32(row["NvrID"]) : 0; _channelID = row["ChannelID"] != null?Convert.ToInt32(row["ChannelID"]) : 0; _channelName = row["ChannelName"] as string; _frameRate = row["FrameRate"] != null?Convert.ToInt32(row["FrameRate"]) : 0; _streamFormat = row["StreamFormat"] as string; _audioFormat = row["AudioFormat"] as string; _rtsp1 = row["Rtsp1"] as string; _rtsp2 = row["Rtsp2"] as string; _mainResolution = mainResolution; _subResolution = subResolution; _streamType = strType; _cameraID = row["CameraID"] as string; _areaName = row["AreaName"] as string; _isBackRecord = row["IsBackRecord"] != null?byte.Parse(row["IsBackRecord"].ToString()) : (byte)0; }
/// <summary> /// Enables data from the sensor with the specified format. /// </summary> /// <param name="type">Image type to use</param> /// <param name="resolution">Image resolution to use. The default value is ImageResolution.Resolution640x480.</param> public void Enable(ImageType type, ImageResolution resolution) { var res = NuiImageStreamOpen(type, resolution, 0, 2, IntPtr.Zero, ref streamHandle); if (res != HRESULT.S_OK) throw new KinectException("Failed to open the imagestream."); IsEnabled = true; }
private string ImageResolutionSuffix(ImageResolution ir) { if (ir == ImageResolution.High) { return "e"; } else if (ir == ImageResolution.Medium) { return "4"; } else { return "2"; } }
private string ImageResolutionPrefix(ImageResolution ir) { if (ir == ImageResolution.High) { return ""; } else if (ir == ImageResolution.Medium) { return "640_480/"; } else { return "256_192/"; } }
internal ImageFrame(ImageType imageType, ImageResolution imageResolution, int height, int width, int framenumber, int pixelDataLength, int timestamp, byte[] data) { ImageType = imageType; Resolution = imageResolution; Height = height; Width = width; FrameNumber = framenumber; PixelDataLength = pixelDataLength; Timestamp = timestamp; ImageData = data; BytesPerPixel = pixelDataLength / (Width * Height); }
/// <summary> /// Starts acquisition of depth frames. /// </summary> /// <param name="resolution">The resolution to use for the depth camera.</param> /// <param name="includePlayerIndex">If set to <c>true</c> it includes the player index (id of tracked skeleton) in the event arguments.</param> /// <param name="numBuffers">The number of image buffers to use. A larger number results in smoother playback but more latency as well. Default is 2.</param> public void StartDepthFrames(ImageResolution resolution, bool includePlayerIndex = false, int numBuffers = 2) { Contract.Requires(!this.DepthFramesRunning); Contract.Requires(numBuffers > 0); Contract.Ensures(this.DepthFramesRunning); if (!this.DepthFramesRunning) { var type = includePlayerIndex ? ImageType.DepthAndPlayerIndex : ImageType.Depth; this.Device.DepthStream.Open(ImageStreamType.Depth, numBuffers, resolution, type); _DepthFramesRunning = true; } }
/// <summary> /// Starts acquisition of video frames. /// </summary> /// <param name="resolution">The resolution to use for the video camera.</param> /// <param name="type">The type of image to acquire between RGB and YAV.</param> /// <param name="numBuffers">The number of image buffers to use. A larger number results in smoother playback but more latency as well. Default is 2.</param> public void StartVideoFrames(ImageResolution resolution, ImageType type = ImageType.Color, int numBuffers = 2) { Contract.Requires(!this.VideoFramesRunning); Contract.Requires(type == ImageType.Color || type == ImageType.ColorYuv || type == ImageType.ColorYuvRaw); Contract.Requires(numBuffers > 0); Contract.Ensures(this.VideoFramesRunning); if (!this.VideoFramesRunning) { this.Device.VideoStream.Open(ImageStreamType.Video, numBuffers, resolution, type); _VideoFramesRunning = true; } }
public ImageCacheKey(string imageName, string imageResolution = null, string backgroundColour = null, string watermarkText = null, string imageType = null) { _imageResolution = ImageResolution.Parse(imageResolution); _backgroundColour = BackgroundColour.Parse(backgroundColour); if (!string.IsNullOrWhiteSpace(watermarkText)) { _watermarkHash = GetWatermarkStringHash(watermarkText); } _imageType = ImageType.Parse(imageType); ImageName = imageName; }
/// <summary> /// Generates camera screens to use inside an Urho context based on the /// ImageCameras recieved from the QTM host. /// </summary> /// <returns></returns> public static bool GenerateCameras() { CurrentCamera = null; Cameras = new Dictionary <int, Camera>(); CameraScreen.ResetScreenCounter(); // Get Camera Settings List <SettingsGeneralCameraSystem> cameraSettingsList = SettingsService.GetCameraSettings(); // Get Image Settings List <ImageCamera> imageCameraSettingsList = SettingsService.GetImageCameraSettings(); // Iterate over image settings list and create camera objects foreach (ImageCamera imageCameraSettings in imageCameraSettingsList) { SettingsGeneralCameraSystem cameraSettings = cameraSettingsList .Where(c => c.CameraId == imageCameraSettings.CameraID) .First(); if (!imageCameraSettings.Enabled && cameraSettings.Mode != CameraMode.ModeMarker) { SettingsService.SetCameraMode(imageCameraSettings.CameraID, cameraSettings.Mode); } ImageResolution imageResolution = new ImageResolution(imageCameraSettings.Width / 2, imageCameraSettings.Height / 2); // Create camera object and add it to dictionary Camera camera = new Camera(imageCameraSettings.CameraID, cameraSettings, imageResolution); Cameras.Add(camera.ID, camera); // Make sure that the current settings are reflected in the state of the application // The state of the QTM host should always have precedence unless expliciltly told to // change settings if (CurrentCamera == null) { CurrentCamera = camera; } } // Load and run profiler CameraProfiler cameraProfiler = new CameraProfiler(Cameras, "CameraProfiles.json"); cameraProfiler.Run(); // Dispose of it once it's done cameraProfiler.Dispose(); cameraProfiler = null; return(true); }
private string ImageResolutionSuffix(ImageResolution ir) { if (ir == ImageResolution.High) { return("e"); } else if (ir == ImageResolution.Medium) { return("4"); } else { return("2"); } }
private string ImageResolutionPrefix(ImageResolution ir) { if (ir == ImageResolution.High) { return(""); } else if (ir == ImageResolution.Medium) { return("640_480/"); } else { return("256_192/"); } }
/// <summary> /// Grid element, contains a frame and the marker spheres to be displayed /// </summary> public CameraScreen(int cameraID, ImageResolution resolution, float frameHeight, float frameWidth, Color backgroundColor) { // Set position according to screenCount and increment the counter position = screenCount; screenCount++; CameraID = cameraID; Resolution = resolution; ReceiveSceneUpdates = true; FrameColor = backgroundColor; Height = frameHeight; Width = frameWidth; }
/// <summary> /// https://etastaging.s3.amazonaws.com/img/catalog/view/3c41wO-19.jpg /// det lader ikke til at login er krævet for at hente den konkrete JPG.... /// </summary> /// <param name="catalogId"></param> /// <param name="pageIndex"></param> /// <returns></returns> public static string GetPageUri(string catalogId, string pageIndex, ImageResolution resolution = ImageResolution.Thumb) { if (resolution == ImageResolution.Thumb) { return(string.Format("https://etastaging.s3.amazonaws.com/img/catalog/thumb/{0}-{1}.jpg", catalogId, pageIndex)); } else if (resolution == ImageResolution.View) { return(string.Format("https://etastaging.s3.amazonaws.com/img/catalog/view/{0}-{1}.jpg", catalogId, pageIndex)); } else if (resolution == ImageResolution.Zoom) { return(string.Format("https://etastaging.s3.amazonaws.com/img/catalog/zoom/{0}-{1}.jpg", catalogId, pageIndex)); } throw new ArgumentOutOfRangeException("ImageResolution"); }
public static ImageSize ToDimension(this ImageResolution imageSizeKind) { switch (imageSizeKind) { default: case ImageResolution.Undefined: throw new NotSupportedException($"Value {imageSizeKind} cannot be transformed into a valid instance of {nameof(ImageSize)}"); case ImageResolution.Small: return(ImageSize.Small); case ImageResolution.Medium: return(ImageSize.Medium); case ImageResolution.Large: return(ImageSize.Large); } }
public Camera(int id, SettingsGeneralCameraSystem settings, ImageResolution imageResolution) { ID = id; Settings = settings; ImageResolution = imageResolution; Model = GetModelName(settings.Model); Orientation = settings.Orientation; PageTitle = "#" + ID + " " + Model; LensControlEnabled = CheckForLensControl(); // TODO: this should not have to be done in the constructor if (IsImageMode()) { EnableImageMode(false); } }
public static string GetPageUri(Catalog catalog, int pageIndex, ImageResolution resolution = ImageResolution.Thumb) { if (catalog == null) { throw new ArgumentNullException("Catalog"); } int pageCount; if (!int.TryParse(catalog.PageCount, out pageCount)) { throw new ArgumentOutOfRangeException("Catalog.PageCount is not a valid number!"); } if (pageIndex <= 0 || pageIndex > pageCount) { throw new ArgumentOutOfRangeException("PageIndex should be between 1 and pageCount"); } return(GetPageUri(catalog.Id, pageIndex.ToString(), resolution)); }
public ChannelItem(int guid, string chName, string channel, int frameRate, string strFormat, string audio, string rtsp1, string rtsp2, ImageResolution main, ImageResolution child, StreamType streamtype, string cameraID, string cityName, bool isBackRecord, string remoteEP) { Guid = guid; Name = chName; Channel = channel; FrameRate = frameRate; StrFormat = strFormat; Audio = audio; Rtsp1 = rtsp1; Rtsp2 = rtsp2; MainResolution = main; SubResolution = child; StreamType = streamtype; CameraID = cameraID; AreaName = cityName; IsBackRecord = isBackRecord; RemoteEP = remoteEP; }
private static extern HRESULT NuiImageStreamOpen(ImageType eImageType, ImageResolution eResolution, uint dwImageFrameFlags, uint dwFrameLimit, IntPtr hNextFrameEvent, ref IntPtr phStreamHandle);
public ImageOptimization(ImageResolution maximumResolution) { MaximumResolution = maximumResolution; IsEnable = true; }
static void Main(string[] args) { //var readLine = Console.ReadLine(); //if (readLine == null) return; //var args = readLine.Split(' '); //var args = new[] { "house2.bmp", "house222.bmp", "canny", "1", "0,25", "0,1" }; //task1 //Инверсия значений пикселей изображения if (args.Length == 3 && args[2] == "invert") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); Inversion.InversionProcess(image); ImageIO.ImageToFile(image, outputFileName); } //Отражение изображения по вертикали и по горизонтали if (args.Length == 4 && args[2] == "mirror") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); if (args[3] == "x") { Reflection.FlipHorizontal(image); } if (args[3] == "y") { Reflection.FlipVertical(image); } ImageIO.ImageToFile(image, outputFileName); } //Поворот изображений по и против часовой стрелки на 90, 180 и 270 градусов(на произвольный угол) if (args.Length == 5 && args[2] == "rotate") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); if (args[3] == "cw") { image = Rotate.ClockWiseRotate(image, angle: int.Parse(args[4])); } if (args[3] == "ccw") { image = Rotate.CounterClockWiseRotate(image, angle: int.Parse(args[4])); } ImageIO.ImageToFile(image, outputFileName); } //фильтр Превитта if (args.Length == 4 && args[2] == "prewitt") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); if (args[3] == "x") { image = MedianFiltering.Convolution(image, Filters.PrewittHorizontal(), 3, 2); } if (args[3] == "y") { image = MedianFiltering.Convolution(image, Filters.PrewittVertical(), 3, 2); } ImageIO.ImageToFile(image, outputFileName); } //фильтр Собеля if (args.Length == 4 && args[2] == "sobel") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); if (args[3] == "x") { image = MedianFiltering.Convolution(image, Filters.SobelHorizontal(), 3); } if (args[3] == "y") { image = MedianFiltering.Convolution(image, Filters.SobelVertical(), 3); } ImageIO.ImageToFile(image, outputFileName); } //фильтр Робертса if (args.Length == 4 && args[2] == "roberts") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); if (args[3] == "1") { image = MedianFiltering.Convolution(image, Filters.RobertsMainDiagonal(), 2, 2); } if (args[3] == "2") { image = MedianFiltering.Convolution(image, Filters.RobertsAdditionalDiagonal(), 2, 2); } ImageIO.ImageToFile(image, outputFileName); } //Медианная фильтрация с квадратным окном произвольного размера if (args.Length == 4 && args[2] == "median") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); image = MedianFiltering.MedianFilter(image, kernelSize: int.Parse(args[3])); ImageIO.ImageToFile(image, outputFileName); } //Свёртка с фильтром Гаусса с произвольным выбором параметра — радиуса σ if (args.Length == 4 && args[2] == "gauss") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); var data = new double[image.rawdata.Length]; var template = new double[image.rawdata.Length]; for (var i = 0; i < image.rawdata.Length; i++) { data[i] = Convert.ToDouble(image.rawdata[i]); } ConvolutionGauss.GaussProcess(data, image.Width, image.Height, sigma: double.Parse(args[3]), windowSize: 9, temp: template, dest: data); for (var i = 0; i < image.rawdata.Length; i++) { image.rawdata[i] = Convert.ToSingle(data[i]); } ImageIO.ImageToFile(image, outputFileName); } //Вычисление модуля градиента как корень из суммы квадратов свёрток с первой производной фильтра Гаусса по горизонтали и вертикали if (args.Length == 4 && args[2] == "gradient") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); ConvolutionGauss.GradientProcess(image.rawdata, image.Width, image.Height, double.Parse(args[3]), (int)(double.Parse(args[3]) * 6), image.rawdata); ImageIO.ImageToFile(image, outputFileName); } //Фильтр Габора с произвольными параметрами if (args.Length == 8 && args[2] == "gabor") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); image = ConvolutionGauss.Gabor(image, Filters.Gabor((int)(6 * double.Parse(args[3])), double.Parse(args[3]), double.Parse(args[6]), double.Parse(args[5]), double.Parse(args[4]), double.Parse(args[6])), (int)(6 * double.Parse(args[3])), (int)(6 * double.Parse(args[3])), int.Parse(args[7])); ImageIO.ImageToFile(image, outputFileName); } //Обнаружение сосудов на изображениях глазного дна с помощью фильтров Габора if (args.Length == 4 && args[2] == "vessels") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); image = ConvolutionGauss.Vessels(image, (int)(6 * Convert.ToDouble(args[3])), Convert.ToDouble(args[3])); ImageIO.ImageToFile(image, outputFileName); } //task2 //Увеличение изображений в вещественное число раз с помощью билинейной интерполяции if (args.Length == 4 && args[2] == "up_bilinear") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); image = ImageResolution.Bilinear(image, Convert.ToDouble(args[3])); ImageIO.ImageToFile(image, outputFileName); } //Увеличение изображений в вещественное число раз с помощью бикубической интерполяции if (args.Length == 4 && args[2] == "up_bicubic") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); var resultImage = ImageResolution.Bicubic(image, Convert.ToDouble(args[3])); ImageIO.ImageToFile(resultImage, outputFileName); } //Понижение разрешения изображений в вещественное число раз if (args.Length == 4 && args[2] == "downsample") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); image = ImageResolution.DownBilinear(image, Convert.ToDouble(args[3])); ImageIO.ImageToFile(image, outputFileName); } //Вычисление метрик сравнения изображений(MSE и PSNR, SSIM и MSSIM) if (args.Length == 4 && args[2] == "metric") { string inputFileName = args[0], inputFileName2 = args[1]; if (!File.Exists(inputFileName) || !File.Exists(inputFileName2)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); var image2 = ImageIO.FileToGrayscaleFloatImage(inputFileName2); double result; switch (args[3]) { case "mse": result = Metrics.Mse(image, image2); Console.WriteLine(result); Console.ReadKey(); break; case "psnr": result = Metrics.Psnr(image, image2); Console.WriteLine(result); Console.ReadKey(); break; case "ssim": result = Metrics.Ssim(image.rawdata, image2.rawdata, image.Width, image.Height); Console.WriteLine(result); Console.ReadKey(); break; case "mssim": result = Metrics.Mssim(image.rawdata, image2.rawdata, image.Width, image.Height); Console.WriteLine(result); Console.ReadKey(); break; } } //task3 //Алгоритм детектирования границ Канни if (args.Length == 6 && args[2] == "canny") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); var image2 = Canny.Process(image, Convert.ToSingle(args[3]), Convert.ToSingle(args[4]), Convert.ToSingle(args[5])); ImageIO.ImageToFile(image2, outputFileName); } //Алгоритм Харриса для детектирования углов if (args.Length == 4 && args[2] == "harris") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); image = Harris.Process(image, double.Parse(args[3])); ImageIO.ImageToFile(image, outputFileName); } //Билатеральная фильтрация изображений if (args.Length == 5 && args[2] == "bilateral") { string inputFileName = args[0], outputFileName = args[1]; if (!File.Exists(inputFileName)) { return; } var image = ImageIO.FileToGrayscaleFloatImage(inputFileName); image = Bilateral.Process(image, double.Parse(args[3]), double.Parse(args[3])); ImageIO.ImageToFile(image, outputFileName); } }
public ImageOptimization() { MaximumResolution = new ImageResolution(1920, 1080); IsEnable = false; }
protected override async Task <bool> Start(string tempInputFolderPath, string tempOutputFolderPath, string waifu2xCaffePath, string ffmpegPath) { _isRunning = true; _tempInputDir = tempInputFolderPath; this._taskState = "extracting animation frames"; InvokeTaskStateChanged(); var extractResult = await AnimationFrameExtractor.ExtractFrames(InputFilePath, tempInputFolderPath, () => this._canceled); if (this._canceled) { Logger.Information("Terminating frame extraction for {AnimationPath} since this task has been cancelled", this.InputFilePath); _isRunning = false; return(false); } if (extractResult == null) { Logger.Error("An error occurred while extracting the animation frames for {InputFilePath} using {TaskExtractorTypeName}", this.InputFilePath, AnimationFrameExtractor.GetType().Name); _isRunning = false; return(false); } TaskQueue tasks = new TaskQueue(); int numCompleted = 0; int numStarted = 0; Queue <string> remainingImages = new Queue <string>(extractResult.ExtractedFiles); var outputResolutionResolver = this.OutputResolutionResolver; ImageResolution inputImageResolution = null; ImageResolution previousResultOutputImageResolution = null; ImageResolution outputImageResolution; bool canUseOldFrames = false; using (var firstFrame = Image.FromFile(extractResult.ExtractedFiles.First())) { inputImageResolution = new ImageResolution { WidthInt = firstFrame.Width, HeightInt = firstFrame.Height }; outputImageResolution = outputResolutionResolver.Resolve(inputImageResolution); var resolvedResolutionSize = outputImageResolution.Width * outputImageResolution.Height / 1e6; var maxResolution = CompileProcess.MaxOutputResolutionMegapixels; if (resolvedResolutionSize > maxResolution) // Max output resolution is 8MP { Logger.Warning("Output resolution for animation frame {InputAnimation} is too high for the {ImageCompiler} animation frame compiler at {OutputResolutionMegapixels} megapixels, limiting output size to {MaxCompileResolutionMegapixels} megapixels.", InputFilePath, CompileProcess.GetType().Name, resolvedResolutionSize, maxResolution); outputResolutionResolver = new TargetPixelCountResolutionResolver(maxResolution * 1e6f); outputImageResolution = outputResolutionResolver.Resolve(inputImageResolution); } } // Take into account how output images are resized to have even dimensions after upscaling outputImageResolution.WidthInt += outputImageResolution.WidthInt % 2; outputImageResolution.HeightInt += outputImageResolution.HeightInt % 2; string firstPreviousResultOutputFramePath = Path.Combine(tempOutputFolderPath, Path.GetFileName(extractResult.ExtractedFiles.First())); if (File.Exists(firstPreviousResultOutputFramePath)) { previousResultOutputImageResolution = ImageHelper.GetImageResolution(firstPreviousResultOutputFramePath); } if (previousResultOutputImageResolution != null && previousResultOutputImageResolution.Distance(outputImageResolution) < 20) { canUseOldFrames = true; } List <string> outputImageFiles = new List <string>(); do { tasks.QueueLength = MaxWaifuTaskThreads; while (tasks.CanQueueTask && remainingImages.Count > 0) { this._taskState = $"{numCompleted}/{extractResult.ExtractedFiles.Count} frames complete, {MaxWaifuTaskThreads} at a time"; InvokeTaskStateChanged(); int frameIdx = ++numStarted; Logger.Debug("Starting frame {@FrameIndex}/{@NumFrames}", frameIdx, extractResult.ExtractedFiles.Count); string nextImgPath = remainingImages.Dequeue(); string fileName = Path.GetFileName(nextImgPath); string inputFramePath = Path.Combine(tempInputFolderPath, fileName); string outputFramePath = Path.Combine(tempOutputFolderPath, fileName); outputImageFiles.Add(outputFramePath); if (File.Exists(outputFramePath)) { Logger.Information("Found old output frame {FrameIndex} for {OutputAnimationPath}", frameIdx, OutputFilePath); if (!canUseOldFrames) { Logger.Information("Not using previous output frame {FrameIndex} for {OutputAnimationPath} since they do not match the current target resolution", frameIdx, this.OutputFilePath); Logger.Information("Current output resolution: {@CurrentOutputResolution}", outputImageResolution); Logger.Information("Previous output resolution: {@OldOutputResolution}", previousResultOutputImageResolution); File.Delete(outputFramePath); } else { var outputFrameRes = ImageHelper.GetImageResolution(outputFramePath); if (outputFrameRes != outputImageResolution) { Logger.Information("Using previous output frame {FrameIndex} for {OutputAnimationPath} but the image resolution is *slightly* off, resizing.."); ImageHelper.ResizeImage(outputFramePath, outputImageResolution); } numCompleted += 1; continue; } } var imageTask = new ImageTask(inputFramePath, outputFramePath, this.OutputResolutionResolver, this.ConvertMode); imageTask.TaskCompleted += (task) => { Interlocked.Increment(ref numCompleted); tasks.TryCompleteTask(task); }; imageTask.TaskFaulted += (task, reason) => { Logger.Debug("ImageTask failed for frame {@FrameIndex}/{@NumFrames} while upscaling {@InputFile} to {@OutputFile}", frameIdx, extractResult.ExtractedFiles.Count, inputFramePath, outputFramePath); }; imageTask.StartTask(tempInputFolderPath, tempOutputFolderPath, waifu2xCaffePath, ffmpegPath); tasks.TryQueueTask(imageTask); } numSubTasks = tasks.RunningTasks.Count; await Task.Delay(10); } while (numCompleted < extractResult.ExtractedFiles.Count && !_canceled); if (this._canceled) { Logger.Debug("Canceling frame upconversion"); foreach (var task in tasks.RunningTasks) { task.CancelTask(); } while (tasks.RunningTasks.Count > 0) { await Task.Delay(1); } this._isRunning = false; Logger.Debug("AnimationTask has been canceled"); return(false); } Logger.Information("Resizing output frames for {OutputAnimationPath} to have the same even dimensions"); foreach (var image in outputImageFiles) { var imageSize = ImageHelper.GetImageResolution(image); if (imageSize == outputImageResolution) { continue; } ImageHelper.ResizeImage(image, outputImageResolution); } this._taskState = $"Combining {extractResult.ExtractedFiles.Count} frames to {Path.GetExtension(OutputFilePath)}"; InvokeTaskStateChanged(); bool success = await CompileProcess.Run(InputFilePath, OutputFilePath, tempOutputFolderPath, extractResult.Fps); Cleanup(); _isRunning = false; return(success); }
/// <summary> /// Starts acquisition of video frames. /// </summary> /// <param name="resolution">The resolution to use for the video camera.</param> /// <param name="type">The type of image to acquire between RGB and YAV.</param> /// <param name="numBuffers">The number of image buffers to use. A larger number results in smoother playback but more latency as well. Default is 2.</param> public void StartVideoFrames(ImageResolution resolution, ImageType type = ImageType.Color, int numBuffers = 2) { Contract.Requires(!this.VideoFramesRunning); Contract.Requires(type == ImageType.Color || type == ImageType.ColorYuv || type == ImageType.ColorYuvRaw); Contract.Requires(numBuffers > 0); Contract.Ensures(this.VideoFramesRunning); if (!this.VideoFramesRunning) { this.Device.VideoStream.Open(ImageStreamType.Video, numBuffers, resolution, type); _VideoFramesRunning = true; } }
/// <summary> /// Starts acquisition of depth frames. /// </summary> /// <param name="resolution">The resolution to use for the depth camera.</param> /// <param name="includePlayerIndex">If set to <c>true</c> it includes the player index (id of tracked skeleton) in the event arguments.</param> /// <param name="numBuffers">The number of image buffers to use. A larger number results in smoother playback but more latency as well. Default is 2.</param> public void StartDepthFrames(ImageResolution resolution, bool includePlayerIndex = false, int numBuffers = 2) { Contract.Requires(!this.DepthFramesRunning); Contract.Requires(numBuffers > 0); Contract.Ensures(this.DepthFramesRunning); if (!this.DepthFramesRunning) { var type = includePlayerIndex ? ImageType.DepthAndPlayerIndex : ImageType.Depth; this.Device.DepthStream.Open(ImageStreamType.Depth, numBuffers, resolution, type); _DepthFramesRunning = true; } }
/// <summary> /// Convert Co-ordinates in Depth-image space to Video-frame space. /// </summary> /// <param name="colorResolution">The resoultion of the video</param> /// <param name="depthX">The depth x-ordinate (in [0,1] space)</param> /// <param name="depthY">The depth y-ordinate (in [0,1] space)</param> /// <param name="videoX">(output) x-ordinate in video-frame space</param> /// <param name="videoY">(output) y-ordinate in video-frame space</param> public void GetVideoCoordsFromDepth(ImageResolution colorResolution, int depthX, int depthY, out int videoX, out int videoY) { // defer the calculation to the Kinect driver kinectNUI.NuiCamera.GetColorPixelCoordinatesFromDepthPixel( colorResolution, new ImageViewArea(), depthX, depthY, 0, out videoX, out videoY); }
private void OnImageResolutionChanged(ImageResolutionChanged message) { _imageResolution = message.ImageResolution; CanExecuteChanged?.Invoke(this, EventArgs.Empty); }
public static int GetSizeForResolution(ImageResolution imageResolution) { switch (imageResolution) { case ImageResolution.Invalid: return 0; case ImageResolution.Resolution1280x1024: return 1280 * 1024; case ImageResolution.Resolution640x480: return 640 * 480; case ImageResolution.Resolution320x240: return 320 * 240; case ImageResolution.Resolution80x60: return 80 * 60; default: return 0; } }
public static int GetHeightForResolution(ImageResolution imageResolution) { switch (imageResolution) { case ImageResolution.Invalid: return 0; case ImageResolution.Resolution1280x1024: return 1024; case ImageResolution.Resolution640x480: return 480; case ImageResolution.Resolution320x240: return 240; case ImageResolution.Resolution80x60: return 60; default: return 0; } }
public ActionResult Create([Bind(Include = "ID,Title,Description,Type,Tags,Salt,SplitPhotographKey,PhotographWidth,PhotographHeight,UHD4K,FHD,HD,nHD,LikeCount,FavouriteCount,CreationDate")] Photograph photograph, HttpPostedFileBase upload) { if (ModelState.IsValid) { // Create original photograph key string originalPhotographKey = Utility.Crypto.GenerateRandomAlphaNumericString(10); photograph.OriginalPhotographKey = originalPhotographKey; // Create SplitPhotographKey string splitImageKey = Utility.Crypto.GenerateRandomAlphaNumericString(8); photograph.SplitPhotographKey = splitImageKey; //Setting row or column count /* * TODO: specify splitcoumnCount and splitRowCount. * Need to just specify count. Logic for splitting and displaying images is already sorted. */ photograph.SplitColumnCount = Constants.SPLIT_IMAGE_COLUMN_COUNT; photograph.SplitRowCount = Constants.SPLIT_IMAGE_ROW_COUNT; photograph.CreationDate = DateTime.Now; db.Photograph.Add(photograph); db.SaveChanges(); if (upload != null && upload.ContentLength > 0) { var photographDirecotoryPath = HttpContext.Server.MapPath("~/photograph"); //Naming of folder and files associated with image var imageFolderPath = Path.Combine(photographDirecotoryPath, photograph.ID.ToString()); if (!System.IO.Directory.Exists(imageFolderPath)) { System.IO.Directory.CreateDirectory(imageFolderPath); } var originalFilePath = Path.Combine(imageFolderPath, photograph.ID + "_" + originalPhotographKey + ".jpg"); var loweResolutionImagePath = Path.Combine(imageFolderPath, photograph.ID + ".jpg"); var thumbnailImagePath = Path.Combine(imageFolderPath, photograph.ID + "_th.jpg"); //Copy stream as original file using (Stream outputFile = System.IO.File.Create(originalFilePath)) { Utility.FileUtility.CopyStream(upload.InputStream, outputFile); } Bitmap img = new Bitmap(upload.InputStream); var imageHeight = img.Height; var imageWidth = img.Width; //Updating photographs width and height photograph.PhotographWidth = imageWidth; photograph.PhotographHeight = imageHeight; bool isImageHorizontal = true; if (imageHeight > imageWidth) { isImageHorizontal = false; } //Generating thumbnail Utility.ImageUtility.ResizeImage(originalFilePath, thumbnailImagePath, 0, 75); //Generating low resolution image if (isImageHorizontal) { Utility.ImageUtility.ResizeImage(originalFilePath, loweResolutionImagePath, 400, 0); } else { Utility.ImageUtility.ResizeImage(originalFilePath, loweResolutionImagePath, 0, 300); } //Utility.ImageUtility.CropImage(originalFilePath, temp2FilePath, 0 , 0, 200, 200); /* * Creating images in different resolution and their respective split images */ // Photograph size currently not available photograph.HD = false; photograph.nHD = false; photograph.UHD4K = false; photograph.FHD = false; photograph.qHD = false; photograph.og = false; //Create list of imageResolution. These ImageResolution's will be create for image. For adding new ImageResolution, add it to this list. List <ImageResolution> imageResolutionList = new List <ImageResolution>(); imageResolutionList.Add(ImageResolution.UHD4K); imageResolutionList.Add(ImageResolution.FHD); imageResolutionList.Add(ImageResolution.qHD); imageResolutionList.Add(ImageResolution.nHD); //Special case when image resolution is smaller than 'nHD'. Create split image and name it as _og.jpg if ((imageWidth < ImageResolution.nHD.Width && imageHeight < ImageResolution.nHD.Height) && (imageWidth > 400 || imageHeight > 300)) { ImageResolution customOgImageResolution = ImageResolution.og; customOgImageResolution.Width = imageWidth; customOgImageResolution.Height = imageHeight; imageResolutionList.Add(customOgImageResolution); photograph.og = true; } foreach (ImageResolution imageResolution in imageResolutionList) { if (imageWidth >= imageResolution.Width || imageHeight >= imageResolution.Height) { //Create resized image for particular iamge resolution var resizedImagePath = Path.Combine(imageFolderPath, photograph.ID + "_" + originalPhotographKey + "_" + imageResolution.Representation + ".jpg"); if (isImageHorizontal) { Utility.ImageUtility.ResizeImage(originalFilePath, resizedImagePath, imageResolution.Width, 0); } else { Utility.ImageUtility.ResizeImage(originalFilePath, resizedImagePath, 0, imageResolution.Height); } //Split Image wiht spili image key Service.PhotographService.SplitImage(resizedImagePath, imageFolderPath, photograph.ID.ToString(), splitImageKey, Constants.SPLIT_IMAGE_COLUMN_COUNT, Constants.SPLIT_IMAGE_ROW_COUNT, imageResolution.Representation); //Setting ture value for resolution in Photograph switch (imageResolution.Representation) { case Constants.RESOLUTION_4K: photograph.UHD4K = true; break; case Constants.RESOLUTION_FHD: photograph.FHD = true; break; case Constants.RESOLUTION_qHD: photograph.qHD = true; break; case Constants.RESOLUTION_nHD: photograph.nHD = true; break; } } } } db.SaveChanges(); return(RedirectToAction("Manage")); } return(View(photograph)); }
public static bool ToPdf(this Document document, IEnumerable <ElementId> viewElementIds, string path, PdfSharp.PageSize pageSize = PdfSharp.PageSize.A4, ImageResolution imageResolution = ImageResolution.DPI_600) { if (document == null || viewElementIds == null || string.IsNullOrWhiteSpace(path)) { return(false); } if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path))) { return(false); } //Creating directory for temporary images string directory = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.Guid.NewGuid().ToString()); System.IO.Directory.CreateDirectory(directory); string name = string.IsNullOrEmpty(document.Title) ? "???" : document.Title; //Adjusting image pixel size int pixelSize = 512; switch (pageSize) { case PdfSharp.PageSize.A0: pixelSize = 14043; break; case PdfSharp.PageSize.A1: pixelSize = 9933; break; case PdfSharp.PageSize.A2: pixelSize = 7016; break; case PdfSharp.PageSize.A3: pixelSize = 4961; break; case PdfSharp.PageSize.A4: pixelSize = 3508; break; case PdfSharp.PageSize.A5: pixelSize = 2480; break; } //Adjusting image resolution switch (imageResolution) { case ImageResolution.DPI_600: pixelSize = pixelSize * 2; break; case ImageResolution.DPI_300: pixelSize = pixelSize * 1; break; case ImageResolution.DPI_150: pixelSize = System.Convert.ToInt32(pixelSize * 0.5); break; case ImageResolution.DPI_72: pixelSize = System.Convert.ToInt32(pixelSize * 0.25); break; } //Creating Revit Export Options for View Image ImageExportOptions imageExportOptions = new ImageExportOptions() { FilePath = System.IO.Path.Combine(directory, name), FitDirection = FitDirectionType.Horizontal, ZoomType = ZoomFitType.FitToPage, ImageResolution = imageResolution, HLRandWFViewsFileType = ImageFileType.PNG, ShadowViewsFileType = ImageFileType.PNG, PixelSize = pixelSize, ExportRange = ExportRange.SetOfViews }; //Exporting temporary images from Views. Necessary to do it one by one to keep view order List <string> imagePaths = new List <string>(); foreach (ElementId elementId in viewElementIds) { if (elementId == null) { continue; } View view = document.GetElement(elementId) as View; if (view == null) { continue; } imageExportOptions.SetViewsAndSheets(new List <ElementId>() { elementId }); document.ExportImage(imageExportOptions); foreach (string imagePath in System.IO.Directory.GetFiles(directory)) { if (!imagePaths.Contains(imagePath)) { imagePaths.Add(imagePath); break; } } } //Creating pdf Document from view images using (PdfDocument pdfDocument = new PdfDocument()) { foreach (string imagePath in imagePaths) { PdfPage pdfPage = pdfDocument.AddPage(); pdfPage.Size = pageSize; byte[] bytes = System.IO.File.ReadAllBytes(imagePath); using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(bytes, false)) { double widthFactor = 1; double heightFactor = 1; XImage xImage = XImage.FromStream(memoryStream); if (xImage.PointHeight > xImage.PointWidth) { pdfPage.Orientation = PdfSharp.PageOrientation.Portrait; widthFactor = xImage.PointWidth / pdfPage.Width.Point; } else { pdfPage.Orientation = PdfSharp.PageOrientation.Landscape; heightFactor = xImage.PointHeight / pdfPage.Height.Point; } XGraphics xGraphics = XGraphics.FromPdfPage(pdfPage); xGraphics.DrawImage(xImage, 0, 0, pdfPage.Width.Point * widthFactor, pdfPage.Height.Point * heightFactor); } } pdfDocument.Save(path); } //Removing temporary image files -> Not necessary foreach (string imagePath in imagePaths) { if (System.IO.File.Exists(imagePath)) { System.IO.File.Delete(imagePath); } } //Recursive removing whole temporary directory where view images were saved System.IO.Directory.Delete(directory, true); return(System.IO.File.Exists(path)); }