// ArucoObjectTracker methods

            /// <summary>
            /// <see cref="ArucoObjectTracker.Detect(int, Aruco.Dictionary, HashSet{ArucoObject})"/>
            /// </summary>
            public override void Detect(int cameraId, Aruco.Dictionary dictionary)
            {
                if (!IsActivated)
                {
                    return;
                }

                CameraParameters cameraParameters = arucoTracker.ArucoCamera.CameraParameters;

                foreach (var arucoCharucoBoard in arucoTracker.GetArucoObjects <ArucoCharucoBoard>(dictionary))
                {
                    if (arucoTracker.RefineDetectedMarkers)
                    {
                        Aruco.RefineDetectedMarkers(arucoTracker.ArucoCamera.Images[cameraId], arucoCharucoBoard.Board, arucoTracker.MarkerTracker.MarkerCorners[cameraId][dictionary],
                                                    arucoTracker.MarkerTracker.MarkerIds[cameraId][dictionary], arucoTracker.MarkerTracker.RejectedCandidateCorners[cameraId][dictionary]);
                        arucoTracker.MarkerTracker.DetectedMarkers[cameraId][dictionary] = (int)arucoTracker.MarkerTracker.MarkerIds[cameraId][dictionary].Size();
                    }

                    Std.VectorPoint2f charucoCorners = null;
                    Std.VectorInt     charucoIds     = null;

                    if (arucoTracker.MarkerTracker.DetectedMarkers[cameraId][dictionary] > 0)
                    {
                        if (cameraParameters == null)
                        {
                            arucoCharucoBoard.InterpolatedCorners = Aruco.InterpolateCornersCharuco(arucoTracker.MarkerTracker.MarkerCorners[cameraId][dictionary],
                                                                                                    arucoTracker.MarkerTracker.MarkerIds[cameraId][dictionary], arucoTracker.ArucoCamera.Images[cameraId], (Aruco.CharucoBoard)arucoCharucoBoard.Board, out charucoCorners,
                                                                                                    out charucoIds);
                        }
                        else
                        {
                            arucoCharucoBoard.InterpolatedCorners = Aruco.InterpolateCornersCharuco(arucoTracker.MarkerTracker.MarkerCorners[cameraId][dictionary],
                                                                                                    arucoTracker.MarkerTracker.MarkerIds[cameraId][dictionary], arucoTracker.ArucoCamera.Images[cameraId], (Aruco.CharucoBoard)arucoCharucoBoard.Board, out charucoCorners,
                                                                                                    out charucoIds, cameraParameters.CamerasMatrix[cameraId], cameraParameters.DistCoeffs[cameraId]);
                        }
                    }
                    else
                    {
                        arucoCharucoBoard.InterpolatedCorners = 0;
                    }

                    arucoCharucoBoard.DetectedCorners = charucoCorners;
                    arucoCharucoBoard.DetectedIds     = charucoIds;
                }
            }
Exemple #2
0
            // 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;
                }
            }