private void CalcChessboardCorners(Size patternSize, float squareSize, MatOfPoint3f corners, int markerType) { if ((int)(patternSize.width * patternSize.height) != corners.rows()) { Debug.Log("Invalid corners size."); corners.create((int)(patternSize.width * patternSize.height), 1, CvType.CV_32FC3); } const int cn = 3; float[] cornersArr = new float[corners.rows() * cn]; int width = (int)patternSize.width; int height = (int)patternSize.height; switch (markerType) { case (int)MarkerType.ChessBoard: case (int)MarkerType.CirclesGlid: for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { cornersArr [(i * width * cn) + (j * cn)] = j * squareSize; cornersArr [(i * width * cn) + (j * cn) + 1] = i * squareSize; cornersArr [(i * width * cn) + (j * cn) + 2] = 0; } } corners.put(0, 0, cornersArr); break; case (int)MarkerType.AsymmetricCirclesGlid: for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { cornersArr [(i * width * cn) + (j * cn)] = (2 * j + i % 2) * squareSize; cornersArr [(i * width * cn) + (j * cn) + 1] = i * squareSize; cornersArr [(i * width * cn) + (j * cn) + 2] = 0; } } corners.put(0, 0, cornersArr); break; default: Debug.Log("Unknown marker type."); break; } }