0

So I try to save a cv Dictionary in a file, because I access a the python function via Matlab and it always generates the same Dictionary when I call the function. So I want to safe the Dictionary in a file, where I can access it from python without generating it first.

I saw this post Reading cv2.aruco.Dictionary from a yaml file issue and the saving works, but when I tried the code which is commend below in the post:

import cv2
import numpy as np
import json


aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_100)

with open('DictionaryFile.yml', "w") as FILE:
    FILE.write(json.dumps({
        "marker_size" : aruco_dict.markerSize,
        "bytes_list": aruco_dict.bytesList.tolist(),
        "max_corr": aruco_dict.maxCorrectionBits,
    }, indent=4))


with open('DictionaryFile.yml', "r") as FILE:
    data = json.loads(FILE.read())
    loaded_bytes = np.array(data["bytes_list"], dtype=np.uint8)
    loaded_dict = cv2.aruco.Dictionary(
        len(loaded_bytes),
        data["marker_size"],
        data["max_corr"]
    )
    loaded_dict.bytesList = loaded_bytes

and I get this error: loaded_dict.bytesList = loaded_bytes cv2.error: Conversion error: value How do I solve this conversion problem?

fmw42
  • 46,825
  • 10
  • 62
  • 80

0 Answers0