public override void Detect(int cameraId, Aruco.Dictionary dictionary, Cv.Mat image) { base.Detect(cameraId, dictionary, image); ArucoMarkerTracker markerTracker = arucoTracker.MarkerTracker; Std.VectorVectorPoint2f diamondCorners = null; Std.VectorVec4i diamondIds = null; if (markerTracker.DetectedMarkers[cameraId][dictionary] > 0) { if (arucoCameraUndistortion == null) { Aruco.DetectCharucoDiamond(image, markerTracker.MarkerCorners[cameraId][dictionary], markerTracker.MarkerIds[cameraId][dictionary], DetectSquareMarkerLengthRate, out diamondCorners, out diamondIds); } else { Aruco.DetectCharucoDiamond(image, markerTracker.MarkerCorners[cameraId][dictionary], markerTracker.MarkerIds[cameraId][dictionary], DetectSquareMarkerLengthRate, out diamondCorners, out diamondIds, arucoCameraUndistortion.RectifiedCameraMatrices[cameraId], arucoCameraUndistortion.UndistortedDistCoeffs[cameraId]); } } DiamondCorners[cameraId][dictionary] = diamondCorners; DiamondIds[cameraId][dictionary] = diamondIds; DetectedDiamonds[cameraId][dictionary] = (diamondIds != null) ? (int)diamondIds.Size() : 0; }
// MonoBehaviour methods /// <summary> /// Initializes the trackers list. /// </summary> protected override void Awake() { base.Awake(); MarkerTracker = new ArucoMarkerTracker(); additionalTrackers = new Dictionary <Type, ArucoObjectTracker>() { { typeof(ArucoGridBoard), new ArucoGridBoardTracker() }, { typeof(ArucoCharucoBoard), new ArucoCharucoBoardTracker() }, { typeof(ArucoDiamond), new ArucoDiamondTracker() } }; }
// ArucoObjectTracker methods public override void Detect(int cameraId, Aruco.Dictionary dictionary, Cv.Mat image) { base.Detect(cameraId, dictionary, image); ArucoMarkerTracker markerTracker = arucoTracker.MarkerTracker; if (arucoTracker.RefineDetectedMarkers && arucoTracker.MarkerTracker.DetectedMarkers[cameraId][dictionary] > 0) { foreach (var arucoBoard in arucoTracker.GetArucoObjects<ArucoGridBoard>(dictionary)) { Aruco.RefineDetectedMarkers(image, arucoBoard.Board, markerTracker.MarkerCorners[cameraId][dictionary], markerTracker.MarkerIds[cameraId][dictionary], markerTracker.RejectedCandidateCorners[cameraId][dictionary]); markerTracker.DetectedMarkers[cameraId][dictionary] = (int)markerTracker.MarkerIds[cameraId][dictionary].Size(); } } }
// MonoBehaviour methods /// <summary> /// Initializes the trackers list and sets <see cref="ArucoCameraDisplay" /> from editor field if not null. /// </summary> protected override void Awake() { base.Awake(); MarkerTracker = new ArucoMarkerTracker(); additionalTrackers = new Dictionary <Type, ArucoObjectTracker> { { typeof(ArucoGridBoard), new ArucoGridBoardTracker() }, { typeof(ArucoCharucoBoard), new ArucoCharucoBoardTracker() }, { typeof(ArucoDiamond), new ArucoDiamondTracker() } }; if (arucoCameraDisplay != null) { ArucoCameraDisplay = arucoCameraDisplay; } }
// ArucoObjectTracker methods public override void Detect(int cameraId, Aruco.Dictionary dictionary, Cv.Mat image) { base.Detect(cameraId, dictionary, image); ArucoMarkerTracker markerTracker = arucoTracker.MarkerTracker; foreach (var arucoCharucoBoard in arucoTracker.GetArucoObjects <ArucoCharucoBoard>(dictionary)) { if (arucoTracker.RefineDetectedMarkers) { Aruco.RefineDetectedMarkers(image, arucoCharucoBoard.Board, markerTracker.MarkerCorners[cameraId][dictionary], markerTracker.MarkerIds[cameraId][dictionary], markerTracker.RejectedCandidateCorners[cameraId][dictionary]); markerTracker.DetectedMarkers[cameraId][dictionary] = (int)markerTracker.MarkerIds[cameraId][dictionary].Size(); } Std.VectorPoint2f charucoCorners = null; Std.VectorInt charucoIds = null; if (markerTracker.DetectedMarkers[cameraId][dictionary] > 0) { if (arucoCameraUndistortion == null) { Aruco.InterpolateCornersCharuco(markerTracker.MarkerCorners[cameraId][dictionary], markerTracker.MarkerIds[cameraId][dictionary], arucoCamera.Images[cameraId], (Aruco.CharucoBoard)arucoCharucoBoard.Board, out charucoCorners, out charucoIds); } else { Aruco.InterpolateCornersCharuco(markerTracker.MarkerCorners[cameraId][dictionary], markerTracker.MarkerIds[cameraId][dictionary], arucoCamera.Images[cameraId], (Aruco.CharucoBoard)arucoCharucoBoard.Board, out charucoCorners, out charucoIds, arucoCameraUndistortion.RectifiedCameraMatrices[cameraId], arucoCameraUndistortion.UndistortedDistCoeffs[cameraId]); } } arucoCharucoBoard.DetectedCorners = charucoCorners; arucoCharucoBoard.DetectedIds = charucoIds; } }