1

as the title, I need to serialize to file a custom created dictionary from arUco library using OpenCV 3.x (the version 3 is strict).

Second step is to load again the dictionary from file.

I could not find examples online or had a partial success.

Any help is appreciated!

N Dorigatti
  • 3,482
  • 2
  • 22
  • 33
  • 2
    The dictionary is just a class with three public members: `Mat bytesList`, `int markerSize`, `int maxCorrectionBits`. Can't you just save and load them in/from a `FileStorage`? – Miki Feb 09 '16 at 14:24

1 Answers1

4

Use this code to save:

int number= 10, dimension=7;
cv::aruco::Dictionary dictionary = cv::aruco::generateCustomDictionary(number, dimension);
cv::Mat store=dictionary.bytesList;
cv::FileStorage fs("dic_save.yml", cv::FileStorage::WRITE);
fs << "MarkerSize" << dictionary.markerSize;
fs << "MaxCorrectionBits" << dictionary.maxCorrectionBits;
fs << "ByteList" << dictionary.bytesList;
fs.release();

Use this code to read:

cv::FileStorage fsr("dic_save.yml", cv::FileStorage::READ);
int mSize, mCBits;
cv::Mat bits;
fsr["MarkerSize"] >> mSize;
fsr["MaxCorrectionBits"] >> mCBits;
fsr["ByteList"] >> bits;
fsr.release();
cv::aruco::Dictionary dic = cv::aruco::Dictionary(bits, mSize, mCBits);
Michel de Ruiter
  • 7,131
  • 5
  • 49
  • 74