public void CalculateCameraIntrinsics() { if (processedImageCount > 0) { Debug.Log("Starting Camera Intrinsics calculation."); intrinsics = CalibrationAPI.Instance.CalculateChessboardIntrinsics(chessSquareSize); Debug.Log($"Chessboard intrinsics reprojection error: {intrinsics.ToString()}"); intrinsicsFileName = CalibrationDataHelper.SaveCameraIntrinsics(intrinsics); Debug.Log($"Camera Intrinsics saved to file: {intrinsicsFileName}"); // Undistort obtained images to understand quality of calculated camera intrinsics. var chessboardImageFileNames = CalibrationDataHelper.GetChessboardImageFileNames(); foreach (var fileName in chessboardImageFileNames) { var texture = CalibrationDataHelper.LoadChessboardImage(fileName); if (texture == null || !UndistortChessboardImage(texture, intrinsics)) { Debug.LogWarning($"Failed to locate/undistort chessboard image: {fileName}"); } else { CalibrationDataHelper.SaveChessboardUndistortedImage(texture, fileName); } } } else { Debug.LogWarning("No images have been processed, unable to calculate camera intrinsics."); } }
private void Update() { if (feedImage != null && feedImage.texture == null) { feedImage.texture = CompositorWrapper.Instance.GetVideoCameraFeed(); } if (cornersImage) { cornersImage.texture = chessboardCorners; } if (heatmapImage) { heatmapImage.texture = chessboardHeatmap; } if (Input.GetKeyDown(KeyCode.Space)) { var dslrTexture = CompositorWrapper.Instance.GetVideoCameraTexture(); var fileName = CalibrationDataHelper.GetUniqueFileName(); CalibrationDataHelper.SaveChessboardImage(dslrTexture, fileName); if (!ProcessChessboardImage(dslrTexture)) { Debug.LogWarning($"Failed to process/locate chessboard in dataset: {fileName}"); } else { CalibrationDataHelper.SaveChessboardDetectedImage(dslrTexture, fileName); CalibrationDataHelper.SaveImage(chessboardHeatmap, "ChessboardHeatmap"); CalibrationDataHelper.SaveImage(chessboardCorners, "ChessboardCorners"); } } if (Input.GetKeyDown(KeyCode.Return)) { Debug.Log("Starting Camera Intrinsics calculation."); intrinsics = CalibrationAPI.Instance.CalculateChessboardIntrinsics(chessSquareSize); Debug.Log($"Chessboard intrinsics reprojection error: {intrinsics.ToString()}"); var file = CalibrationDataHelper.SaveCameraIntrinsics(intrinsics); Debug.Log($"Camera Intrinsics saved to file: {file}"); } }