Пример #1
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FPinInDo[0])
            {
                bool useVVVVCoords = FPinInCoordSystem[0] == TCoordinateSystem.VVVV;

                SpreadMax = Math.Max(FPinInObject.SliceCount, FPinInImage.SliceCount);

                FPinOutExtrinsics.SliceCount = SpreadMax;
                FPinOutStatus.SliceCount     = SpreadMax;

                for (int i = 0; i < SpreadMax; i++)
                {
                    try
                    {
                        if (FPinInObject[i].SliceCount == 0 || FPinInImage[i].SliceCount == 0)
                        {
                            throw new Exception("No datapoints");
                        }
                        if (FPinInImage[i].SliceCount == 1)
                        {
                            throw new Exception("Only 1 image point is being input per board, check SliceCount!");
                        }
                        if (FPinInObject[i].SliceCount == 1)
                        {
                            throw new Exception("Only 1 object point is being input per board, check SliceCount!");
                        }
                        if (FPinInIntrinsics[i].intrinsics == null)
                        {
                            throw new Exception("Waiting for camera calibration intrinsics");
                        }

                        ExtrinsicCameraParameters extrinsics = CameraCalibration.FindExtrinsicCameraParams2(MatrixUtils.ObjectPoints(FPinInObject[i], useVVVVCoords), MatrixUtils.ImagePoints(FPinInImage[i]), FPinInIntrinsics[i].intrinsics);
                        FPinOutExtrinsics[i] = new Extrinsics(extrinsics);

                        if (useVVVVCoords)
                        {
                            FPinOutView[i] = MatrixUtils.ConvertToVVVV(FPinOutExtrinsics[i].Matrix);
                        }
                        else
                        {
                            FPinOutView[i] = FPinOutExtrinsics[i].Matrix;
                        }

                        FPinOutStatus[i] = "OK";
                    }
                    catch (Exception e)
                    {
                        FPinOutStatus[i] = e.Message;
                    }
                }
            }
        }
Пример #2
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FPinInDo[0])
            {
                int  nPointsPerImage = FPinInObject.SliceCount;
                bool useVVVVCoords   = FPinInCoordSystem[0] == TCoordinateSystem.VVVV;

                if (nPointsPerImage == 0)
                {
                    FStatus[0] = "Insufficient points";
                    return;
                }
                int nImages = FPinInImage.SliceCount / nPointsPerImage;

                MCvPoint3D32f[][] objectPoints = new MCvPoint3D32f[nImages][];
                PointF[][]        imagePoints  = new PointF[nImages][];
                Size       imageSize           = new Size((int)FPinInSensorSize[0].x, (int)FPinInSensorSize[0].y);
                CALIB_TYPE flags = new CALIB_TYPE();
                IntrinsicCameraParameters   intrinsicParam = new IntrinsicCameraParameters();
                ExtrinsicCameraParameters[] extrinsicsPerView;
                GetFlags(out flags);

                if (flags.HasFlag(CALIB_TYPE.CV_CALIB_USE_INTRINSIC_GUESS))
                {
                    if (FPinInIntrinsics[0] == null)
                    {
                        Matrix <double> mat = intrinsicParam.IntrinsicMatrix;
                        mat[0, 0] = FPinInSensorSize[0].x / 2.0d;
                        mat[1, 1] = FPinInSensorSize[0].y / 2.0d;
                        mat[0, 2] = FPinInSensorSize[0].x / 2.0d;
                        mat[1, 2] = FPinInSensorSize[0].y / 2.0d;
                        mat[2, 2] = 1;
                    }
                    else
                    {
                        intrinsicParam.DistortionCoeffs = FPinInIntrinsics[0].intrinsics.DistortionCoeffs.Clone();
                        intrinsicParam.IntrinsicMatrix  = FPinInIntrinsics[0].intrinsics.IntrinsicMatrix.Clone();
                    }
                }

                imagePoints = MatrixUtils.ImagePoints(FPinInImage, nPointsPerImage);

                for (int i = 0; i < nImages; i++)
                {
                    objectPoints[i] = MatrixUtils.ObjectPoints(FPinInObject, useVVVVCoords);
                }

                try
                {
                    FPinOutError[0] = CameraCalibration.CalibrateCamera(objectPoints, imagePoints, imageSize, intrinsicParam, flags, out extrinsicsPerView);

                    Intrinsics intrinsics = new Intrinsics(intrinsicParam, imageSize);
                    FPinOutIntrinsics[0] = intrinsics;
                    if (useVVVVCoords)
                    {
                        FPinOutProjection[0] = intrinsics.Matrix;
                    }
                    else
                    {
                        FPinOutProjection[0] = intrinsics.Matrix;
                    }

                    FPinOutExtrinsics.SliceCount = nImages;
                    FPinOutView.SliceCount       = nImages;
                    for (int i = 0; i < nImages; i++)
                    {
                        Extrinsics extrinsics = new Extrinsics(extrinsicsPerView[i]);
                        FPinOutExtrinsics[i] = extrinsics;

                        if (useVVVVCoords)
                        {
                            FPinOutView[i] = MatrixUtils.ConvertToVVVV(extrinsics.Matrix);
                        }
                        else
                        {
                            FPinOutView[i] = extrinsics.Matrix;
                        }
                    }

                    FPinOutSuccess[0] = true;
                    FStatus[0]        = "OK";
                }
                catch (Exception e)  {
                    FPinOutSuccess[0] = false;
                    FStatus[0]        = e.Message;
                }
            }
        }