// find calibrates camera with collected data found by UFindCharucoBoardCorners method unsafe public static UCameraCalibrationData UCalibrateCameraCharuco(int width, int height, CharucoBoardParameters boardParameters, DoubleVectorIntMarshaller allCharucoIds, DoubleVectorPoint2FMarshaller allCharucoCorners) { MatDoubleMarshaller distCoeffs = new MatDoubleMarshaller(); MatDoubleMarshaller cameraMatrix = new MatDoubleMarshaller(); double reProjectionError = CalibrateCameraCharuco( height, width, boardParameters.squaresW, boardParameters.squaresH, boardParameters.squareLength, boardParameters.markerLength, allCharucoIds.NativeDataPointer, allCharucoCorners.NativeDataPointer, cameraMatrix.NativeDataPointer, distCoeffs.NativeDataPointer ); UCameraCalibrationData calibrationData = new UCameraCalibrationData( distCoeffs, cameraMatrix, reProjectionError ); return(calibrationData); }
// find charuco board corners in frame with given board parameters and imbues marshaller objects with information found unsafe public static bool UFindCharucoBoardCorners(Color32[] texture, int width, int height, CharucoBoardParameters boardParameters, DoubleVectorIntMarshaller allCharucoIds, DoubleVectorPoint2FMarshaller allCharucoCorners) { bool foundBoard = false; IntPtr foundBoardMarkers = CreateBooleanPointer(); fixed(Color32 *texP = texture) { DetectCharucoBoard( texP, width, height, boardParameters.squaresW, boardParameters.squaresH, boardParameters.squareLength, boardParameters.markerLength, foundBoardMarkers, allCharucoIds.NativeDataPointer, allCharucoCorners.NativeDataPointer ); } if (Marshal.ReadByte(foundBoardMarkers, 0) > 0) { foundBoard = true; } DeleteBooleanPointer(foundBoardMarkers); return(foundBoard); }
// public static UCameraCalibrationData UStaticCalibrateCameraData() // { // MatDoubleMarshaller distCoeffs = new MatDoubleMarshaller(); // MatDoubleMarshaller cameraMatrix = new MatDoubleMarshaller(); // StaticCameraCalibData( // cameraMatrix.NativeDataPointer, // distCoeffs.NativeDataPointer, // true // ); // UCameraCalibrationData calibrationData = new UCameraCalibrationData( // distCoeffs, // cameraMatrix // ); // return calibrationData; // } // unsafe public static UCameraCalibrationData UCalibrateCamera(Color32[] texture, int width, int height, DoubleVectorIntMarshaller allCharucoIds, DoubleVectorPoint2FMarshaller allCharucoCorners) // { // var watch = System.Diagnostics.Stopwatch.StartNew(); // // IntPtr distCoeffs = OpenCVMarshal.CreateMatPointer(); // MatDoubleMarshaller distCoeffs = new MatDoubleMarshaller(); // // IntPtr cameraMatrix = OpenCVMarshal.CreateMatPointer(); // MatDoubleMarshaller cameraMatrix = new MatDoubleMarshaller(); // fixed (Color32* texP = texture) // { // CalibrateCamera( // texP, // width, // height, // allCharucoIds.NativeDataPointer, // allCharucoCorners.NativeDataPointer, // cameraMatrix.NativeDataPointer, // distCoeffs.NativeDataPointer // ); // } // UCameraCalibrationData calibrationData = new UCameraCalibrationData( // distCoeffs, // cameraMatrix // ); // watch.Stop(); // var elapsedMs = watch.ElapsedMilliseconds; // return calibrationData; // } unsafe public static UCameraCalibrationData UCalibrateCameraCharuco(int width, int height, CharucoBoardParameters boardParameters, DoubleVectorIntMarshaller allCharucoIds, DoubleVectorPoint2FMarshaller allCharucoCorners) { var watch = System.Diagnostics.Stopwatch.StartNew(); // IntPtr distCoeffs = OpenCVMarshal.CreateMatPointer(); MatDoubleMarshaller distCoeffs = new MatDoubleMarshaller(); // IntPtr cameraMatrix = OpenCVMarshal.CreateMatPointer(); MatDoubleMarshaller cameraMatrix = new MatDoubleMarshaller(); double reProjectionError = CalibrateCameraCharuco( height, width, boardParameters.squaresW, boardParameters.squaresH, boardParameters.squareLength, boardParameters.markerLength, allCharucoIds.NativeDataPointer, allCharucoCorners.NativeDataPointer, cameraMatrix.NativeDataPointer, distCoeffs.NativeDataPointer ); UCameraCalibrationData calibrationData = new UCameraCalibrationData( distCoeffs, cameraMatrix, reProjectionError ); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; return(calibrationData); }
// returns marker detection data and board pose information with board orientation public unsafe static (UDetectMarkersData, UBoardMarkerPoseEstimationDataEuler) UEstimateCharucoBoardPose(Color32[] texture, int width, int height, CharucoBoardParameters boardParameters, IntPtr cameraMatrix, IntPtr distCoeffs) { // marshallers Vec3dMarshaller tvecMarshaller = new Vec3dMarshaller(); Vec3dMarshaller rvecMarshaller = new Vec3dMarshaller(); MatDoubleMarshaller eulerAngles = new MatDoubleMarshaller(); // marker pointers VectorIntMarshaller markerIds = new VectorIntMarshaller(); DoubleVectorPoint2FMarshaller markerCornerMarshaller = new DoubleVectorPoint2FMarshaller(); DoubleVectorPoint2FMarshaller rejectedCandidateMarshaller = new DoubleVectorPoint2FMarshaller(); fixed(Color32 *texP = texture) { EstimateCharucoBoardPose( texP, width, height, boardParameters.markerLength, boardParameters.squareLength, boardParameters.squaresW, boardParameters.squaresH, markerIds.NativeDataPointer, markerCornerMarshaller.NativeDataPointer, rejectedCandidateMarshaller.NativeDataPointer, cameraMatrix, distCoeffs, rvecMarshaller.NativeDataPointer, tvecMarshaller.NativeDataPointer, eulerAngles.NativeDataPointer ); } UDetectMarkersData markerData = new UDetectMarkersData( (int[])markerIds.GetMangedObject(), (List <List <Vector2> >)markerCornerMarshaller.GetMangedObject(), (List <List <Vector2> >)rejectedCandidateMarshaller.GetMangedObject(), markerIds.NativeDataPointer, markerCornerMarshaller.NativeDataPointer, rejectedCandidateMarshaller.NativeDataPointer ); UBoardMarkerPoseEstimationDataEuler PoseEstimateData = new UBoardMarkerPoseEstimationDataEuler( (Vec3d)rvecMarshaller.GetMangedObject(), (Vec3d)tvecMarshaller.GetMangedObject(), (double[][])eulerAngles.GetMangedObject() ); return(markerData : markerData, PoseEstimateData : PoseEstimateData); }
unsafe public static bool UFindCharucoBoardCorners(Color32[] texture, int width, int height, CharucoBoardParameters boardParameters, DoubleVectorIntMarshaller allCharucoIds, DoubleVectorPoint2FMarshaller allCharucoCorners) { var watch = System.Diagnostics.Stopwatch.StartNew(); int cornersH = 9; int cornersW = 6; float squareLength = 0.025f; float markersLength = 0.0125f; bool foundBoard = false; IntPtr foundBoardMarkers = CreateBooleanPointer(); fixed(Color32 *texP = texture) { DetectCharucoBoard( texP, width, height, boardParameters.squaresW, boardParameters.squaresH, boardParameters.squareLength, boardParameters.markerLength, foundBoardMarkers, allCharucoIds.NativeDataPointer, allCharucoCorners.NativeDataPointer ); } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; if (Marshal.ReadByte(foundBoardMarkers, 0) > 0) { foundBoard = true; } DeleteBooleanPointer(foundBoardMarkers); return(foundBoard); }