create_board.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <opencv2/highgui.hpp>
  2. #include <opencv2/objdetect/aruco_detector.hpp>
  3. #include <iostream>
  4. #include "aruco_samples_utility.hpp"
  5. using namespace cv;
  6. namespace {
  7. const char* about = "Create an ArUco grid board image";
  8. const char* keys =
  9. "{@outfile |<none> | Output image }"
  10. "{w | | Number of markers in X direction }"
  11. "{h | | Number of markers in Y direction }"
  12. "{l | | Marker side length (in pixels) }"
  13. "{s | | Separation between two consecutive markers in the grid (in pixels)}"
  14. "{d | | dictionary: DICT_4X4_50=0, DICT_4X4_100=1, DICT_4X4_250=2,"
  15. "DICT_4X4_1000=3, DICT_5X5_50=4, DICT_5X5_100=5, DICT_5X5_250=6, DICT_5X5_1000=7, "
  16. "DICT_6X6_50=8, DICT_6X6_100=9, DICT_6X6_250=10, DICT_6X6_1000=11, DICT_7X7_50=12,"
  17. "DICT_7X7_100=13, DICT_7X7_250=14, DICT_7X7_1000=15, DICT_ARUCO_ORIGINAL = 16}"
  18. "{cd | | Input file with custom dictionary }"
  19. "{m | | Margins size (in pixels). Default is marker separation (-s) }"
  20. "{bb | 1 | Number of bits in marker borders }"
  21. "{si | false | show generated image }";
  22. }
  23. int main(int argc, char *argv[]) {
  24. CommandLineParser parser(argc, argv, keys);
  25. parser.about(about);
  26. if(argc < 7) {
  27. parser.printMessage();
  28. return 0;
  29. }
  30. int markersX = parser.get<int>("w");
  31. int markersY = parser.get<int>("h");
  32. int markerLength = parser.get<int>("l");
  33. int markerSeparation = parser.get<int>("s");
  34. int margins = markerSeparation;
  35. if(parser.has("m")) {
  36. margins = parser.get<int>("m");
  37. }
  38. int borderBits = parser.get<int>("bb");
  39. bool showImage = parser.get<bool>("si");
  40. String out = parser.get<String>(0);
  41. if(!parser.check()) {
  42. parser.printErrors();
  43. return 0;
  44. }
  45. Size imageSize;
  46. imageSize.width = markersX * (markerLength + markerSeparation) - markerSeparation + 2 * margins;
  47. imageSize.height =
  48. markersY * (markerLength + markerSeparation) - markerSeparation + 2 * margins;
  49. aruco::Dictionary dictionary = readDictionatyFromCommandLine(parser);
  50. aruco::GridBoard board(Size(markersX, markersY), float(markerLength), float(markerSeparation), dictionary);
  51. // show created board
  52. //! [aruco_generate_board_image]
  53. Mat boardImage;
  54. board.generateImage(imageSize, boardImage, margins, borderBits);
  55. //! [aruco_generate_board_image]
  56. if(showImage) {
  57. imshow("board", boardImage);
  58. waitKey(0);
  59. }
  60. imwrite(out, boardImage);
  61. return 0;
  62. }