YARP
Yet Another Robot Platform
IntrinsicParams.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
10 #include <yarp/os/Time.h>
11 
12 using namespace yarp::sig;
13 
14 IntrinsicParams::IntrinsicParams(): physFocalLength(0.0),principalPointX(0.0),
15  principalPointY(0.0), focalLengthX(0.0), focalLengthY(0.0),
16  distortionModel(), isOptional(false) {}
17 
18 IntrinsicParams::IntrinsicParams(const yarp::os::Property &intrinsic, bool isOptional): isOptional(isOptional)
19 {
20  fromProperty(intrinsic);
21 }
22 
24 {
25  intrinsic.put("physFocalLength", physFocalLength);
26  intrinsic.put("focalLengthX", focalLengthX);
27  intrinsic.put("focalLengthY", focalLengthY);
28  intrinsic.put("principalPointX", principalPointX);
29  intrinsic.put("principalPointY", principalPointY);
30  intrinsic.put("stamp", yarp::os::Time::now());
31 
33  intrinsic.put("distortionModel", "none");
34  return;
35  }
36  intrinsic.put("distortionModel", "plumb_bob");
37  intrinsic.put("k1", distortionModel.k1);
38  intrinsic.put("k2", distortionModel.k2);
39  intrinsic.put("t1", distortionModel.t1);
40  intrinsic.put("t2", distortionModel.t2);
41  intrinsic.put("k3", distortionModel.k3);
42 }
43 
45 {
46  yAssert(intrinsic.check("focalLengthX") &&
47  intrinsic.check("focalLengthY") &&
48  intrinsic.check("principalPointX") &&
49  intrinsic.check("principalPointY"));
50  focalLengthX = intrinsic.find("focalLengthX").asFloat64();
51  focalLengthY = intrinsic.find("focalLengthY").asFloat64();
52  principalPointX = intrinsic.find("principalPointX").asFloat64();
53  principalPointY = intrinsic.find("principalPointY").asFloat64();
54 
55  // The physical focal length is optional
56  physFocalLength = intrinsic.check("physFocalLength", yarp::os::Value(0.0)).asFloat64();
57 
58  // The distortion parameters are optional
59  if (intrinsic.find("distortionModel").asString() != "plumb_bob") {
60  return;
61  }
63  distortionModel.k1 = intrinsic.check("k1", yarp::os::Value(0.0)).asFloat64();
64  distortionModel.k2 = intrinsic.check("k2", yarp::os::Value(0.0)).asFloat64();
65  distortionModel.t1 = intrinsic.check("t1", yarp::os::Value(0.0)).asFloat64();
66  distortionModel.t2 = intrinsic.check("t2", yarp::os::Value(0.0)).asFloat64();
67  distortionModel.k3 = intrinsic.check("k3", yarp::os::Value(0.0)).asFloat64();
68 }
69 
71  yarp::os::Property prop;
72  bool ok = prop.read(reader);
73  if (ok)
74  {
75  fromProperty(prop);
76  }
77  return ok;
78 }
80  yarp::os::Property prop;
81  toProperty(prop);
82  return prop.write(writer);
83 }
#define yAssert(x)
Definition: Log.h:297
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:37
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: Property.cpp:1034
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:998
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Property.cpp:1024
bool write(ConnectionWriter &writer) const override
Write this object to a network connection.
Definition: Property.cpp:1117
bool read(ConnectionReader &reader) override
Read this object from a network connection.
Definition: Property.cpp:1105
A single value (typically within a Bottle).
Definition: Value.h:47
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:225
virtual std::string asString() const
Get string value.
Definition: Value.cpp:237
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition: Time.cpp:124
Signal processing.
Definition: Image.h:25
@ YARP_PLUM_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.