// MonoBehaviour methods /// <summary> /// Initialize the properties and suscribe to <see cref="ArucoObject.PropertyUpdated"/>. /// </summary> protected override void Awake() { base.Awake(); ImageSize = new Cv.Core.Size(); UpdateBoard(); UpdateHashCode(); }
public void Draw(Cv.Core.Size outSize, out Cv.Core.Mat img) { Cv.Core.Exception exception = new Cv.Core.Exception(); System.IntPtr imgPtr; au_CharucoBoard_draw3(cppPtr, outSize.cppPtr, out imgPtr, exception.cppPtr); img = new Cv.Core.Mat(imgPtr); exception.Check(); }
public void Draw(Cv.Core.Size outSize, out Cv.Core.Mat img, int marginSize, int borderBits) { Cv.Core.Exception exception = new Cv.Core.Exception(); System.IntPtr imgPtr; au_CharucoBoard_draw1(cppPtr, outSize.cppPtr, out imgPtr, marginSize, borderBits, exception.cppPtr); img = new Cv.Core.Mat(imgPtr); exception.Check(); }
public void Draw(Cv.Core.Size outSize, out Cv.Core.Mat img, int marginSize) { Cv.Core.Exception exception = new Cv.Core.Exception(); System.IntPtr imgPtr; au_GridBoard_draw2(cppPtr, outSize.cppPtr, out imgPtr, marginSize, exception.cppPtr); img = new Cv.Core.Mat(imgPtr); exception.Check(); }
public static double CalibrateCameraCharuco(Std.VectorVectorPoint2f charucoCorners, Std.VectorVectorInt charucoIds, CharucoBoard board, Cv.Core.Size imageSize, Cv.Core.Mat cameraMatrix, Cv.Core.Mat distCoeffs) { Cv.Core.Exception exception = new Cv.Core.Exception(); double reProjectionError = au_calibrateCameraCharuco5(charucoCorners.cppPtr, charucoIds.cppPtr, board.cppPtr, imageSize.cppPtr, cameraMatrix.cppPtr, distCoeffs.cppPtr, exception.cppPtr); exception.Check(); return(reProjectionError); }
public static double CalibrateCameraCharuco(Std.VectorVectorPoint2f charucoCorners, Std.VectorVectorInt charucoIds, CharucoBoard board, Cv.Core.Size imageSize, Cv.Core.Mat cameraMatrix, Cv.Core.Mat distCoeffs, out Std.VectorMat rvecs, out Std.VectorMat tvecs) { Cv.Core.Exception exception = new Cv.Core.Exception(); System.IntPtr rvecsPtr, tvecsPtr; double reProjectionError = au_calibrateCameraCharuco3(charucoCorners.cppPtr, charucoIds.cppPtr, board.cppPtr, imageSize.cppPtr, cameraMatrix.cppPtr, distCoeffs.cppPtr, out rvecsPtr, out tvecsPtr, exception.cppPtr); rvecs = new Std.VectorMat(rvecsPtr); tvecs = new Std.VectorMat(tvecsPtr); exception.Check(); return(reProjectionError); }
public void Calibrate() { Aruco.CharucoBoard charucoBoard = CalibrationBoard.Board as Aruco.CharucoBoard; // Check if there is enough captured frames for calibration for (int cameraId = 0; cameraId < ArucoCamera.CamerasNumber; cameraId++) { // Calibration with a grid board if (charucoBoard == null) { if (AllIds[cameraId].Size() < 1) { throw new System.Exception("Need at least one frame captured for the camera " + (cameraId + 1) + "/" + ArucoCamera.CamerasNumber + " to calibrate."); } } // Calibration with a charuco board else { if (AllCharucoIds[cameraId].Size() < 4) { IsCalibrated = false; throw new System.Exception("Need at least four frames captured for the camera " + (cameraId + 1) + "/" + ArucoCamera.CamerasNumber + " to calibrate with a ChAruco board."); } } } // Prepare camera parameters Cv.Core.Mat[] camerasMatrix = new Cv.Core.Mat[ArucoCamera.CamerasNumber], distCoeffs = new Cv.Core.Mat[ArucoCamera.CamerasNumber]; double[] reprojectionErrors = new double[ArucoCamera.CamerasNumber]; // Calibrate each camera for (int cameraId = 0; cameraId < ArucoCamera.CamerasNumber; cameraId++) { // Prepare camera parameters if (CalibrationFlagsController.FixAspectRatio) { camerasMatrix[cameraId] = new Cv.Core.Mat(3, 3, Cv.Core.TYPE.CV_64F, new double[9] { CalibrationFlagsController.FixAspectRatioValue, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 }); } else { camerasMatrix[cameraId] = new Cv.Core.Mat(); } distCoeffs[cameraId] = new Cv.Core.Mat(); // Prepare data for calibration Std.VectorVectorPoint2f allCornersContenated = new Std.VectorVectorPoint2f(); Std.VectorInt allIdsContenated = new Std.VectorInt(); Std.VectorInt markerCounterPerFrame = new Std.VectorInt(); uint allCornersSize = AllCorners[cameraId].Size(); markerCounterPerFrame.Reserve(allCornersSize); for (uint i = 0; i < allCornersSize; i++) { Std.VectorVectorPoint2f allCornersI = AllCorners[cameraId].At(i); uint allCornersISize = allCornersI.Size(); markerCounterPerFrame.PushBack((int)allCornersISize); for (uint j = 0; j < allCornersISize; j++) { allCornersContenated.PushBack(allCornersI.At(j)); allIdsContenated.PushBack(AllIds[cameraId].At(i).At(j)); } } // Calibrate camera with aruco Cv.Core.Size imageSize = ArucoCamera.Images[cameraId].size; Std.VectorMat rvecs, tvecs; reprojectionErrors[cameraId] = Aruco.CalibrateCameraAruco(allCornersContenated, allIdsContenated, markerCounterPerFrame, CalibrationBoard.Board, imageSize, camerasMatrix[cameraId], distCoeffs[cameraId], out rvecs, out tvecs, CalibrationFlagsController.CalibrationFlags, CalibrationTermCriteria); // If the used board is a charuco board, refine the calibration if (charucoBoard != null) { AllCharucoCorners[cameraId] = new Std.VectorVectorPoint2f(); AllCharucoIds[cameraId] = new Std.VectorVectorInt(); // Interpolate charuco corners using camera parameters for (uint i = 0; i < AllIds[cameraId].Size(); i++) { Std.VectorPoint2f charucoCorners; Std.VectorInt charucoIds; Aruco.InterpolateCornersCharuco(AllCorners[cameraId].At(i), AllIds[cameraId].At(i), AllImages[cameraId].At(i), charucoBoard, out charucoCorners, out charucoIds); AllCharucoCorners[cameraId].PushBack(charucoCorners); AllCharucoIds[cameraId].PushBack(charucoIds); } // Calibrate camera using charuco reprojectionErrors[cameraId] = Aruco.CalibrateCameraCharuco(AllCharucoCorners[cameraId], AllCharucoIds[cameraId], charucoBoard, imageSize, camerasMatrix[cameraId], distCoeffs[cameraId], out rvecs, out tvecs, CalibrationFlagsController.CalibrationFlags, CalibrationTermCriteria); } // Save calibration parameters Rvecs[cameraId] = rvecs; Tvecs[cameraId] = tvecs; } IsCalibrated = true; // Create camera parameters CameraParameters = new CameraParameters(ArucoCamera.CamerasNumber) { CalibrationFlags = (int)CalibrationFlagsController.CalibrationFlags, FixAspectRatioValue = CalibrationFlagsController.FixAspectRatioValue, ReprojectionError = reprojectionErrors, CamerasMatrix = camerasMatrix, DistCoeffs = distCoeffs }; for (int cameraId = 0; cameraId < ArucoCamera.CamerasNumber; cameraId++) { CameraParameters.ImagesHeight[cameraId] = ArucoCamera.ImageTextures[cameraId].height; CameraParameters.ImagesWidth[cameraId] = ArucoCamera.ImageTextures[cameraId].width; } // Save camera parameters string outputFolderPath = Path.Combine((Application.isEditor) ? Application.dataPath : Application.persistentDataPath, OutputFolder); if (!Directory.Exists(outputFolderPath)) { Directory.CreateDirectory(outputFolderPath); } string calibrationFilePath = outputFolderPath; calibrationFilePath += (CalibrationFilename == null || CalibrationFilename.Length == 0) ? ArucoCamera.Name + " - " + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") : CalibrationFilename; calibrationFilePath += ".xml"; CameraParameters.SaveToXmlFile(calibrationFilePath); }
public static double CalibrateCameraAruco(Std.VectorVectorPoint2f corners, Std.VectorInt ids, Std.VectorInt counter, Board board, Cv.Core.Size imageSize, Cv.Core.Mat cameraMatrix, Cv.Core.Mat distCoeffs, out Std.VectorMat rvecs, out Std.VectorMat tvecs, Cv.Calib3d.Calib flags) { Cv.Core.Exception exception = new Cv.Core.Exception(); System.IntPtr rvecsPtr, tvecsPtr; double reProjectionError = au_calibrateCameraAruco2(corners.cppPtr, ids.cppPtr, counter.cppPtr, board.cppPtr, imageSize.cppPtr, cameraMatrix.cppPtr, distCoeffs.cppPtr, out rvecsPtr, out tvecsPtr, (int)flags, exception.cppPtr); rvecs = new Std.VectorMat(rvecsPtr); tvecs = new Std.VectorMat(tvecsPtr); exception.Check(); return(reProjectionError); }