void Update() { if (!runningOnAndroid) { if (notCalibrated && Input.GetKeyDown(KeyCode.Space)) { bool sucess = Aruco.UFindCharucoBoardCorners(_webCamTexture.GetPixels32(), _webCamTexture.width, _webCamTexture.height, boardParameters, allCharucoIds, allCharucoCorners); if (sucess) { numOfSuccessfulFrames++; } if (numOfSuccessfulFrames >= numOfFrames) { 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; Utilities.SaveCameraCalibrationParams(calidSaveData); notCalibrated = false; } } } else { if (notCalibrated) { if (Input.touchCount > 0) { bool sucess = Aruco.UFindCharucoBoardCorners(_webCamTexture.GetPixels32(), _webCamTexture.width, _webCamTexture.height, boardParameters, allCharucoIds, allCharucoCorners); if (sucess) { numOfSuccessfulFrames++; } if (numOfSuccessfulFrames >= numOfFrames) { 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; Utilities.SaveCameraCalibrationParams(calidSaveData); notCalibrated = false; } } } } }
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); } }