HI. I am trying to create simple touch game using EmguCV.Should I use optical flow to determine for interaction between images on screen and with my hand ,if changes of points somewhere on screen more than 100 where the image, it means my hand is over image? But how can I track this new points? I can draw on screen here the previous points and new points but
It shows on my head more points then my hand and I can not track my hands movements.
void Optical_Flow_Worker(object sender, EventArgs e)
{
{
Input_Capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES, ActualFrameNumber);
ActualFrame = Input_Capture.QueryFrame();
ActualGrayFrame = ActualFrame.Convert<Gray, Byte>();
NextFrame = Input_Capture.QueryFrame();
NextGrayFrame = NextFrame.Convert<Gray, Byte>();
ActualFeature = ActualGrayFrame.GoodFeaturesToTrack(500, 0.01d, 0.01, 5);
ActualGrayFrame.FindCornerSubPix(ActualFeature, new System.Drawing.Size(10, 10), new System.Drawing.Size(-1, -1), new MCvTermCriteria(20, 0.3d));
OpticalFlow.PyrLK(ActualGrayFrame, NextGrayFrame, ActualFeature[0], new System.Drawing.Size(10, 10), 3, new MCvTermCriteria(20, 0.03d), out NextFeature, out Status, out TrackError);
OpticalFlowFrame = new Image<Bgr, Byte>(ActualFrame.Width, ActualFrame.Height);
OpticalFlowFrame = NextFrame.Copy();
for (int i = 0; i < ActualFeature[0].Length; i++)
DrawFlowVectors(i);
ActualFrameNumber++;
pictureBox1.Image = ActualFrame.Resize(320, 400).ToBitmap() ;
pictureBox3.Image = OpticalFlowFrame.Resize(320, 400).ToBitmap();
}
}
private void DrawFlowVectors(int i)
{
System.Drawing.Point p = new Point();
System.Drawing.Point q = new Point();
p.X = (int)ActualFeature[0][i].X;
p.Y = (int)ActualFeature[0][i].Y;
q.X = (int)NextFeature[i].X;
q.Y = (int)NextFeature[i].Y;
p.X = (int)(q.X + 6 * Math.Cos(angle + Math.PI / 4));
p.Y = (int)(q.Y + 6 * Math.Sin(angle + Math.PI / 4));
p.X = (int)(q.X + 6 * Math.Cos(angle - Math.PI / 4));
p.Y = (int)(q.Y + 6 * Math.Sin(angle - Math.PI / 4));
OpticalFlowFrame.Draw(new Rectangle(q.X,q.Y,1,1), new Bgr(Color.Red), 1);
OpticalFlowFrame.Draw(new Rectangle(p.X, p.Y, 1, 1), new Bgr(Color.Blue), 1);
}