Ejemplo n.º 1
0
        public PuzzleBot(IHost host)
        {
            _host = host;
            _host.WriteLogMessage(c_componentName, "Initializing PuzzleBot comm. channels.");
            _machine = new CncMachine(_host);
            _upwardCamera = new OpenCV.CaptureEngine(
                $"http://{_host.GetParam<string>("MachineHostName")}:{_host.GetParam<int>("UpCameraPort")}/?action=stream");
            _downwardCamera = new OpenCV.CaptureEngine(
                $"http://{_host.GetParam<string>("MachineHostName")}:{_host.GetParam<int>("DownCameraPort")}/?action=stream");
            _upwardCameraView = _host.CreateCameraView("Upward Camera");
            _downwardCameraView = _host.CreateCameraView("Downward Camera");
            _downwardCameraIntrinsic = _host.GetParam<JObject>("IntrinsticCalib").ToMat();
            _downwardCameraExtrinstic = _host.GetParam<JObject>("ExtrinsticCalib").ToMat();

            _viewUpdateThread = new Thread(CameraViewUpdater);
            _viewUpdateThread.Start();

            _host.WriteLogMessage(c_componentName, "Press enter to home...");
            _host.ReadLine();
            _machine.PerformMechanicalHome();

            AttachKeyHandlers();
            MainControlLoop();
        }
Ejemplo n.º 2
0
        void Routine_CameraCalibration()
        {
            _host.WriteLogMessage(c_componentName, "Ensuring chessboard configured...");
            var cbParams = CameraCalibration.EnsureChessboardConfigured(_host);
            var finder = new ChessboardCornerFinder(cbParams.HorizontalSquareCount, cbParams.VerticalSquareCount);
            List<Point<float>[]> calPoints = new List<OpenCV.Point<float>[]>();

            int camWidth = 0;
            int camHeight = 0;
            Action findCorner = () => {
                _downwardImageOverrideMode = true;
                while (true) {
                    using (var img = _downwardCamera.TryGrabFrame()) {
                        camWidth = img.Columns;
                        camHeight = img.Rows;
                        var result = finder.TryFind(img);
                        _downwardCameraView.UpdateImage(img);
                        if (result != null) {
                            _host.WriteLogMessage(c_componentName, "Found corners!");
                            calPoints.Add(result);
                            Thread.Sleep(100);
                            break;
                        }
                    }
                }
                _downwardImageOverrideMode = false;
            };

            Action findCornerSet = () => {
                findCorner();
                Thread.Sleep(100);
                findCorner();
                Thread.Sleep(100);
                findCorner();
                Thread.Sleep(100);
            };

            _host.WriteLogMessage(c_componentName, "Jog machine over first calibration target and press enter.");
            _host.ReadLine();

            while (true) {
                findCornerSet();
                _host.WriteLogMessage(c_componentName, "Jog machine over next calibration target and press enter or (N) to stop.");
                if (_host.ReadLine().Equals("N")) break;
            }

            Mat camMat;
            Mat distCoeff;
            var rms = CameraCalibration.Calibrate(cbParams, calPoints.ToArray(),
                new Point<int>() { X = camWidth, Y = camHeight }, out camMat, out distCoeff);
            _host.WriteLogMessage(c_componentName, $"Camera claibrated, {rms} error.");

            _host.SaveParam("IntrinsticCalib", camMat.ToJObject());
            _host.SaveParam("ExtrinsticCalib", distCoeff.ToJObject());
            _host.WriteLogMessage(c_componentName, "Camera calibated!");
            _downwardCameraExtrinstic = distCoeff;
            _downwardCameraIntrinsic = camMat;
        }
Ejemplo n.º 3
0
 public static extern Mat Undistort(Mat img, Mat cameraMatrix, Mat distCoeffs);
Ejemplo n.º 4
0
 public static extern bool TryFindChessboardCorners(Mat img, int patternWidth, int patternHeight, float[] cornerPoints);
Ejemplo n.º 5
0
 public static extern void Mat_SaveImage(Mat handle, string filename);
Ejemplo n.º 6
0
 public static extern int Mat_GetType(Mat handle);
Ejemplo n.º 7
0
 public static extern void Mat_GetSteps(Mat handle, int[] steps);
Ejemplo n.º 8
0
 public static extern void ComputeCalibration(int patternWidth, int patternHeight,
     float mmPerSquare, int cameraWidth, int cameraHeight, float[] cornerPoints, int numBoards,
     double* rms, Mat* distCoeffs, Mat* cameraMatrix);
Ejemplo n.º 9
0
 public static extern int Mat_GetDims(Mat handle);
Ejemplo n.º 10
0
 public static extern byte* Mat_GetData(Mat handle);
Ejemplo n.º 11
0
 public static extern int Mat_GetColumns(Mat handle);
Ejemplo n.º 12
0
 public static extern int Mat_GetChannels(Mat handle);
Ejemplo n.º 13
0
 public static extern Mat Mat_DrawCrosshair(Mat handle);
Ejemplo n.º 14
0
 public static extern void Mat_Destroy(Mat handle);
Ejemplo n.º 15
0
 void Routine_ClearCalibrationData()
 {
     _downwardCameraIntrinsic = null;
     _downwardCameraExtrinstic = null;
 }
Ejemplo n.º 16
0
 public static extern int Mat_GetRows(Mat handle);
Ejemplo n.º 17
0
 public static extern bool CaptureEngine_TryGrabFrame(CaptureEngine handle, Mat* frame);