fehlfarbe / python-aruco

Python wrappers for ArUco library
Other
66 stars 16 forks source link

How to set camera parameters not from a file #4

Closed miguelriemoliveira closed 7 years ago

miguelriemoliveira commented 7 years ago

Hello,

To set the camera parameters in your example.py you do

camparam = aruco.CameraParameters()
camparam.readFromXMLFile("dfk72_6mm_param2.yml")

I was trying to set the camera parameters, i.e., image size, distorsion and intrinsics not as in the example but using some function. I searched and found the function setParams from the class CameraParameters (line 124 of aruco.py).

The problem was I tried to use that function in several ways but could never get it to work.

Could you give me an example of how to set the camera parameters directly from the code?

Thanks in advance,

Miguel

BTW, I am sorry because I am a bit of a newbie with these python bindings. Perhaps there is an easy solution.

fehlfarbe commented 7 years ago

Hi Miguel,

just create the CameraMatrix, Distortion and Size numpy arrays with the right shape and use the CameraParameters constructor or setParams method:

import numpy as np
import aruco

cm = np.array([1.0, 1.0, 1.0,
                        1.0, 1.0, 1.0,
                        1.0, 1.0, 1.0]).reshape((3, 3))
dist = np.array([1.0, 1.0, 1.0, 1.0, 1.0]).reshape((1, 5))
size = np.array([800, 600])
camparam = aruco.CameraParameters(cm, dist, size)
camparam.setParams(cm, dist, size)

Be sure that the values in cm and dist are double/float.

miguelriemoliveira commented 7 years ago

Hello Fehlfarbe,

Thanks for the help.

I will try it out as soon as possible.

Best regards,

Miguel