/// <summary> /// Get a pixel's channels as doubles /// </summary> /// <param name="source">Image to lookup</param> /// <param name="row">0.0 to 1.0</param> /// <param name="column">0.0 to 1.0</param> /// <returns></returns> public static Spread <double> GetPixelAsDoubles(CVImage source, double x, double y) { uint row = (uint)(x * (double)source.Width); uint col = (uint)(y * (double)source.Height); return(GetPixelAsDoubles(source, row, col)); }
public void GetImage(TColourFormat format, CVImage target) { if (format == this.NativeFormat) ImageUtils.CopyImage(this, target); else ImageUtils.CopyImageConverted(this, target); }
public void GetImage(TColourFormat format, CVImage target) { if (format == this.NativeFormat) { ImageUtils.CopyImage(this, target); } else { ImageUtils.CopyImageConverted(this, target); } }
public bool SetImage(CVImage source) { if (source == null) return false; bool Reinitialise = Initialise(source.Size, source.NativeFormat); ImageUtils.CopyImage(source, this); return Reinitialise; }
public void GetImage(CVImage target) { LockForReading(); try { FFrontBuffer.GetImage(target); } finally { ReleaseForReading(); } }
public bool SetImage(CVImage source) { if (source == null) { return(false); } bool Reinitialise = Initialise(source.Size, source.NativeFormat); ImageUtils.CopyImage(source, this); return(Reinitialise); }
public static unsafe Spread <double> GetPixelAsDoubles(CVImage source, uint column, uint row) { TColourFormat format = source.ImageAttributes.ColourFormat; uint channelCount = (uint)ChannelCount(format); if (channelCount == 0) { return(new Spread <double>(0)); } uint width = (uint)source.Width; uint height = (uint)source.Height; Spread <double> output = new Spread <double>((int)channelCount); row %= height; column %= width; switch (ChannelFormat(format)) { case TChannelFormat.Byte: { byte *d = (byte *)source.Data.ToPointer(); for (uint channel = 0; channel < channelCount; channel++) { output[(int)channel] = (double)d[(column + row * width) * channelCount + channel]; } break; } case TChannelFormat.Float: { float *d = (float *)source.Data.ToPointer(); for (uint channel = 0; channel < channelCount; channel++) { output[(int)channel] = (double)d[(column + row * width) * channelCount + channel]; } break; } case TChannelFormat.UShort: { ushort *d = (ushort *)source.Data.ToPointer(); for (uint channel = 0; channel < channelCount; channel++) { output[(int)channel] = (double)d[(column + row * width) * channelCount + channel]; } break; } } return(output); }
public static void CopyImage(IImage source, CVImage target) { if (source.Size != target.Size) { throw (new Exception("Can't copy between these 2 images, they differ in dimensions")); } if (GetFormat(source) != target.NativeFormat) { throw (new Exception("Can't copy between these 2 images, they differ in pixel colour format")); } CopyImage(source.Ptr, target.CvMat, target.ImageAttributes.BytesPerFrame); }
/// <summary> /// Copy the input image into the back buffer /// </summary> /// <param name="source">Input image</param> public void Send(CVImage source) { bool Reinitialise; lock (FBackLock) Reinitialise = FBackBuffer.SetImage(source); if (Reinitialise) { InitialiseFrontFromBack(); } Swap(); }
/// <summary> /// Swap the front buffer and back buffer /// </summary> public void Swap() { lock (FBackLock) { FFrontLock.AcquireWriterLock(LockTimeout); try { CVImage swap = FBackBuffer; FBackBuffer = FFrontBuffer; FFrontBuffer = swap; } finally { FFrontLock.ReleaseWriterLock(); } } }
public Texture CreateTexture(Device device) { if (Initialised && FImageInput.Allocated) { FNeedsConversion = CVImageUtils.NeedsConversion(FImageInput.ImageAttributes.ColourFormat, out FConvertedFormat); if (FNeedsConversion) { FBufferConverted = new CVImage(); FBufferConverted.Initialise(FImageInput.ImageAttributes.Size, FConvertedFormat); return CVImageUtils.CreateTexture(FBufferConverted.ImageAttributes, device); } else return CVImageUtils.CreateTexture(FImageInput.ImageAttributes, device); } else return TextureUtils.CreateTexture(device, 1, 1); }
public static void CopyImageConverted(CVImage source, CVImage target) { COLOR_CONVERSION route = ConvertRoute(source.NativeFormat, target.NativeFormat); if (route == COLOR_CONVERSION.CV_COLORCVT_MAX) { throw(new Exception("Unsupported conversion")); } try { CvInvoke.cvCvtColor(source.CvMat, target.CvMat, route); } catch { //CV likes to throw here sometimes, but the next frame it's fine } }
public override void Process() { CVImage swap = FPrevious; FPrevious = FCurrent; FCurrent = swap; FInput.Image.GetImage(TColourFormat.L8, FCurrent); Image <Gray, byte> p = FPrevious.GetImage() as Image <Gray, byte>; Image <Gray, byte> c = FCurrent.GetImage() as Image <Gray, byte>; Image <Gray, float> vx = FVelocityX.GetImage() as Image <Gray, float>; Image <Gray, float> vy = FVelocityY.GetImage() as Image <Gray, float>; OpticalFlow.HS(p, c, UsePrevious, vx, vy, FLambda, new MCvTermCriteria(FIterations)); CopyToRgb(); FOutput.Send(); }
public override void Process() { CVImage swap = FPrevious; FPrevious = FCurrent; FCurrent = swap; FInput.Image.GetImage(TColourFormat.L8, FCurrent); Image <Gray, byte> p = FPrevious.GetImage() as Image <Gray, byte>; Image <Gray, byte> c = FCurrent.GetImage() as Image <Gray, byte>; Image <Gray, float> vx = FVelocityX.GetImage() as Image <Gray, float>; Image <Gray, float> vy = FVelocityY.GetImage() as Image <Gray, float>; OpticalFlow.LK(p, c, FWindowSize, vx, vy); CopyToRgb(); FOutput.Send(); }
/// <summary> /// Copy the input image into the back buffer /// </summary> /// <param name="image">Input image</param> public void SetImage(CVImage image) { bool Reinitialise; lock (FBackLock) Reinitialise = FBackBuffer.SetImage(image); FAllocated = true; OnImageUpdate(); if (Reinitialise) { lock (FAttributesLock) FImageAttributes = image.ImageAttributes.Clone() as CVImageAttributes; OnImageAttributesUpdate(FImageAttributes); } Swap(); }
/// <summary> /// Swap the front buffer and back buffer /// </summary> public void Swap() { FAllocated = true; lock (FBackLock) { FFrontLock.AcquireWriterLock(LockTimeout); try { CVImage swap = FBackBuffer; FBackBuffer = FFrontBuffer; FFrontBuffer = swap; } finally { FFrontLock.ReleaseWriterLock(); } } OnImageUpdate(); }
public static void CopyImageConverted(CVImage source, CVImage target) { //CvInvoke.cvConvert(source.CvMat, target.CvMat); //return; COLOR_CONVERSION route = ConvertRoute(source.NativeFormat, target.NativeFormat); if (route == COLOR_CONVERSION.CV_COLORCVT_MAX) { CvInvoke.cvConvert(source.CvMat, target.CvMat); } else { try { CvInvoke.cvCvtColor(source.CvMat, target.CvMat, route); } catch { //CV likes to throw here sometimes, but the next frame it's fine } } }
/// <summary> /// Copy the input image into the back buffer /// </summary> /// <param name="source">Input image</param> public void SetImage(CVImage source) { bool Reinitialise; lock (FBackLock) Reinitialise = FBackBuffer.SetImage(source); if (Reinitialise) InitialiseFrontFromBack(); Swap(); }
public static void CopyImageConverted(CVImage source, CVImage target) { COLOR_CONVERSION route = ConvertRoute(source.NativeFormat, target.NativeFormat); if (route==COLOR_CONVERSION.CV_COLORCVT_MAX) throw(new Exception("Unsupported conversion")); try { CvInvoke.cvCvtColor(source.CvMat, target.CvMat, route); } catch { //CV likes to throw here sometimes, but the next frame it's fine } }
public void GetImage(CVImage target) { FLink.GetImage(target); }
public static void CopyImage(IntPtr rawData, CVImage target) { CopyMemory(target.Data, rawData, target.ImageAttributes.BytesPerFrame); }
/// <summary> /// Sends an image to the link, ignoring the internal buffer /// </summary> public void Send(CVImage image) { Link.Send(image); }
/// <summary> /// Get a pixel's channels as doubles /// </summary> /// <param name="source">Image to lookup</param> /// <param name="row">0.0 to 1.0</param> /// <param name="column">0.0 to 1.0</param> /// <returns></returns> public static Spread<double> GetPixelAsDoubles(CVImage source, double x, double y) { uint row = (uint) (x * (double)source.Width); uint col = (uint) (y * (double)source.Height); return GetPixelAsDoubles(source, row, col); }
public static void CopyImage(IImage source, CVImage target) { if (source.Size != target.Size) throw (new Exception("Can't copy between these 2 images, they differ in dimensions")); if (GetFormat(source) != target.NativeFormat) throw (new Exception("Can't copy between these 2 images, they differ in pixel colour format")); CopyImage(source.Ptr, target.CvMat, target.ImageAttributes.BytesPerFrame); }
public void GetImage(CVImage target) { GetImage(target.ImageAttributes.ColourFormat, target); }
public static unsafe Spread<double> GetPixelAsDoubles(CVImage source, uint column, uint row) { TColourFormat format = source.ImageAttributes.ColourFormat; uint channelCount = (uint)ChannelCount(format); if (channelCount == 0) { return new Spread<double>(0); } uint width = (uint)source.Width; uint height = (uint)source.Height; Spread<double> output = new Spread<double>((int)channelCount); row %= height; column %= width; switch (ChannelFormat(format)) { case TChannelFormat.Byte: { byte* d = (byte*)source.Data.ToPointer(); for (uint channel = 0; channel < channelCount; channel++) { output[(int)channel] = (double)d[(column + row * width) * channelCount + channel]; } break; } case TChannelFormat.Float: { float* d = (float*)source.Data.ToPointer(); for (uint channel = 0; channel < channelCount; channel++) { output[(int)channel] = (double)d[(column + row * width) * channelCount + channel]; } break; } case TChannelFormat.UShort: { ushort* d = (ushort*)source.Data.ToPointer(); for (uint channel = 0; channel < channelCount; channel++) { output[(int)channel] = (double)d[(column + row * width) * channelCount + channel]; } break; } } return output; }
/// <summary> /// Sends an image to the link, ignoring the internal buffer /// </summary> public void Send(CVImage image) { Link.SetImage(image); }