/// <inheritdoc /> public void Apply(IImageContext context) { byte[] array = null; switch (this.CameraVersion) { case CameraVersion.OV5647: array = new byte[BayerMetaLengthV1]; Array.Copy(context.Data, context.Data.Length - BayerMetaLengthV1, array, 0, BayerMetaLengthV1); break; case CameraVersion.IMX219: array = new byte[BayerMetaLengthV2]; Array.Copy(context.Data, context.Data.Length - BayerMetaLengthV2, array, 0, BayerMetaLengthV2); break; } byte[] meta = new byte[4]; Array.Copy(array, 0, meta, 0, 4); if (Encoding.ASCII.GetString(meta) != "BRCM") { throw new Exception("Could not find Bayer metadata in header"); } context.Data = new byte[array.Length]; Array.Copy(array, context.Data, array.Length); }
/// <summary> /// Creates a new instance of <see cref="FrameDiffAnalyser"/>. /// </summary> /// <param name="config">The motion configuration object.</param> /// <param name="onDetect">A callback when changes are detected.</param> /// <param name="imageContext">The image metadata.</param> public FrameDiffAnalyser(MotionConfig config, Action onDetect, IImageContext imageContext) : base(imageContext) { this.TestFrame = new List <byte>(); this.MotionConfig = config; this.OnDetect = onDetect; }
private Bitmap LoadBitmap(IImageContext imageContext, MemoryStream stream) { if (imageContext.Raw) { return(new Bitmap(imageContext.Resolution.Width, imageContext.Resolution.Height, imageContext.PixelFormat)); } return(new Bitmap(stream)); }
private async void SaveImageAsync(IImageContext imageContext) { using (var stream = File.Create(image)) { await imageContext.SaveAsync(stream); } var navigationService = DependencyService.Get <INavigationService>(); await navigationService.NavigateBackAsync(); }
/// <summary> /// Call to enable motion detection. /// </summary> /// <param name="config">The motion configuration.</param> /// <param name="onDetect">A callback for when motion is detected.</param> /// <param name="imageContext">The frame metadata.</param> public void DetectMotion(MotionConfig config, Action onDetect, IImageContext imageContext) { this.Config = config; this.ShouldDetectMotion = true; if (this.MotionType == MotionType.FrameDiff) { this.Analyser = new FrameDiffAnalyser(config, onDetect, imageContext); } else { // TODO: Motion vector analyser } }
public void PerformEffects(IImageContext context) { int width = context.Width; int height = context.Height; context.ImagesAfterManipulate = new List <Image>(); foreach (var image in context.ImagesToManipulate) { var img = CreateRoundedCorner(image, RoundRectanglePosition.TopLeft); img = CreateRoundedCorner(image, RoundRectanglePosition.TopRight); img = CreateRoundedCorner(image, RoundRectanglePosition.BottomLeft); img = CreateRoundedCorner(image, RoundRectanglePosition.BottomRight); context.ImagesAfterManipulate.Add(ResizeBitmap(new Bitmap(img), width, height)); } }
private async void SaveImageAsync(IImageContext imageContext) { if (File.Exists(this.image)) { File.Delete(this.image); } var imagePath = Path.ChangeExtension(this.image, "png"); using (var stream = File.Create(imagePath)) { await imageContext.SaveAsync(stream, ImageFormat.Png, 1.0); } var navigationService = DependencyService.Get <INavigationService>(); Device.BeginInvokeOnMainThread(async() => { await navigationService.NavigateBackAsync(); }); }
private async void SaveImageAsync(IImageContext imageContext) { var imagePaths = await StorageHelper.EnumerateFilesAsync("ImageEditor", "ProfilePicture"); var imagePath = imagePaths.FirstOrDefault(); if (!string.IsNullOrEmpty(imagePath)) { using (var stream = File.OpenWrite(imagePath)) { var maximumSize = new Size(1000, 1000); await imageContext.SaveAsync(stream, ImageFormat.Png, 1.0, maximumSize); } } var navigationService = DependencyService.Get <INavigationService>(); Device.BeginInvokeOnMainThread(async() => { await navigationService.NavigateBackAsync(); }); }
public UnitOfWork() { context = new ImageContext(); }
/// <summary> /// Creates a new instance of <see cref="FrameProcessingContext"/>. /// </summary> /// <param name="context">Metadata for the image frame.</param> public FrameProcessingContext(IImageContext context) { _context = context; }
/// <summary> /// Apply a convolution based on the kernel passed in. /// </summary> /// <param name="store">The image data.</param> /// <param name="kernel">The kernel.</param> /// <param name="kernelWidth">The kernel's width.</param> /// <param name="kernelHeight">The kernel's height.</param> /// <param name="context">An image context providing additional metadata on the data passed in.</param> public void Convolute(byte[] store, double[,] kernel, int kernelWidth, int kernelHeight, IImageContext context) { Bitmap bmp = null; BitmapData bmpData = null; IntPtr pNative = IntPtr.Zero; int bytes, stride; byte[] rgbValues = null; using (var ms = new MemoryStream(store)) { if (context.Raw) { bmp = new Bitmap(context.Resolution.Width, context.Resolution.Height, context.PixelFormat); bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); pNative = bmpData.Scan0; Marshal.Copy(store, 0, pNative, store.Length); } else { bmp = new Bitmap(ms); bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); pNative = bmpData.Scan0; } unsafe { // Declare an array to hold the bytes of the bitmap. bytes = bmpData.Stride * bmp.Height; stride = bmpData.Stride; byte *ptr1 = (byte *)bmpData.Scan0; rgbValues = new byte[bytes]; // Copy the RGB values into the array. Marshal.Copy(pNative, rgbValues, 0, bytes); for (int column = 0; column < bmpData.Height; column++) { for (int row = 0; row < bmpData.Width; row++) { if (column > 3 && row > 3) { int r1 = 0, g1 = 0, b1 = 0; for (var l = 0; l < kernelWidth; l++) { for (var m = 0; m < kernelHeight; m++) { r1 += (int)(rgbValues[(this.Bound(column + m, bmpData.Height) * stride) + (this.Bound(row + l, bmpData.Width) * 3)] * kernel[l, m]); g1 += (int)(rgbValues[(this.Bound(column + m, bmpData.Height) * stride) + (this.Bound(row + l, bmpData.Width) * 3) + 1] * kernel[l, m]); b1 += (int)(rgbValues[(this.Bound(column + m, bmpData.Height) * stride) + (this.Bound(row + l, bmpData.Width) * 3) + 2] * kernel[l, m]); } } ptr1[(row * 3) + (column * stride)] = (byte)Math.Max(0, r1); ptr1[(row * 3) + (column * stride) + 1] = (byte)Math.Max(0, g1); ptr1[(row * 3) + (column * stride) + 2] = (byte)Math.Max(0, b1); } else { ptr1[(row * 3) + (column * stride)] = 0; ptr1[(row * 3) + (column * stride) + 1] = 0; ptr1[(row * 3) + (column * stride) + 2] = 0; } } } } bmp.UnlockBits(bmpData); } if (context.Raw) { Marshal.Copy(pNative, store, 0, bytes); } else { using (var ms = new MemoryStream()) { bmp.Save(ms, ImageFormat.Jpeg); Array.Copy(ms.ToArray(), 0, store, 0, ms.Length); } } bmp.Dispose(); }
/// <summary> /// Allows manipulating of the image frame. /// </summary> /// <param name="context">A delegate to the manipulation you wish to carry out.</param> /// <param name="imageContext">Metadata for the image frame.</param> public void Manipulate(Action <IFrameProcessingContext> context, IImageContext imageContext) { this.OnManipulate = context; this.ImageContext = imageContext; }
private void InitBitmapData(IImageContext imageContext, BitmapData bmpData) { var pNative = bmpData.Scan0; Marshal.Copy(imageContext.Data, 0, pNative, imageContext.Data.Length); }
/// <summary> /// Apply a convolution based on the kernel passed in. /// </summary> /// <param name="kernel">The kernel.</param> /// <param name="kernelWidth">The kernel's width.</param> /// <param name="kernelHeight">The kernel's height.</param> /// <param name="context">An image context providing additional metadata on the data passed in.</param> public void ApplyConvolution(double[,] kernel, int kernelWidth, int kernelHeight, IImageContext context) { BitmapData bmpData = null; IntPtr pNative = IntPtr.Zero; int bytes; byte[] store = null; using (var ms = new MemoryStream(context.Data)) using (var bmp = this.LoadBitmap(context, ms)) { bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); if (context.Raw) { this.InitBitmapData(context, bmpData); } pNative = bmpData.Scan0; // Split image into 4 quadrants and process individually. var quadA = new Rectangle(0, 0, bmpData.Width / 2, bmpData.Height / 2); var quadB = new Rectangle(bmpData.Width / 2, 0, bmpData.Width / 2, bmpData.Height / 2); var quadC = new Rectangle(0, bmpData.Height / 2, bmpData.Width / 2, bmpData.Height / 2); var quadD = new Rectangle(bmpData.Width / 2, bmpData.Height / 2, bmpData.Width / 2, bmpData.Height / 2); bytes = bmpData.Stride * bmp.Height; var rgbValues = new byte[bytes]; // Copy the RGB values into the array. Marshal.Copy(pNative, rgbValues, 0, bytes); var bpp = Image.GetPixelFormatSize(bmp.PixelFormat) / 8; var t1 = Task.Run(() => { this.ProcessQuadrant(quadA, bmp, bmpData, rgbValues, kernel, kernelWidth, kernelHeight, bpp); }); var t2 = Task.Run(() => { this.ProcessQuadrant(quadB, bmp, bmpData, rgbValues, kernel, kernelWidth, kernelHeight, bpp); }); var t3 = Task.Run(() => { this.ProcessQuadrant(quadC, bmp, bmpData, rgbValues, kernel, kernelWidth, kernelHeight, bpp); }); var t4 = Task.Run(() => { this.ProcessQuadrant(quadD, bmp, bmpData, rgbValues, kernel, kernelWidth, kernelHeight, bpp); }); Task.WaitAll(t1, t2, t3, t4); if (context.Raw) { store = new byte[bytes]; Marshal.Copy(pNative, store, 0, bytes); } bmp.UnlockBits(bmpData); if (!context.Raw) { using (var ms2 = new MemoryStream()) { bmp.Save(ms2, context.StoreFormat); store = new byte[ms2.Length]; Array.Copy(ms2.ToArray(), 0, store, 0, ms2.Length); } } } context.Data = store; }
public ImageLogic() { _imageContext = ContextFactory.CreateImageContext(); _offeredServiceContext = ContextFactory.CreateOfferedServiceContext(); }
public ImageService(IImageContext ic, IMapper im) { this.imageContext = ic; this.mapper = im; }
/// <inheritdoc /> public void Apply(IImageContext context) { this.Convolute(context.Data, this.Kernel, _kernelWidth, _kernelHeight, context); }
/// <summary> /// Creates a new instance of <see cref="FrameAnalyser"/>. /// </summary> /// <param name="imageContext">The image metadata.</param> protected FrameAnalyser(IImageContext imageContext) { this.WorkingData = new List <byte>(); this.ImageContext = imageContext; }
public UnitOfWork(IImageContext context) { this.context = context; }
/// <summary> /// Allows manipulating of the image frame. /// </summary> /// <param name="context">A delegate to the manipulation you wish to carry out.</param> /// <param name="imageContext">Metadata for the image frame.</param> public void Manipulate(Action <IFrameProcessingContext> context, IImageContext imageContext) { _manipulate = context; _imageContext = imageContext; }
/// <summary> /// Creates a new instance of <see cref="MotionVectorAnalyser"/>. /// </summary> /// <param name="imageContext">The image metadata.</param> public MotionVectorAnalyser(IImageContext imageContext) : base(imageContext) { }
/// <summary> /// Call to enable motion detection. /// </summary> /// <param name="handler">The motion capture handler.</param> /// <param name="config">The motion configuration object.</param> /// <param name="onDetect">The callback when motion is detected.</param> /// <param name="imageContext">The image metadata.</param> /// <returns>The camera instance.</returns> public MMALCamera WithMotionDetection(IMotionCaptureHandler handler, MotionConfig config, Action onDetect, IImageContext imageContext) { MMALCameraConfig.InlineMotionVectors = true; handler.DetectMotion(config, onDetect, imageContext); return(this); }
/// <inheritdoc /> public void Apply(IImageContext context) { this.ApplyConvolution(_kernel, KernelWidth, KernelHeight, context); }
public void Apply(IImageContext context) { throw new NotImplementedException(); }