Commit acca22a9 authored by Davis King's avatar Davis King

Made the camera_transform output the point's distance.

parent 1294d6d3
...@@ -853,13 +853,14 @@ namespace dlib ...@@ -853,13 +853,14 @@ namespace dlib
inline dpoint operator() ( inline dpoint operator() (
const vector<double>& p, const vector<double>& p,
double& scale double& scale,
double& distance
) const ) const
{ {
vector<double> temp = p-camera_pos; vector<double> temp = p-camera_pos;
temp = proj*temp; temp = proj*temp;
const double distance = temp.z()>0 ? temp.z() : 1e-9; distance = temp.z();
scale = dist_scale/distance; scale = dist_scale/(temp.z()>0 ? temp.z() : 1e-9);
temp.x() = temp.x()*scale + width; temp.x() = temp.x()*scale + width;
temp.y() = temp.y()*scale + width; temp.y() = temp.y()*scale + width;
return temp; return temp;
...@@ -869,8 +870,8 @@ namespace dlib ...@@ -869,8 +870,8 @@ namespace dlib
const vector<double>& p const vector<double>& p
) const ) const
{ {
double scale; double scale, distance;
return (*this)(p,scale); return (*this)(p,scale,distance);
} }
inline friend void serialize (const camera_transform& item, std::ostream& out) inline friend void serialize (const camera_transform& item, std::ostream& out)
......
...@@ -644,7 +644,8 @@ namespace dlib ...@@ -644,7 +644,8 @@ namespace dlib
dpoint operator() ( dpoint operator() (
const vector<double>& p, const vector<double>& p,
double& scale double& scale,
double& distance
) const; ) const;
/*! /*!
ensures ensures
...@@ -654,6 +655,9 @@ namespace dlib ...@@ -654,6 +655,9 @@ namespace dlib
- #scale == a number that tells you how large things are at the point p. - #scale == a number that tells you how large things are at the point p.
Objects further from the camera appear smaller, in particular, they Objects further from the camera appear smaller, in particular, they
appear #scale times their normal size. appear #scale times their normal size.
- #distance == how far away the point is from the image plane. Objects in
front of the camera will have a positive distance and those behind a
negative distance.
!*/ !*/
vector<double> get_camera_pos( vector<double> get_camera_pos(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment