YARP
Yet Another Robot Platform
IntrinsicParams.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
7 #include <yarp/os/Time.h>
8 
9 using namespace yarp::sig;
10 
11 IntrinsicParams::IntrinsicParams(): physFocalLength(0.0),principalPointX(0.0),
12  principalPointY(0.0), focalLengthX(0.0), focalLengthY(0.0),
13  distortionModel(), isOptional(false) {}
14 
15 IntrinsicParams::IntrinsicParams(const yarp::os::Property &intrinsic, bool isOptional): isOptional(isOptional)
16 {
17  fromProperty(intrinsic);
18 }
19 
21 {
22  intrinsic.put("physFocalLength", physFocalLength);
23  intrinsic.put("focalLengthX", focalLengthX);
24  intrinsic.put("focalLengthY", focalLengthY);
25  intrinsic.put("principalPointX", principalPointX);
26  intrinsic.put("principalPointY", principalPointY);
27  intrinsic.put("stamp", yarp::os::Time::now());
28 
30  intrinsic.put("distortionModel", "none");
31  return;
32  }
33  intrinsic.put("distortionModel", "plumb_bob");
34  intrinsic.put("k1", distortionModel.k1);
35  intrinsic.put("k2", distortionModel.k2);
36  intrinsic.put("t1", distortionModel.t1);
37  intrinsic.put("t2", distortionModel.t2);
38  intrinsic.put("k3", distortionModel.k3);
39 }
40 
42 {
43  yAssert(intrinsic.check("focalLengthX") &&
44  intrinsic.check("focalLengthY") &&
45  intrinsic.check("principalPointX") &&
46  intrinsic.check("principalPointY"));
47  focalLengthX = intrinsic.find("focalLengthX").asFloat64();
48  focalLengthY = intrinsic.find("focalLengthY").asFloat64();
49  principalPointX = intrinsic.find("principalPointX").asFloat64();
50  principalPointY = intrinsic.find("principalPointY").asFloat64();
51 
52  // The physical focal length is optional
53  physFocalLength = intrinsic.check("physFocalLength", yarp::os::Value(0.0)).asFloat64();
54 
55  // The distortion parameters are optional
56  if (intrinsic.find("distortionModel").asString() != "plumb_bob") {
57  return;
58  }
60  distortionModel.k1 = intrinsic.check("k1", yarp::os::Value(0.0)).asFloat64();
61  distortionModel.k2 = intrinsic.check("k2", yarp::os::Value(0.0)).asFloat64();
62  distortionModel.t1 = intrinsic.check("t1", yarp::os::Value(0.0)).asFloat64();
63  distortionModel.t2 = intrinsic.check("t2", yarp::os::Value(0.0)).asFloat64();
64  distortionModel.k3 = intrinsic.check("k3", yarp::os::Value(0.0)).asFloat64();
65 }
66 
68  yarp::os::Property prop;
69  bool ok = prop.read(reader);
70  if (ok)
71  {
72  fromProperty(prop);
73  }
74  return ok;
75 }
77  yarp::os::Property prop;
78  toProperty(prop);
79  return prop.write(writer);
80 }
#define yAssert(x)
Definition: Log.h:294
An interface for reading from a network connection.
An interface for writing to a network connection.
A class for storing options and configuration information.
Definition: Property.h:34
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: Property.cpp:1051
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:1015
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Property.cpp:1041
bool write(ConnectionWriter &writer) const override
Write this object to a network connection.
Definition: Property.cpp:1134
bool read(ConnectionReader &reader) override
Read this object from a network connection.
Definition: Property.cpp:1122
A single value (typically within a Bottle).
Definition: Value.h:45
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:222
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition: Time.cpp:121
Signal processing.
Definition: Image.h:22
@ YARP_PLUMB_BOB
Plumb bob distortion model.
double focalLengthY
Result of the product of the physical focal length(mm) and the size sy of the individual imager eleme...
DistortionModel distortionModel
Distortion model of the image.
void fromProperty(const yarp::os::Property &intrinsic)
fromProperty, fill the struct using the data stored in a Property.
double focalLengthX
Result of the product of the physical focal length(mm) and the size sx of the individual imager eleme...
bool read(yarp::os::ConnectionReader &reader) override
Read this object from a network connection.
IntrinsicParams()
IntrinsicParams, default constructor.
double physFocalLength
Physical focal length of the lens (m)
void toProperty(yarp::os::Property &intrinsic) const
toProperty, convert the struct to a Property.
double principalPointX
Horizontal coordinate of the principal point of the image, as a pixel offset from the left edge.
bool write(yarp::os::ConnectionWriter &writer) const override
Write this object to a network connection.
double principalPointY
Vertical coordinate of the principal point of the image, as a pixel offset from the top edge.