latest version v1.9 - last update 10 Apr 2010 |
This class derives the 3D position of an object from a 2D image point. More...
#include <ltiDistanceFromPixel.h>
Classes | |
class | parameters |
The parameters for the class DistanceFromPixel. More... | |
Public Member Functions | |
DistanceFromPixel () | |
DistanceFromPixel (const parameters &par) | |
DistanceFromPixel (const DistanceFromPixel &other) | |
virtual | ~DistanceFromPixel () |
virtual const char * | getTypeName () const |
bool | apply (const vector< int > &src, vector< float > &dest) const |
bool | apply (const vector< int > &src, float &dest) const |
DistanceFromPixel & | copy (const DistanceFromPixel &other) |
DistanceFromPixel & | operator= (const DistanceFromPixel &other) |
virtual functor * | clone () const |
const parameters & | getParameters () const |
This class derives the 3D position of an object from a 2D image point.
Obviously we have to make some assumptions at first to get this to work.
First of all we are calculating the distance between a camera positioned at an arbitrary height and an object standing on a flat floor. We also assume that the optical axis of the camera is parallel to the floor.
Different parameters of the camera have to be known:
So here is some example code. The camera axis is not directly aligned along the axis on which the distance should be calculated. It is rotated a little bit down to the floor. Thus, we also have to use the class lti::coordinateTransformation:
lti::coordinateTransformation coordTransform; lti::coordinateTransformation::parameters transformParam; float b; float fDataDisplacement[3] = { 0, 0, -7}; lti::vector<float> vDisplace(3,fDataDisplacement); std::cout << "y angle of cam (beta):" << std::endl; std::cin >> b; transformParam.initParameters(0,b,0,vDisplace); coordTransform.setParameters(transformParam); lti::DistanceFromPixel distance; lti::DistanceFromPixel::parameters distanceParam; lti::vector<int> imgCoordinate(2,0); lti::vector<float> spaceCoordinate(3,0); // parameters for the Sony EVI D100P distanceParam.fHeight=41.0f; distanceParam.iPictureSizeX=379; // x distanceParam.iPictureSizeY=262; // y distanceParam.fD=19.07f; // focal length in cm distanceParam.fKx=0.0555f; // camera const in x-direction cm/pixel distanceParam.fKy=0.0555f; // camera const in y-direction cm/pixel std::cout << "x coordinate of object on floor in pixel (integer) :"; std::cin >> imgCoordinate[0]; std::cout << std::endl; std::cout << "y coordinate of object on floor in pixel (integer) :"; std::cin >> imgCoordinate[1]; std::cout << std::endl; distance.setParameters(distanceParam); distance.apply(imgCoordinate,spaceCoordinate); std::cout << "3D coordinates of object in camera system: " << spaceCoordinate << std::endl; float eucliddist=0; distance.apply(imgCoordinate,eucliddist); std::cout << "Euclidian distance between object and camera: " << eucliddist << std::endl; std::cout << "Point " << spaceCoordinate << " in the camera coordinate system" << std::endl; coordTransform.apply(spaceCoordinate); std::cout << "has position " << spaceCoordinate << " in the global coordinate system." << std::endl;
lti::DistanceFromPixel::DistanceFromPixel | ( | ) |
Default constructor.
lti::DistanceFromPixel::DistanceFromPixel | ( | const parameters & | par | ) |
Construct a functor using the given parameters.
lti::DistanceFromPixel::DistanceFromPixel | ( | const DistanceFromPixel & | other | ) |
Copy constructor.
other | the object to be copied |
virtual lti::DistanceFromPixel::~DistanceFromPixel | ( | ) | [virtual] |
Destructor.
bool lti::DistanceFromPixel::apply | ( | const vector< int > & | src, | |
float & | dest | |||
) | const |
This method calculates the euclidian distance between the 3D space position point of an image point and the camera.
The requirements needed for this to work are described above in the detailed description of this class.
src | lti::vector<int> src(2,0) | |
dest | float dest |
This method calculates the corresponding 3D space point from an 2D image point The requirements needed for this to work are described above in the detailed description of this class.
src | lti::vector<int> src(2,0) | |
dest | lti::vector<int> dest(3,0) |
virtual functor* lti::DistanceFromPixel::clone | ( | ) | const [virtual] |
Returns a pointer to a clone of this functor.
Implements lti::functor.
DistanceFromPixel& lti::DistanceFromPixel::copy | ( | const DistanceFromPixel & | other | ) |
Copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::functor.
const parameters& lti::DistanceFromPixel::getParameters | ( | ) | const |
Returns used parameters.
Reimplemented from lti::functor.
virtual const char* lti::DistanceFromPixel::getTypeName | ( | ) | const [virtual] |
Returns the name of this type ("DistanceFromPixel").
Reimplemented from lti::functor.
DistanceFromPixel& lti::DistanceFromPixel::operator= | ( | const DistanceFromPixel & | other | ) |