XmlParserCamera

class XmlParserCamera(self)

Bases: pybind11_object

XML parser to load and save intrinsic camera parameters.

To have a complete description of the camera parameters and the corresponding projection model implemented in ViSP, see vpCameraParameters .

Example of an XML file “myXmlFile.xml” containing intrinsic camera parameters:

<?xml version="1.0"?>
<root>
  <camera>
    <name>myCamera</name>
    <image_width>640</image_width>
    <image_height>480</image_height>
    <model>
      <type>perspectiveProjWithoutDistortion</type>
      <px>1129.0</px>
      <py>1130.6</py>
      <u0>317.9</u0>
      <v0>229.1</v0>
    </model>
    <model>
      <type>perspectiveProjWithDistortion</type>
      <px>1089.9</px>
      <py>1090.1</py>
      <u0>326.1</u0>
      <v0>230.5</v0>
      <kud>-0.196</kud>
      <kdu>0.204</kdu>
    </model>
  </camera>
</root>

Example of loading existing camera parameters from an XML file:

#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpXmlParserCamera.h>

int main()
{
  vpCameraParameters cam; // Create a camera parameter container
  vpXmlParserCamera p; // Create a XML parser
  vpCameraParameters::vpCameraParametersProjType projModel; // Projection model
  // Use a perspective projection model without distortion
  projModel = vpCameraParameters::perspectiveProjWithoutDistortion;
  // Parse the xml file "myXmlFile.xml" to find the intrinsic camera
  // parameters of the camera named "myCamera" for the image sizes 640x480,
  // for the projection model projModel. The size of the image is optional
  // if camera parameters are given only for one image size.
  if (p.parse(cam, "myXmlFile.xml", "myCamera", projModel,640,480) != vpXmlParserCamera::SEQUENCE_OK) {
   std::cout << "Cannot found myCamera" << std::endl;
  }

  // cout the parameters
  cam.printParameters();

  // Get the camera parameters for the model without distortion
  double px = cam.get_px();
  double py = cam.get_py();
  double u0 = cam.get_u0();
  double v0 = cam.get_v0();

  // Now we modify the principal point (u0,v0) for example to add noise
  u0 *= 0.9;
  v0 *= 0.8;

  // Set the new camera parameters
  cam.initPersProjWithoutDistortion(px, py, u0, v0);

  // Save the parameters in a new file "myXmlFileWithNoise.xml"
  p.save(cam,"myXmlFileWithNoise.xml",p.getCameraName(),p.getWidth(),p.getHeight());
}

Example of writing an XML file containing intrinsic camera parameters:

#include <visp3/core/vpCameraParameters.h>
#include <visp3/core/vpXmlParserCamera.h>

int main()
{
  // Create a camera parameter container. We want to set these parameters
  // for a 320x240 image, and we want to use the perspective projection
  // modelization without distortion.
  vpCameraParameters cam;

  // Set the principal point coordinates (u0,v0)
  double u0 = 162.3;
  double v0 = 122.4;
  // Set the pixel ratio (px, py)
  double px = 563.2;
  double py = 564.1;

  // Set the camera parameters for a model without distortion
  cam.initPersProjWithoutDistortion(px, py, u0, v0);

  // Create a XML parser
  vpXmlParserCamera p;
  // Save the camera parameters in an XML file.
  if (p.save(cam, "myNewXmlFile.xml", "myNewCamera", 320, 240) != vpXmlParserCamera::SEQUENCE_OK) {
    std::cout << "Cannot save camera parameters" << std::endl;
  }
}

Methods

__init__

getCameraName

getCameraParameters

getHeight

getSubsampling_height

getSubsampling_width

getWidth

parse

param cam:

Camera parameters to fill.

save

A typical usage would be the following:

setCameraName

setHeight

setSubsampling_height

setSubsampling_width

setWidth

Inherited Methods

Operators

__doc__

__init__

__module__

Attributes

SEQUENCE_ERROR

SEQUENCE_OK

__annotations__

class XmlCodeSequenceType(self, value: int)

Bases: pybind11_object

Values:

  • SEQUENCE_OK

  • SEQUENCE_ERROR

__and__(self, other: object) object
__eq__(self, other: object) bool
__ge__(self, other: object) bool
__getstate__(self) int
__gt__(self, other: object) bool
__hash__(self) int
__index__(self) int
__init__(self, value: int)
__int__(self) int
__invert__(self) object
__le__(self, other: object) bool
__lt__(self, other: object) bool
__ne__(self, other: object) bool
__or__(self, other: object) object
__rand__(self, other: object) object
__ror__(self, other: object) object
__rxor__(self, other: object) object
__setstate__(self, state: int) None
__xor__(self, other: object) object
property name : str
__init__(self)
getCameraName(self) str
getCameraParameters(self) visp._visp.core.CameraParameters
getHeight(self) int
getSubsampling_height(self) int
getSubsampling_width(self) int
getWidth(self) int
parse(self, cam: visp._visp.core.CameraParameters, filename: str, camera_name: str, projModel: visp._visp.core.CameraParameters.CameraParametersProjType, image_width: int = 0, image_height: int = 0, verbose: bool = true) int
Parameters:
cam: visp._visp.core.CameraParameters

Camera parameters to fill.

filename: str

Name of the xml file to parse.

projModel: visp._visp.core.CameraParameters.CameraParametersProjType

Camera projection model needed.

verbose: bool = true

true to enable verbose mode, false otherwise.

Returns:

vpXmlParserCamera::SEQUENCE_OK if success and vpXmlParserCamera::SEQUENCE_ERROR otherwise.

save(self: visp._visp.core.XmlParserCamera, cam: visp._visp.core.CameraParameters, filename: str, camera_name: str, image_width: int = 0, image_height: int = 0, additionalInfo: str =, verbose: bool = true) int

A typical usage would be the following:

#include <visp3/core/vpTime.h>
#include <visp3/core/vpXmlParserCamera.h>

int main()
{
  vpCameraParameters cam;
  std::stringstream ss_additional_info;
  ss_additional_info << "<date>" << vpTime::getDateTime() << "</date>";

  vpXmlParserCamera p;
  if (p.save(cam, "camera.xml", "myCamera", 320, 240, ss_additional_info.str()) != vpXmlParserCamera::SEQUENCE_OK) {
    std::cout << "Cannot save camera parameters" << std::endl;
  }
}

In camera.xml file, you will see:

<camera>
  ...
  <!--Additional information-->
  <additional_information>
    <date>2016/06/10 09:15:56</date>
  </additional_information>
</camera>
Parameters:
cam

Camera parameters to save.

filename

Name of the xml file to fill.

additionalInfo

Additional information added in the saved xml file. The content of this string should be in xml format.

verbose

true to enable verbose mode, false otherwise.

Returns:

error code.

setCameraName(self, name: str) None
setHeight(self, height: int) None
setSubsampling_height(self, subsampling: int) None
setSubsampling_width(self, subsampling: int) None
setWidth(self, width: int) None