Пример #1
0
        /// <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));
        }
Пример #2
0
		public void GetImage(TColourFormat format, CVImage target)
		{
			if (format == this.NativeFormat)
				ImageUtils.CopyImage(this, target);
			else
				ImageUtils.CopyImageConverted(this, target);
		}
Пример #3
0
 public void GetImage(TColourFormat format, CVImage target)
 {
     if (format == this.NativeFormat)
     {
         ImageUtils.CopyImage(this, target);
     }
     else
     {
         ImageUtils.CopyImageConverted(this, target);
     }
 }
Пример #4
0
		public bool SetImage(CVImage source)
		{
			if (source == null)
				return false;

			bool Reinitialise = Initialise(source.Size, source.NativeFormat);

			ImageUtils.CopyImage(source, this);

			return Reinitialise;
		}
Пример #5
0
 public void GetImage(CVImage target)
 {
     LockForReading();
     try
     {
         FFrontBuffer.GetImage(target);
     }
     finally
     {
         ReleaseForReading();
     }
 }
		public void GetImage(CVImage target)
		{
			LockForReading();
			try
			{
				FFrontBuffer.GetImage(target);
			}
			finally
			{
				ReleaseForReading();
			}
		}
Пример #7
0
        public bool SetImage(CVImage source)
        {
            if (source == null)
            {
                return(false);
            }

            bool Reinitialise = Initialise(source.Size, source.NativeFormat);

            ImageUtils.CopyImage(source, this);

            return(Reinitialise);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        /// <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);
		}
Пример #13
0
        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
            }
        }
Пример #14
0
        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();
        }
Пример #15
0
        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();
		}
Пример #17
0
        /// <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();
        }
Пример #18
0
        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();
		}
Пример #20
0
		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
			}
		}
Пример #21
0
 public void GetImage(CVImage target)
 {
     FLink.GetImage(target);
 }
Пример #22
0
 public static void CopyImage(IntPtr rawData, CVImage target)
 {
     CopyMemory(target.Data, rawData, target.ImageAttributes.BytesPerFrame);
 }
Пример #23
0
 /// <summary>
 /// Sends an image to the link, ignoring the internal buffer
 /// </summary>
 public void Send(CVImage image)
 {
     Link.Send(image);
 }
Пример #24
0
		/// <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);
		}
Пример #25
0
		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
				}
			}

		}
Пример #26
0
		public static void CopyImage(IntPtr rawData, CVImage target)
		{
			CopyMemory(target.Data, rawData, target.ImageAttributes.BytesPerFrame);
		}
Пример #27
0
		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);
		}
Пример #28
0
		public void GetImage(CVImage target)
		{
			FLink.GetImage(target);
		}
Пример #29
0
 public void GetImage(CVImage target)
 {
     GetImage(target.ImageAttributes.ColourFormat, target);
 }
Пример #30
0
		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;
		}
Пример #31
0
		/// <summary>
		/// Sends an image to the link, ignoring the internal buffer
		/// </summary>
		public void Send(CVImage image)
		{
			Link.SetImage(image);
		}
Пример #32
0
		public void GetImage(CVImage target)
		{
			GetImage(target.ImageAttributes.ColourFormat, target);
		}