Пример #1
0
    void Update()
    {
        // if space is down do AR tranformation
        if (notCalibrated && Input.GetKeyDown(KeyCode.Space))
        {
            // laod camera calibrations setting
            CameraCalibSerializable calidSaveData = Utilities.LoadCameraCalibrationParams();
            // initialise marhsallers
            MatDoubleMarshaller distCoeffs   = new MatDoubleMarshaller(calidSaveData.distortionCoefficients);
            MatDoubleMarshaller cameraMatrix = new MatDoubleMarshaller(calidSaveData.cameraMatrix);
            double reProjectionError         = calidSaveData.reProjectionError;
            // get calibration data
            calibData     = new UCameraCalibrationData(distCoeffs, cameraMatrix, reProjectionError);
            notCalibrated = false;
        }
        else if (!notCalibrated)
        {
            // estimate charuco board pose
            (
                UDetectMarkersData markerData,
                UBoardMarkerPoseEstimationDataEuler poseEstimationData
            ) = Aruco.UEstimateCharucoBoardPose(
                _webCamTexture.GetPixels32(),
                _webCamTexture.width,
                _webCamTexture.height,
                boardParameters,
                calibData.cameraMatrix.NativeDataPointer,
                calibData.distCoeffs.NativeDataPointer
                );

            TransformGameObjects(poseEstimationData, markerData);
        }
    }
Пример #2
0
    void Update()
    {
        if (notCalibrated)
        {
            if (Input.touchCount > 0)
            {
                // find charuco board corners in the frame
                bool sucess = Aruco.UFindCharucoBoardCorners(_webCamTexture.GetPixels32(), _webCamTexture.width, _webCamTexture.height, boardParameters, allCharucoIds, allCharucoCorners);

                if (sucess)
                {
                    numOfSuccessfulFrames++;
                }

                if (numOfSuccessfulFrames >= 40)
                {
                    // calibrate camera after defined amount of frames have been recorded
                    calibData = Aruco.UCalibrateCameraCharuco(_webCamTexture.width, _webCamTexture.height, boardParameters, allCharucoIds, allCharucoCorners);

                    CameraCalibSerializable calidSaveData;
                    calidSaveData.distortionCoefficients = (double[][])calibData.distCoeffs.GetMangedObject();
                    calidSaveData.cameraMatrix           = (double[][])calibData.cameraMatrix.GetMangedObject();
                    calidSaveData.reProjectionError      = calibData.reProjectionError;
                    // save obtained calibration settings
                    Utilities.SaveCameraCalibrationParams(calidSaveData);

                    notCalibrated = false;
                }
            }
        }
        if (!notCalibrated)
        {
            (
                UDetectMarkersData markerData,
                UBoardMarkerPoseEstimationDataEuler poseEstimationData
            ) = Aruco.UEstimateCharucoBoardPose(
                _webCamTexture.GetPixels32(),
                _webCamTexture.width,
                _webCamTexture.height,
                boardParameters,
                calibData.cameraMatrix.NativeDataPointer,
                calibData.distCoeffs.NativeDataPointer
                );

            TransformGameObjects(poseEstimationData, markerData);
        }
    }