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 
32  if (distortionModel.type != YarpDistortion::YARP_PLUM_BOB) {
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  }
62  distortionModel.type = YarpDistortion::YARP_PLUM_BOB;
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 }
yarp::sig::IntrinsicParams::principalPointY
double principalPointY
Vertical coordinate of the principal point of the image, as a pixel offset from the top edge.
Definition: IntrinsicParams.h:99
yarp::os::Property::put
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:998
yarp::sig
Signal processing.
Definition: Image.h:25
yarp::sig::IntrinsicParams::read
bool read(yarp::os::ConnectionReader &reader) override
Read this object from a network connection.
Definition: IntrinsicParams.cpp:70
yarp::os::Property::write
bool write(ConnectionWriter &writer) const override
Write this object to a network connection.
Definition: Property.cpp:1117
IntrinsicParams.h
yarp::sig::IntrinsicParams::DistortionModel::t2
double t2
Definition: IntrinsicParams.h:54
yarp::sig::IntrinsicParams::physFocalLength
double physFocalLength
Physical focal length of the lens (m)
Definition: IntrinsicParams.h:97
yarp::os::Property::find
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: Property.cpp:1034
yarp::sig::IntrinsicParams::DistortionModel::type
YarpDistortion type
Definition: IntrinsicParams.h:56
yarp::os::Time::now
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition: Time.cpp:124
yarp::sig::IntrinsicParams::focalLengthY
double focalLengthY
Result of the product of the physical focal length(mm) and the size sy of the individual imager eleme...
Definition: IntrinsicParams.h:101
yarp::sig::IntrinsicParams::DistortionModel::k1
double k1
Definition: IntrinsicParams.h:51
yarp::sig::IntrinsicParams::principalPointX
double principalPointX
Horizontal coordinate of the principal point of the image, as a pixel offset from the left edge.
Definition: IntrinsicParams.h:98
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::sig::IntrinsicParams::focalLengthX
double focalLengthX
Result of the product of the physical focal length(mm) and the size sx of the individual imager eleme...
Definition: IntrinsicParams.h:100
yarp::os::Value::asString
virtual std::string asString() const
Get string value.
Definition: Value.cpp:237
yarp::sig::IntrinsicParams::write
bool write(yarp::os::ConnectionWriter &writer) const override
Write this object to a network connection.
Definition: IntrinsicParams.cpp:79
yarp::sig::IntrinsicParams::fromProperty
void fromProperty(const yarp::os::Property &intrinsic)
fromProperty, fill the struct using the data stored in a Property.
Definition: IntrinsicParams.cpp:44
yarp::sig::IntrinsicParams::DistortionModel::k3
double k3
Definition: IntrinsicParams.h:55
yarp::os::Property::check
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Property.cpp:1024
yarp::sig::IntrinsicParams::IntrinsicParams
IntrinsicParams()
IntrinsicParams, default constructor.
Definition: IntrinsicParams.cpp:14
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::sig::IntrinsicParams::distortionModel
DistortionModel distortionModel
Distortion model of the image.
Definition: IntrinsicParams.h:102
yarp::sig::IntrinsicParams::DistortionModel::t1
double t1
Definition: IntrinsicParams.h:53
yarp::os::Property::read
bool read(ConnectionReader &reader) override
Read this object from a network connection.
Definition: Property.cpp:1105
yarp::sig::IntrinsicParams::toProperty
void toProperty(yarp::os::Property &intrinsic) const
toProperty, convert the struct to a Property.
Definition: IntrinsicParams.cpp:23
Time.h
yarp::sig::IntrinsicParams::DistortionModel::k2
double k2
Definition: IntrinsicParams.h:52
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::os::Value::asFloat64
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:225
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37