Ejemplo n.º 1
0
		public void GetImage(TColorFormat format, CVImage target)
		{
			if (format == this.NativeFormat)
				ImageUtils.CopyImage(this, target);
			else
				ImageUtils.CopyImageConverted(this, target);
		}
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        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
                }
            }
        }
Ejemplo n.º 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);
		}
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 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();

		}
Ejemplo n.º 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();

		}
Ejemplo n.º 14
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();
		}
        /// <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);
		}
Ejemplo n.º 19
0
 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);
		}
Ejemplo n.º 23
0
 public static void FlipImageVertical(CVImage image)
 {
     FlipImageVertical(image, image);
 }
Ejemplo n.º 24
0
		public void GetImage(CVImage target)
		{
			FLink.GetImage(target);
		}
Ejemplo n.º 25
0
		public void GetImage(CVImage target)
		{
			LockForReading();
			try
			{
				FFrontBuffer.GetImage(target);
			}
			finally
			{
				ReleaseForReading();
			}
		}
Ejemplo n.º 26
0
 public void GetImage(CVImage target)
 {
     FLink.GetImage(target);
 }
Ejemplo n.º 27
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();
		}
Ejemplo n.º 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;
		}
Ejemplo n.º 29
0
 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);
		}
Ejemplo n.º 32
0
 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);
		}
Ejemplo n.º 34
0
 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);
		}
Ejemplo n.º 36
0
		/// <summary>
		/// Sends an image to the link, ignoring the internal buffer
		/// </summary>
		public void Send(CVImage image)
		{
			Link.Send(image);
		}
Ejemplo n.º 37
0
 /// <summary>
 /// Sends an image to the link, ignoring the internal buffer
 /// </summary>
 public void Send(CVImage image)
 {
     Link.Send(image);
 }
Ejemplo n.º 38
0
 public static void FlipImageHorizontal(CVImage source, CVImage target)
 {
     CvInvoke.cvFlip(source.CvMat, target.CvMat, FLIP.HORIZONTAL);
 }