Beispiel #1
0
            /// <summary>
            /// Detects the Aruco markers on the current images of the cameras and store the results in the <see cref="MarkerCornersCurrentImage"/> and
            /// <see cref="MarkerIdsCurrentImage"/> properties.
            /// </summary>
            public virtual void DetectMarkers()
            {
                if (!IsConfigured)
                {
                    throw new Exception("Configure the calibration controller before detect markers.");
                }

                for (int cameraId = 0; cameraId < ArucoCamera.CameraNumber; cameraId++)
                {
                    Std.VectorInt           markerIds;
                    Std.VectorVectorPoint2f markerCorners, rejectedCandidateCorners;

                    Cv.Mat image = ArucoCamera.Images[cameraId];

                    Aruco.DetectMarkers(image, CalibrationBoard.Dictionary, out markerCorners, out markerIds, DetectorParameters, out rejectedCandidateCorners);

                    MarkerCornersCurrentImage[cameraId] = markerCorners;
                    MarkerIdsCurrentImage[cameraId]     = markerIds;

                    if (RefineMarkersDetection)
                    {
                        Aruco.RefineDetectedMarkers(image, CalibrationBoard.Board, MarkerCornersCurrentImage[cameraId], MarkerIdsCurrentImage[cameraId],
                                                    rejectedCandidateCorners);
                    }
                }
            }
Beispiel #2
0
            public void Detect()
            {
                if (!IsConfigured)
                {
                    return;
                }

                for (int cameraId = 0; cameraId < ArucoCamera.CamerasNumber; cameraId++)
                {
                    Std.VectorInt           markerIds;
                    Std.VectorVectorPoint2f markerCorners, rejectedCandidateCorners;

                    Cv.Core.Mat image = ArucoCamera.Images[cameraId];

                    Aruco.DetectMarkers(image, CalibrationBoard.Dictionary, out markerCorners, out markerIds, DetectorParameters, out rejectedCandidateCorners);

                    MarkerCornersCurrentImage[cameraId] = markerCorners;
                    MarkerIdsCurrentImage[cameraId]     = markerIds;

                    if (RefineMarkersDetection)
                    {
                        Aruco.RefineDetectedMarkers(image, CalibrationBoard.Board, MarkerCornersCurrentImage[cameraId], MarkerIdsCurrentImage[cameraId], rejectedCandidateCorners);
                    }
                }
            }
Beispiel #3
0
            // ArucoObjectTracker methods

            public override void Detect(int cameraId, Aruco.Dictionary dictionary, Cv.Mat 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();
                    }
                }
            }
            // ArucoObjectTracker methods

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

                if (arucoTracker.RefineDetectedMarkers)
                {
                    foreach (var arucoBoard in arucoTracker.GetArucoObjects <ArucoGridBoard>(dictionary))
                    {
                        Aruco.RefineDetectedMarkers(arucoTracker.ArucoCamera.Images[cameraId], arucoBoard.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();
                    }
                }
            }
            // 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;
                }
            }
Beispiel #6
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;
                }
            }