Writing camera matrix to xml/yaml file [closed]
I have calibrated my camera having the following parameters:
camera_matrix=[[ 532.80990646 ,0.0,342.49522219],[0.0,532.93344713,233.88792491],[0.0,0.0,1.0]] dist_coeff = [-2.81325798e-01,2.91150014e-02,1.21234399e-03,-1.40823665e-04,1.54861424e-01]
I am working in python.I wrote the following code to save the above into a file but the file was like a normal text file.
f = open("C:\Users\Administrator\Desktop\calibration_camera.xml","w")
f.write('Camera Matrix:\n'+str(camera_matrix))
f.write('\n')
f.write('Distortion Coefficients:\n'+str(dist_coefs))
f.write('\n')
f.close()
How can i save this data into an xml/yaml file using python commands.Please help. Thanks in advance
since there's no support for the FileStorage api in python - don't bother with yml/xml, write a simple (numbers only) text file (and read it back in later yourself.)
Thanks. eventually i did write it in yaml
Since i cannot answer my own question i am commenting the solution. import yaml data = {"<name>":var_name,"<name2>":var_name2...and so on} fname ="abc.yaml" with open(fname,"w") as f: yaml.dump(data,f)