im having a little problem in my project.
i have a main form witu buttons , from this form im starting my game.
when im starting my game it should automaticlly start capturring,
but it doesnt.
only after i press twice on the pause button its start.
if im doing twice pauses in the constractor of the form it doesnt help.
i know it not the right solution but i just checked it.
this is the camera class with the pause code:
public class C_Camera
{
// public Timer timer;
public Capture capWebCam = null;
public bool binCapturingInProgress = false;
public Image<Bgr, byte> imgOriginal;
public Image<Gray, byte> imgProcessed;
public ImageBox imageBox1 = new ImageBox();
public TextBox textBox1;
public List<PointF> centerList;
CircleF[] circles;
public void newCapture(bool b, List<PointF> centers)
{
centerList = centers;
binCapturingInProgress = b;
try
{
capWebCam = new Capture();
}
catch (NullReferenceException except)
{
MessageBox.Show(except.Message);
return;
}
Application.Idle += processFrameAndUpdateGUI;//add process image function to the applicationlist in tasks
binCapturingInProgress = true;
/* timer = new Timer();
timer.Interval = Convert.ToInt32(TimeSpan.FromMilliseconds(1000 / 60).TotalMilliseconds);
timer.Tick += processFrameAndUpdateGUI;
timer.Start();
*/}
public void closeCapture()
{
if (capWebCam != null)
capWebCam.Dispose();
}
public void processFrameAndUpdateGUI(object sender, EventArgs arg)
{
imgOriginal = capWebCam.QueryFrame();
if (imgOriginal == null)
{
return;
}
//imgProcessed = imgOriginal.InRange(new Bgr(0, 80, 0)/*min filter*/, new Bgr(70, 256, 70));
imgProcessed = imgOriginal.InRange(new Bgr(0, 0, 140)/*min filter*/, new Bgr(90, 90, 256));
//imgProcessed = imgOriginal.InRange(new Bgr(0, 0, 175)/*min filter*/, new Bgr(100, 100, 256));
imgProcessed = imgProcessed.SmoothGaussian(9);//9
circles = imgProcessed.HoughCircles(new Gray(100), //canny threshhold
new Gray(50), //accumolator threshold
2,//size of image
imgProcessed.Height / 4, //min size in pixels between centers of detected circles
15, //min radios
43)[0];//max radios and get circles from first channel
foreach (CircleF circle in circles)
{
centerList.Add(circle.Center);
// circlesOfBalls.Add(circle);
if (textBox1.Text != "") textBox1.AppendText(Environment.NewLine);
textBox1.AppendText("ball position = x" + centerList[centerList.Count - 1].X +
", y = " + centerList[centerList.Count - 1].Y.ToString().PadLeft(4)
+ "centerList.Count= " + centerList.Count);
// + ", radios = " + centerList[centerList.Count - 1].Radius.ToString("###,000").PadLeft(7))
textBox1.ScrollToCaret();// scrolls the textBox to last line
// draw a small green circle in the center
CvInvoke.cvCircle(imgOriginal, // draw on the original image
new Point((int)circle.Center.X, (int)circle.Center.Y),//center point of circle
3, // radios of circle,
new MCvScalar (0, 255, 0), // draw in green color
-1, //indicates to fill the circle
LINE_TYPE.CV_AA, //smoothes the pixels
0);// no shift
//draw a red circle around the detected object
// if (imgOriginal.Data != null)
imgOriginal.Draw(circle, //current circle
new Bgr(Color.Red), // draw pure red
3);
} // end of for each
// if(imgOriginal.Data != null)
imageBox1.Image = imgOriginal;
}
public string pause()
{
if (binCapturingInProgress == true)// if we are currently processing an image, user just choose pause, so
{
Application.Idle -= processFrameAndUpdateGUI;
binCapturingInProgress = false;
return "resume";
}
else
{
Application.Idle += processFrameAndUpdateGUI;
binCapturingInProgress = true;
return "pause";
}
}
}
and this is the game code:
public partial class Game : Form
{
List<circlef> ballCircles = new List<circlef>();
C_Camera camera;
C_Serial serial;
List<pointf> centers = new List ... (more)