Exemplo n.º 1
0
 public static void DrawDetectedMarkers(Cv.Core.Mat image, Std.VectorVectorPoint2f corners, Color borderColor)
 {
     Cv.Core.Exception exception         = new Cv.Core.Exception();
     Cv.Core.Scalar    borderColorScalar = borderColor;
     au_drawDetectedMarkers4(image.cppPtr, corners.cppPtr, borderColorScalar.cppPtr, exception.cppPtr);
     exception.Check();
 }
Exemplo n.º 2
0
 public static void RefineDetectedMarkers(Cv.Core.Mat image, Board board, Std.VectorVectorPoint2f detectedCorners, Std.VectorInt detectedIds,
                                          Std.VectorVectorPoint2f rejectedCorners)
 {
     Cv.Core.Exception exception = new Cv.Core.Exception();
     au_refineDetectedMarkers8(image.cppPtr, board.cppPtr, detectedCorners.cppPtr, detectedIds.cppPtr, rejectedCorners.cppPtr, exception.cppPtr);
     exception.Check();
 }
Exemplo n.º 3
0
 public Cv.Core.Mat At(uint pos)
 {
     Cv.Core.Exception exception = new Cv.Core.Exception();
     Cv.Core.Mat       element   = new Cv.Core.Mat(au_std_vectorMat_at(cppPtr, pos, exception.cppPtr), DeleteResponsibility.False);
     exception.Check();
     return(element);
 }
Exemplo n.º 4
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);
                    }
                }
            }
Exemplo n.º 5
0
            /// <summary>
            /// Initialize the <see cref="Images"/> property, the undistortion maps and the undistorded images.
            /// </summary>
            protected void InitializeMatImages()
            {
                images         = new Cv.Core.Mat[CamerasNumber];
                imageDataSizes = new int[CamerasNumber];

                Cv.Core.Mat undistordedImages_R = null;
                if (CameraParameters != null)
                {
                    undistordedImages      = new Cv.Core.Mat[CamerasNumber];
                    undistordedImages_maps = new Cv.Core.Mat[CamerasNumber][];
                    undistordedImages_R    = new Cv.Core.Mat();
                }

                for (int cameraId = 0; cameraId < CamerasNumber; cameraId++)
                {
                    // Image
                    byte[] imageData = ImageTextures[cameraId].GetRawTextureData();
                    images[cameraId]         = new Cv.Core.Mat(ImageTextures[cameraId].height, ImageTextures[cameraId].width, ImageType(ImageTextures[cameraId]), imageData);
                    imageDataSizes[cameraId] = (int)(images[cameraId].ElemSize() * images[cameraId].Total());

                    // Undistortion maps
                    if (CameraParameters != null)
                    {
                        Cv.Core.Mat cameraMatrix = CameraParameters.CamerasMatrix[cameraId];
                        undistordedImages_maps[cameraId] = new Cv.Core.Mat[2]; // map1 and map2
                        Cv.Imgproc.InitUndistortRectifyMap(cameraMatrix, CameraParameters.DistCoeffs[cameraId], undistordedImages_R,
                                                           cameraMatrix, Images[cameraId].size, Cv.Core.TYPE.CV_16SC2, out undistordedImages_maps[cameraId][0], out undistordedImages_maps[cameraId][1]);
                        undistordedImages[cameraId] = new Cv.Core.Mat(undistordedImages_maps[cameraId][0].size, ImageType(ImageTextures[cameraId]));
                    }
                }
            }
Exemplo n.º 6
0
 static public Cv.Core.Mat GetBitsFromByteList(Cv.Core.Mat byteList, int markerSiz)
 {
     Cv.Core.Exception exception = new Cv.Core.Exception();
     Cv.Core.Mat       bits      = new Cv.Core.Mat(au_Dictionary_getBitsFromByteList(byteList.cppPtr, markerSiz, exception.cppPtr));
     exception.Check();
     return(bits);
 }
Exemplo n.º 7
0
            // Methods

            /// <summary>
            /// Create the image and the image texture of the <see cref="ArucoObject"/>.
            /// </summary>
            public virtual void Create()
            {
                Cv.Core.Mat image = null;
                ImageTexture = null;

                // In case of a marker
                ArucoMarker marker = ArucoObject as ArucoMarker;

                if (marker != null)
                {
                    marker.Dictionary.DrawMarker(marker.MarkerId, (int)marker.MarkerSideLength, out image, marker.MarkerBorderBits);
                }

                // In case of a grid board
                ArucoGridBoard arucoGridBoard = ArucoObject as ArucoGridBoard;

                if (arucoGridBoard != null)
                {
                    Aruco.GridBoard gridBoard = arucoGridBoard.Board as Aruco.GridBoard;
                    gridBoard.Draw(arucoGridBoard.ImageSize, out image, arucoGridBoard.MarginsSize, arucoGridBoard.MarkerBorderBits);
                }

                // In case of a charuco board
                ArucoCharucoBoard arucoCharucoBoard = ArucoObject as ArucoCharucoBoard;

                if (arucoCharucoBoard != null)
                {
                    Aruco.CharucoBoard charucoBoard = arucoCharucoBoard.Board as Aruco.CharucoBoard;
                    charucoBoard.Draw(arucoCharucoBoard.ImageSize, out image, arucoCharucoBoard.MarginsSize, arucoCharucoBoard.MarkerBorderBits);
                }

                // In case of a diamond
                ArucoDiamond diamond = ArucoObject as ArucoDiamond;

                if (diamond != null && diamond.Ids.Length == 4)
                {
                    Cv.Core.Vec4i ids = new Cv.Core.Vec4i();
                    for (int i = 0; i < diamond.Ids.Length; ++i)
                    {
                        ids.Set(i, diamond.Ids[i]);
                    }
                    Aruco.DrawCharucoDiamond(diamond.Dictionary, ids, (int)diamond.SquareSideLength, (int)diamond.MarkerSideLength, out image);
                }

                // Vertical flip to convert the image from Unity's left-handed coordinate system to OpenCV's right-handed coordinate system
                int verticalFlipCode = 0;

                Cv.Core.Flip(image, image, verticalFlipCode);

                // Set the properties
                Image = image;
                if (Image != null)
                {
                    int markerDataSize = (int)(Image.ElemSize() * Image.Total());
                    ImageTexture = new Texture2D(Image.cols, Image.rows, TextureFormat.RGB24, false);
                    ImageTexture.LoadRawTextureData(Image.dataIntPtr, markerDataSize);
                    ImageTexture.Apply();
                }
            }
Exemplo n.º 8
0
 public static void RefineDetectedMarkers(Cv.Core.Mat image, Board board, Std.VectorVectorPoint2f detectedCorners, Std.VectorInt detectedIds,
                                          Std.VectorVectorPoint2f rejectedCorners, Cv.Core.Mat cameraMatrix, Cv.Core.Mat distCoeffs, float minRepDistance)
 {
     Cv.Core.Exception exception = new Cv.Core.Exception();
     au_refineDetectedMarkers5(image.cppPtr, board.cppPtr, detectedCorners.cppPtr, detectedIds.cppPtr, rejectedCorners.cppPtr, cameraMatrix.cppPtr,
                               distCoeffs.cppPtr, minRepDistance, exception.cppPtr);
     exception.Check();
 }
Exemplo n.º 9
0
                public int GetDistanceToId(Dictionary dictionary, Cv.Core.Mat bits, int id)
                {
                    Cv.Core.Exception exception = new Cv.Core.Exception();
                    int distanceToId            = au_Dictionary_getDistanceToId2(cppPtr, bits.cppPtr, id, exception.cppPtr);

                    exception.Check();
                    return(distanceToId);
                }
Exemplo n.º 10
0
                public bool Identify(Dictionary dictionary, Cv.Core.Mat onlyBits, out int idx, out int rotation, double maxCorrectionRate)
                {
                    Cv.Core.Exception exception = new Cv.Core.Exception();
                    bool result = au_Dictionary_identify(cppPtr, onlyBits.cppPtr, out idx, out rotation, maxCorrectionRate, exception.cppPtr);

                    exception.Check();
                    return(result);
                }
Exemplo n.º 11
0
 public static void RefineDetectedMarkers(Cv.Core.Mat image, Board board, Std.VectorVectorPoint2f detectedCorners, Std.VectorInt detectedIds,
                                          Std.VectorVectorPoint2f rejectedCorners, Cv.Core.Mat cameraMatrix, Cv.Core.Mat distCoeffs, float minRepDistance, float errorCorrectionRate,
                                          bool checkAllOrders, Std.VectorInt recoveredIdxs)
 {
     Cv.Core.Exception exception = new Cv.Core.Exception();
     au_refineDetectedMarkers2(image.cppPtr, board.cppPtr, detectedCorners.cppPtr, detectedIds.cppPtr, rejectedCorners.cppPtr, cameraMatrix.cppPtr,
                               distCoeffs.cppPtr, minRepDistance, errorCorrectionRate, checkAllOrders, recoveredIdxs.cppPtr, exception.cppPtr);
     exception.Check();
 }
Exemplo n.º 12
0
                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();
                }
Exemplo n.º 13
0
                public void DrawMarker(int id, int sidePixels, out Cv.Core.Mat img, int borderBits)
                {
                    Cv.Core.Exception exception = new Cv.Core.Exception();
                    System.IntPtr     imgPtr;

                    au_Dictionary_drawMarker(cppPtr, id, sidePixels, out imgPtr, borderBits, exception.cppPtr);
                    img = new Cv.Core.Mat(imgPtr);

                    exception.Check();
                }
Exemplo n.º 14
0
                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();
                }
Exemplo n.º 15
0
            public static void DrawCharucoDiamond(Dictionary dictionary, Cv.Core.Vec4i ids, int squareLength, int markerLength, out Cv.Core.Mat image)
            {
                Cv.Core.Exception exception = new Cv.Core.Exception();
                System.IntPtr     imagePtr;

                au_drawCharucoDiamond3(dictionary.cppPtr, ids.cppPtr, squareLength, markerLength, out imagePtr, exception.cppPtr);
                image = new Cv.Core.Mat(imagePtr);

                exception.Check();
            }
Exemplo n.º 16
0
                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();
                }
Exemplo n.º 17
0
            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);
            }
Exemplo n.º 18
0
            public static void DetectMarkers(Cv.Core.Mat image, Dictionary dictionary, out Std.VectorVectorPoint2f corners, out Std.VectorInt ids)
            {
                Cv.Core.Exception exception = new Cv.Core.Exception();
                System.IntPtr     cornersPtr, idsPtr;

                au_detectMarkers3(image.cppPtr, dictionary.cppPtr, out cornersPtr, out idsPtr, exception.cppPtr);
                corners = new Std.VectorVectorPoint2f(cornersPtr);
                ids     = new Std.VectorInt(idsPtr);

                exception.Check();
            }
Exemplo n.º 19
0
            public static void DetectMarkers(Cv.Core.Mat image, Dictionary dictionary, out Std.VectorVectorPoint2f corners, out Std.VectorInt ids,
                                             DetectorParameters parameters, out Std.VectorVectorPoint2f rejectedImgPoints)
            {
                Cv.Core.Exception exception = new Cv.Core.Exception();
                System.IntPtr     cornersPtr, idsPtr, rejectedPtr;

                au_detectMarkers1(image.cppPtr, dictionary.cppPtr, out cornersPtr, out idsPtr, parameters.cppPtr, out rejectedPtr, exception.cppPtr);
                corners           = new Std.VectorVectorPoint2f(cornersPtr);
                ids               = new Std.VectorInt(idsPtr);
                rejectedImgPoints = new Std.VectorVectorPoint2f(rejectedPtr);

                exception.Check();
            }
Exemplo n.º 20
0
            public static void DetectCharucoDiamond(Cv.Core.Mat image, Std.VectorVectorPoint2f markerCorners, Std.VectorInt markerIds, float squareMarkerLengthRate,
                                                    out Std.VectorVectorPoint2f diamondCorners, out Std.VectorVec4i diamondIds)
            {
                Cv.Core.Exception exception = new Cv.Core.Exception();
                System.IntPtr     diamondCornersPtr, diamondIdsPtr;

                au_detectCharucoDiamond3(image.cppPtr, markerCorners.cppPtr, markerIds.cppPtr, squareMarkerLengthRate, out diamondCornersPtr,
                                         out diamondIdsPtr, exception.cppPtr);
                diamondCorners = new Std.VectorVectorPoint2f(diamondCornersPtr);
                diamondIds     = new Std.VectorVec4i(diamondIdsPtr);

                exception.Check();
            }
Exemplo n.º 21
0
                public unsafe Cv.Core.Mat[] Data()
                {
                    System.IntPtr *dataPtr = au_std_vectorMat_data(cppPtr);
                    uint           size    = Size();

                    Cv.Core.Mat[] data = new Cv.Core.Mat[size];
                    for (int i = 0; i < size; i++)
                    {
                        data[i] = new Cv.Core.Mat(dataPtr[i], DeleteResponsibility.False);
                    }

                    return(data);
                }
Exemplo n.º 22
0
            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)
            {
                Cv.Core.Exception exception = new Cv.Core.Exception();
                System.IntPtr     rvecsPtr;

                double reProjectionError = au_calibrateCameraAruco4(corners.cppPtr, ids.cppPtr, counter.cppPtr, board.cppPtr, imageSize.cppPtr, cameraMatrix.cppPtr,
                                                                    distCoeffs.cppPtr, out rvecsPtr, exception.cppPtr);

                rvecs = new Std.VectorMat(rvecsPtr);

                exception.Check();
                return(reProjectionError);
            }
Exemplo n.º 23
0
            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.Calib3d.Calib flags)
            {
                Cv.Core.Exception exception = new Cv.Core.Exception();
                System.IntPtr     rvecsPtr, tvecsPtr;

                double reProjectionError = au_calibrateCameraCharuco2(charucoCorners.cppPtr, charucoIds.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);
            }
Exemplo n.º 24
0
            public CameraParameters(int camerasNumber)
            {
                CalibrationDateTime = DateTime.Now;
                CamerasNumber       = camerasNumber;

                ImagesHeight         = new int[CamerasNumber];
                ImagesWidth          = new int[CamerasNumber];
                CamerasMatrix        = new Cv.Core.Mat[CamerasNumber];
                CamerasMatrixValues  = new double[CamerasNumber][][];
                DistCoeffs           = new Cv.Core.Mat[CamerasNumber];
                DistCoeffsValues     = new double[CamerasNumber][][];
                CamerasFocalLength   = new Vector2[CamerasNumber];
                CamerasOpticalCenter = new Vector2[CamerasNumber];
                OpticalCenters       = new Vector3[CamerasNumber];
            }
Exemplo n.º 25
0
            public static bool EstimatePoseCharucoBoard(Std.VectorPoint2f charucoCorners, Std.VectorInt charucoIds, CharucoBoard board, Cv.Core.Mat cameraMatrix,
                                                        Cv.Core.Mat distCoeffs, out Cv.Core.Vec3d rvec, out Cv.Core.Vec3d tvec)
            {
                Cv.Core.Exception exception = new Cv.Core.Exception();
                System.IntPtr     rvecPtr, tvecPtr;

                bool valid = au_estimatePoseCharucoBoard(charucoCorners.cppPtr, charucoIds.cppPtr, board.cppPtr, cameraMatrix.cppPtr, distCoeffs.cppPtr,
                                                         out rvecPtr, out tvecPtr, exception.cppPtr);

                rvec = new Cv.Core.Vec3d(rvecPtr);
                tvec = new Cv.Core.Vec3d(tvecPtr);

                exception.Check();
                return(valid);
            }
Exemplo n.º 26
0
 public static void DrawDetectedCornersCharuco(Cv.Core.Mat image, Std.VectorPoint2f charucoCorners, Std.VectorInt charucoIds, Cv.Core.Scalar cornerColor)
 {
     Cv.Core.Exception exception = new Cv.Core.Exception();
     au_drawDetectedCornersCharuco1(image.cppPtr, charucoCorners.cppPtr, charucoIds.cppPtr, cornerColor.cppPtr, exception.cppPtr);
     exception.Check();
 }
Exemplo n.º 27
0
 public static void DrawDetectedCornersCharuco(Cv.Core.Mat image, Std.VectorPoint2f charucoCorners)
 {
     Cv.Core.Exception exception = new Cv.Core.Exception();
     au_drawDetectedCornersCharuco3(image.cppPtr, charucoCorners.cppPtr, exception.cppPtr);
     exception.Check();
 }
Exemplo n.º 28
0
 public static void DrawDetectedDiamonds(Cv.Core.Mat image, Std.VectorVectorPoint2f diamondCorners, Std.VectorVec4i diamondIds, Cv.Core.Scalar borderColor)
 {
     Cv.Core.Exception exception = new Cv.Core.Exception();
     au_drawDetectedDiamonds1(image.cppPtr, diamondCorners.cppPtr, diamondIds.cppPtr, borderColor.cppPtr, exception.cppPtr);
     exception.Check();
 }
Exemplo n.º 29
0
            public static int InterpolateCornersCharuco(Std.VectorVectorPoint2f markerCorners, Std.VectorInt markerIds, Cv.Core.Mat image, CharucoBoard board,
                                                        out Std.VectorPoint2f charucoCorners, out Std.VectorInt charucoIds)
            {
                Cv.Core.Exception exception = new Cv.Core.Exception();
                System.IntPtr     charucoCornersPtr, charucoIdsPtr;

                int interpolateCorners = au_interpolateCornersCharuco3(markerCorners.cppPtr, markerIds.cppPtr, image.cppPtr, board.cppPtr,
                                                                       out charucoCornersPtr, out charucoIdsPtr, exception.cppPtr);

                charucoCorners = new Std.VectorPoint2f(charucoCornersPtr);
                charucoIds     = new Std.VectorInt(charucoIdsPtr);
                exception.Check();

                return(interpolateCorners);
            }
Exemplo n.º 30
0
 public static void DrawDetectedDiamonds(Cv.Core.Mat image, Std.VectorVectorPoint2f diamondCorners)
 {
     Cv.Core.Exception exception = new Cv.Core.Exception();
     au_drawDetectedDiamonds3(image.cppPtr, diamondCorners.cppPtr, exception.cppPtr);
     exception.Check();
 }