Writing camera matrix to xml/yaml file [closed]

asked 2014-04-30 15:13:51 -0500

user6789 gravatar image

updated 2014-05-02 04:32:30 -0500

berak gravatar image

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('Distortion Coefficients:\n'+str(dist_coefs))



How can i save this data into an xml/yaml file using python commands.Please help. Thanks in advance

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2017-08-22 11:11:06.064372


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.)

berak gravatar imageberak ( 2014-05-02 04:35:12 -0500 )edit

Thanks. eventually i did write it in yaml

user6789 gravatar imageuser6789 ( 2014-05-23 17:09:12 -0500 )edit

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)

user6789 gravatar imageuser6789 ( 2014-05-30 07:14:29 -0500 )edit