Example #1
0
		public void GetImage(TColorFormat format, CVImage target)
		{
			if (format == this.NativeFormat)
				ImageUtils.CopyImage(this, target);
			else
				ImageUtils.CopyImageConverted(this, target);
		}
        /// <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 CopyImageConverted(CVImage source, CVImage target)
        {
            if (target.Size != source.Size)
            {
                target.Initialise(source.Size, target.NativeFormat);
            }

            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
                }
            }
        }
Example #4
0
		/// <summary>
		/// Copy CVImage into target CVImage 
		/// </summary>
		/// <param name="target"></param>
		public void GetImage(CVImage target)
		{
            if (target.NativeFormat == TColorFormat.UnInitialised)
            {
                target.Initialise(this.ImageAttributes);
            }

            GetImage(target.ImageAttributes.ColorFormat, target);
		}
Example #5
0
        /// <summary>
        /// Copy CVImage into target CVImage
        /// </summary>
        /// <param name="target"></param>
        public void GetImage(CVImage target)
        {
            if (target.NativeFormat == TColorFormat.UnInitialised)
            {
                target.Initialise(this.ImageAttributes);
            }

            GetImage(target.ImageAttributes.ColorFormat, target);
        }
Example #6
0
 public void GetImage(TColorFormat format, CVImage target)
 {
     if (format == this.NativeFormat)
     {
         ImageUtils.CopyImage(this, target);
     }
     else
     {
         ImageUtils.CopyImageConverted(this, target);
     }
 }
 public void GetImage(CVImage target)
 {
     LockForReading();
     try
     {
         FFrontBuffer.GetImage(target);
     }
     finally
     {
         ReleaseForReading();
     }
 }
        public static unsafe Spread <double> GetPixelAsDoubles(CVImage source, uint column, uint row)
        {
            TColorFormat format       = source.ImageAttributes.ColorFormat;
            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>
        /// 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();
        }
        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);
        }
Example #11
0
		public override void Process()
		{
			CVImage swap = FPrevious;
			FPrevious = FCurrent;
			FCurrent = swap;

			FInput.Image.GetImage(TColorFormat.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();

		}
Example #12
0
        public bool SetImage(CVImage source)
        {
            if (source == null)
            {
                return(false);
            }

            if (source.NativeFormat == TColorFormat.UnInitialised)
            {
                return(false);
            }

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

            ImageUtils.CopyImage(source, this);
            this.Timestamp = source.Timestamp;

            return(Reinitialise);
        }
		public override void Process()
		{
			CVImage swap = FPrevious;
			FPrevious = FCurrent;
			FCurrent = swap;

			FInput.Image.GetImage(TColorFormat.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>
		/// 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();
		}
        /// <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 CopyImage(byte[] source, CVImage target)
		{
			Marshal.Copy(source, 0, target.Data, (int) target.ImageAttributes.BytesPerFrame);
		}
		public static void CopyImage(IntPtr source, CVImage target)
		{
			CopyMemory(target.Data, source, target.ImageAttributes.BytesPerFrame);
		}
		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 static void FlipImageHorizontal(CVImage image)
 {
     FlipImageHorizontal(image, image);
 }
		public static unsafe Spread<double> GetPixelAsDoubles(CVImage source, uint column, uint row)
		{
			TColorFormat format = source.ImageAttributes.ColorFormat;
			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 FlipImageHorizontal(CVImage source, CVImage target)
		{
			CvInvoke.cvFlip(source.CvMat, target.CvMat, FLIP.HORIZONTAL);
		}
		public static void FlipImageVertical(CVImage source, CVImage target)
		{
			CvInvoke.cvFlip(source.CvMat, target.CvMat, FLIP.VERTICAL);
		}
 public static void FlipImageVertical(CVImage image)
 {
     FlipImageVertical(image, image);
 }
Example #24
0
		public void GetImage(CVImage target)
		{
			FLink.GetImage(target);
		}
		public void GetImage(CVImage target)
		{
			LockForReading();
			try
			{
				FFrontBuffer.GetImage(target);
			}
			finally
			{
				ReleaseForReading();
			}
		}
 public void GetImage(CVImage target)
 {
     FLink.GetImage(target);
 }
		/// <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();
		}
Example #28
0
		public bool SetImage(CVImage source)
		{
			if (source == null)
				return false;

			if (source.NativeFormat == TColorFormat.UnInitialised)
				return false;

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

			ImageUtils.CopyImage(source, this);
			this.Timestamp = source.Timestamp;

			return Reinitialise;
		}
 public static void FlipImageVertical(CVImage source, CVImage target)
 {
     CvInvoke.cvFlip(source.CvMat, target.CvMat, FLIP.VERTICAL);
 }
		public static void CopyImageConverted(CVImage source, CVImage target)
		{
            if (target.Size != source.Size)
            {
                target.Initialise(source.Size, target.NativeFormat);
            }

			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
				}
			}

		}
		public static void FlipImageVertical(CVImage image)
		{
			FlipImageVertical(image, image);
		}
 public static void CopyImage(byte[] source, CVImage target)
 {
     Marshal.Copy(source, 0, target.Data, (int)target.ImageAttributes.BytesPerFrame);
 }
		public static void FlipImageHorizontal(CVImage image)
		{
			FlipImageHorizontal(image, image);
		}
 public static void CopyImage(IntPtr source, CVImage target)
 {
     CopyMemory(target.Data, source, target.ImageAttributes.BytesPerFrame);
 }
		/// <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);
		}
Example #36
0
		/// <summary>
		/// Sends an image to the link, ignoring the internal buffer
		/// </summary>
		public void Send(CVImage image)
		{
			Link.Send(image);
		}
 /// <summary>
 /// Sends an image to the link, ignoring the internal buffer
 /// </summary>
 public void Send(CVImage image)
 {
     Link.Send(image);
 }
 public static void FlipImageHorizontal(CVImage source, CVImage target)
 {
     CvInvoke.cvFlip(source.CvMat, target.CvMat, FLIP.HORIZONTAL);
 }