override public void Process()
        {
            if (!Enabled)
            {
                return;
            }

            FInput.Image.GetImage(TColorFormat.L8, FGrayscale);

            Size SizeNow = BoardSize;

            PointF[] points = CameraCalibration.FindChessboardCorners(FGrayscale.GetImage() as Image <Gray, byte>, SizeNow, CALIB_CB_TYPE.ADAPTIVE_THRESH);

            lock (FFoundPointsLock)
            {
                if (points == null)
                {
                    FFoundPoints.SliceCount = 0;
                }
                else
                {
                    FFoundPoints.SliceCount = SizeNow.Width * SizeNow.Height;
                    for (int i = 0; i < FFoundPoints.SliceCount; i++)
                    {
                        FFoundPoints[i] = new Vector2D(points[i].X, points[i].Y);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 void UpdateImage()
 {
     if (!FInput.Allocated)
     {
         return;
     }
     FInput.GetImage(FImage);
     FImageBox.Image = FImage.GetImage();
 }
 public void GetImage(CVImage target)
 {
     LockForReading();
     try
     {
         FFrontBuffer.GetImage(target);
     }
     finally
     {
         ReleaseForReading();
     }
 }
Ejemplo n.º 4
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.LK(p, c, FWindowSize, vx, vy);

            CopyToRgb();
            FOutput.Send();
        }
Ejemplo n.º 5
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.º 6
0
        override public void Process()
        {
            if (!Enabled)
            {
                return;
            }

            FInput.Image.GetImage(TColorFormat.L8, FGrayscale);
            Image <Gray, byte> img = FGrayscale.GetImage() as Image <Gray, byte>;

            if (img != null)
            {
                //Seriously EmguCV? what the f**k is up with your syntax?
                //both ways of skinning this cat involve f*****g a moose

                List <ContourTempData> results = new List <ContourTempData>();
                ContourTempData        c;

                try
                {
                    CHAIN_APPROX_METHOD cam;

                    switch (Approximation)
                    {
                    case ContourApproximation.None:
                        cam = CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE;
                        break;

                    case ContourApproximation.TehChinKCOS:
                        cam = CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_TC89_KCOS;
                        break;

                    case ContourApproximation.TehChinL1:
                        cam = CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_TC89_L1;
                        break;

                    case ContourApproximation.LinkRuns:
                        cam = CHAIN_APPROX_METHOD.CV_LINK_RUNS;
                        break;

                    case ContourApproximation.Simple:
                    case ContourApproximation.Poly:
                    default:
                        cam = CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE;
                        break;
                    }

                    Contour <Point> contour = img.FindContours(cam, RETR_TYPE.CV_RETR_LIST);

                    for (; contour != null; contour = contour.HNext)
                    {
                        c        = new ContourTempData();
                        c.Area   = contour.Area;
                        c.Bounds = contour.BoundingRectangle;

                        if (Approximation == ContourApproximation.Poly)
                        {
                            c.Perimeter = new ContourPerimeter(contour.ApproxPoly(FPolyAccuracy), img.Width, img.Height);
                        }
                        else
                        {
                            c.Perimeter = new ContourPerimeter(contour, img.Width, img.Height);
                        }

                        results.Add(c);
                    }


                    lock (FLockResults)
                        FStatus = "OK";
                }
                catch (Exception e)
                {
                    lock (FLockResults)
                        FStatus = e.Message;
                }

                lock (FLockResults)
                {
                    FBoundingBox.SliceCount = results.Count;
                    FArea.SliceCount        = results.Count;
                    FPerimeter.SliceCount   = results.Count;

                    for (int i = 0; i < results.Count; i++)
                    {
                        c = results[i];

                        FBoundingBox[i] = new Vector4D(((double)c.Bounds.X / (double)img.Width) * 2.0d - 1.0d,
                                                       1.0d - ((double)c.Bounds.Y / (double)img.Height) * 2.0d,
                                                       (double)c.Bounds.Width * 2.0d / (double)img.Width,
                                                       (double)c.Bounds.Height * 2.0d / (double)img.Height);

                        FArea[i] = (double)c.Area * (4.0d / (double)(img.Width * img.Height));

                        FPerimeter[i] = c.Perimeter;
                    }
                }
            }
        }
		void FContext_Update(object sender, EventArgs e)
		{
			FContext.Update -= OnUpdate;

			var colorWidth = FContext.FSensor.ColorStream.FrameWidth;
			var colorHeight = FContext.FSensor.ColorStream.FrameHeight;
			var depthWidth = FContext.FSensor.DepthStream.FrameWidth;
			var depthHeight = FContext.FSensor.DepthStream.FrameHeight;

			//find board positions in world coordinates

			//get mapped color image
			CVImage Image = new CVImage();
			//it's mapped so it's in depth coords
			Image.Initialise(new System.Drawing.Size(depthWidth, depthHeight), TColorFormat.RGBA8);
			lock (FContext.ColorLock)
			{
				Image.SetPixels(FContext.ColorData);
			}

			//create grayscale
			CVImage Luminance = new CVImage();
			Luminance.Initialise(Image.Size, TColorFormat.L8);
			Image.GetImage(TColorFormat.L8, Luminance);

			//find corners in rgb
			var pointsInRGB = CameraCalibration.FindChessboardCorners(Luminance.GetImage() as Image<Gray, byte>, new Size(FInBoardX[0], FInBoardY[0]), CALIB_CB_TYPE.ADAPTIVE_THRESH);

			//destroy images
			Image.Dispose();
			Luminance.Dispose();

			//find corners in world
			lock (FContext.DepthLock)
			{
				FContext.FWorldLock.AcquireReaderLock(500);
				try
				{
					var world = FContext.WorldData;
					lock (FDepthCorners)
					{
						FDepthCorners.Clear();
						lock (FWorldCorners)
						{
							FWorldCorners.Clear();
							foreach (var rgbCorner in pointsInRGB)
							{
								int index = (int)rgbCorner.X + (int)rgbCorner.Y * depthWidth;

								FDepthCorners.Add(new Vector3D(
										rgbCorner.X,
										rgbCorner.Y,
										(double) FContext.DepthData[index] / 1000.0
									));
								FWorldCorners.Add(new Vector3D(
										world[index * 4],
										world[index * 4 + 1],
										world[index * 4 + 2]
									));
							}
						}
					}
					FCornersDirty = true;
				}
				catch
				{

				}
				finally
				{
					FContext.FWorldLock.ReleaseReaderLock();
				}
			}
		}