Visual Servoing Platform  version 3.2.1 under development (2019-04-21)
vpXmlParserCamera Class Reference

#include <visp3/core/vpXmlParserCamera.h>

Public Types

enum  vpXmlCodeSequenceType { SEQUENCE_OK, SEQUENCE_ERROR }
 

Public Member Functions

 vpXmlParserCamera ()
 
 ~vpXmlParserCamera ()
 
std::string getCameraName () const
 
vpCameraParameters getCameraParameters () const
 
unsigned int getHeight () const
 
unsigned int getSubsampling_width () const
 
unsigned int getSubsampling_height () const
 
unsigned int getWidth () const
 
int parse (vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const vpCameraParameters::vpCameraParametersProjType &projModel, const unsigned int image_width=0, const unsigned int image_height=0)
 
int save (const vpCameraParameters &cam, const std::string &filename, const std::string &camera_name, const unsigned int image_width=0, const unsigned int image_height=0, const std::string &additionalInfo="")
 
void setCameraName (const std::string &name)
 
void setHeight (const unsigned int height)
 
void setSubsampling_width (const unsigned int subsampling)
 
void setSubsampling_height (const unsigned int subsampling)
 
void setWidth (const unsigned int width)
 

Detailed Description

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
#ifdef VISP_HAVE_PUGIXML
vpXmlParserCamera p; // Create a XML parser
model
// Use a perspective projection model without distortion
// 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
// 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());
#endif
}

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
// modelisation without distortion.
// 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);
#ifdef VISP_HAVE_PUGIXML
// Create a XML parser
// 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;
}
#endif
}
Examples:
mbot-apriltag-2D-half-vs.cpp, mbot-apriltag-ibvs.cpp, mbot-apriltag-pbvs.cpp, tutorial-apriltag-detector-live.cpp, tutorial-apriltag-detector.cpp, tutorial-chessboard-pose.cpp, tutorial-franka-acquire-calib-data.cpp, tutorial-mb-generic-tracker-apriltag-live-webcam.cpp, tutorial-mb-generic-tracker-live.cpp, tutorial-pose-from-points-live.cpp, and tutorial-undistort.cpp.

Definition at line 172 of file vpXmlParserCamera.h.

Member Enumeration Documentation

Enumerator
SEQUENCE_OK 
SEQUENCE_ERROR 

Definition at line 175 of file vpXmlParserCamera.h.

Constructor & Destructor Documentation

vpXmlParserCamera::vpXmlParserCamera ( )

Definition at line 944 of file vpXmlParserCamera.cpp.

vpXmlParserCamera::~vpXmlParserCamera ( )

Definition at line 948 of file vpXmlParserCamera.cpp.

Member Function Documentation

std::string vpXmlParserCamera::getCameraName ( ) const

Definition at line 1024 of file vpXmlParserCamera.cpp.

vpCameraParameters vpXmlParserCamera::getCameraParameters ( ) const

Definition at line 1029 of file vpXmlParserCamera.cpp.

unsigned int vpXmlParserCamera::getHeight ( ) const

Definition at line 1034 of file vpXmlParserCamera.cpp.

unsigned int vpXmlParserCamera::getSubsampling_height ( ) const

Definition at line 1044 of file vpXmlParserCamera.cpp.

unsigned int vpXmlParserCamera::getSubsampling_width ( ) const

Definition at line 1039 of file vpXmlParserCamera.cpp.

unsigned int vpXmlParserCamera::getWidth ( ) const

Definition at line 1049 of file vpXmlParserCamera.cpp.

int vpXmlParserCamera::parse ( vpCameraParameters cam,
const std::string &  filename,
const std::string &  cam_name,
const vpCameraParameters::vpCameraParametersProjType projModel,
const unsigned int  im_width = 0,
const unsigned int  im_height = 0 
)

Parse an xml file to load camera parameters.

Parameters
cam: camera parameters to fill.
filename: name of the xml file to parse
cam_name: name of the camera : useful if the xml file has multiple camera parameters. Set as "" if the camera name is not ambiguous.
projModel: camera projection model needed.
im_width: image width on which camera calibration was performed. Set as 0 if not ambiguous.
im_height: image height on which camera calibration was performed. Set as 0 if not ambiguous.
Returns
vpXmlParserCamera::SEQUENCE_OK if success and vpXmlParserCamera::SEQUENCE_ERROR otherwise.
Examples:
mbot-apriltag-2D-half-vs.cpp, mbot-apriltag-ibvs.cpp, mbot-apriltag-pbvs.cpp, tutorial-apriltag-detector-live.cpp, tutorial-apriltag-detector.cpp, tutorial-chessboard-pose.cpp, tutorial-mb-generic-tracker-apriltag-live-webcam.cpp, tutorial-mb-generic-tracker-live.cpp, and tutorial-undistort.cpp.

Definition at line 967 of file vpXmlParserCamera.cpp.

Referenced by vpViper650::getCameraParameters(), vpViper850::getCameraParameters(), vpAfma6::getCameraParameters(), and vpKinect::start().

int vpXmlParserCamera::save ( const vpCameraParameters cam,
const std::string &  filename,
const std::string &  cam_name,
const unsigned int  im_width = 0,
const unsigned int  im_height = 0,
const std::string &  additionalInfo = "" 
)

Save camera parameters in an xml file.

Parameters
cam: camera parameters to save.
filename: name of the xml file to fill.
cam_name: name of the camera : useful if the xml file has multiple camera parameters. Set as "" if the camera name is not ambiguous.
im_width: width of image on which camera calibration was performed. Set as 0 if not ambiguous.
im_height: height of the image on which camera calibration was performed. Set as 0 if not ambiguous.
additionalInfo: Additional information added in the saved xml file. The content of this string should be in xml format.
Returns
error code.

A typical usage would be the following:

#include <visp3/core/vpTime.h>
#include <visp3/core/vpXmlParserCamera.h>
int main()
{
std::stringstream ss_additional_info;
ss_additional_info << "<date>" << vpTime::getDateTime() << "</date>";
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>
Examples:
tutorial-franka-acquire-calib-data.cpp.

Definition at line 1017 of file vpXmlParserCamera.cpp.

void vpXmlParserCamera::setCameraName ( const std::string &  name)

Definition at line 1054 of file vpXmlParserCamera.cpp.

void vpXmlParserCamera::setHeight ( const unsigned int  height)

Definition at line 1059 of file vpXmlParserCamera.cpp.

void vpXmlParserCamera::setSubsampling_height ( const unsigned int  subsampling)

Definition at line 1069 of file vpXmlParserCamera.cpp.

void vpXmlParserCamera::setSubsampling_width ( const unsigned int  subsampling)

Definition at line 1064 of file vpXmlParserCamera.cpp.

void vpXmlParserCamera::setWidth ( const unsigned int  width)

Definition at line 1074 of file vpXmlParserCamera.cpp.