using System; using System.Collections.Generic; using System.Linq; using System.Text; using OpenCvSharp; using System.Drawing; namespace AtariRobot { //Capture -- Should be pure OpenCV, get image from whatever. Can also include clarification/rectification of image. //Recognize -- Recognize pieces of the image and determine what scene contains. Takes current frame and previous frames. Returns a custom screen state object. //Analyze -- Analyzes the current frame and past frames to determine best move. Takes current state and previous states. Returns a movement recommendation? //Move -- Interfaces with movement control. For paddle, it's direction distatnce/speed/time, etc, joystick is u/d/l/r, and of course, buttons on both. class Program { [STAThread] static void Main(string[] args) { Options options = Options.GetOptions(); CvWindow rawVideo = new CvWindow("RawVideo"); CvWindow edgeVideo = new CvWindow("EdgeDetect"); CvWindow contourVideo = new CvWindow("Contours"); CvWindow recognizedVideo = new CvWindow("Recognized"); CvWindow enlargedVideo = new CvWindow("Enlarged"); CvCapture capture = null; if(string.IsNullOrEmpty(options.Filename)) { capture = Cv.CreateCameraCapture(options.CameraIndex); } else { capture = CvCapture.FromFile(options.Filename); } //CalibrationInfo calibrationInfo = Calibrator.GetCalibrationInfo(capture); double fps = capture.Fps; if (fps == 0) { fps = 60; } int frameTime = (int)(1000 / fps); //frameTime = 250; //while (Cv.WaitKey(frameTime) < 0) //{ // IplImage frame = capture.QueryFrame(); // CvPoint2D32f[] chessboardPoints; // CvSize size = new CvSize(7, 7); // bool patternFound = Cv.FindChessboardCorners(frame, new CvSize(7, 7), out chessboardPoints); // frame.DrawChessboardCorners(size, chessboardPoints, patternFound); // rawVideo.Image = frame; //} PongLogic pongLogic = new PongLogic(options.ComPort); while (Cv.WaitKey(frameTime) < 0) { IplImage frame = capture.QueryFrame(); if (frame == null) { break; } rawVideo.Image = frame; pongLogic.HandleFrame(frame); IplImage enlarged = new IplImage(frame.Width * 2, frame.Height * 2, frame.Depth, frame.ElemChannels); frame.Resize(enlarged); enlargedVideo.Image = enlarged; enlarged.Dispose(); } capture.Dispose(); rawVideo.Dispose(); edgeVideo.Dispose(); contourVideo.Dispose(); recognizedVideo.Dispose(); enlargedVideo.Dispose(); } } }