35 #include <Geometry/ProjectionParametersPerspective.hh>
36 #include <Base/Image/Image.hh>
37 #include <Base/Image/ImageIO.hh>
38 #include <Base/Math/Random.hh>
39 #include <Base/Geometry/HomgPoint2D.hh>
40 #include <Utils/ThreeDOut.hh>
46 int main(
int argc,
char *argv[]) {
98 unsigned int numTests = 1;
99 for (
unsigned int tests=0; tests<numTests; tests++) {
113 R.
SetXYZ(30.0*M_PI/180.0, 3.0*M_PI/180.0, 0.0);
129 double ImgWidth = 300;
130 double ImgHeight = 300;
134 K.
SetFy(focalX*aspectrat);
143 cout <<
"K " << K << endl;
144 cout <<
"R " << R << endl;
145 cout <<
"C " << C << endl;
146 cout <<
"P " << P << endl;
157 vector<HomgPoint3D> points3D;
158 vector<double> zCorr;
160 for (
int i = 0; i < numPoints; i++) {
165 zCorr.push_back(temp3D[2]);
166 points3D.push_back(temp3D);
170 vector<HomgPoint2D> points2D;
172 for (
int i = 0; i < numPoints; i++) {
173 temp2D = ppp.
Project(points3D[i],
true);
176 points2D.push_back(temp2D);
180 vector<HomgPoint3D> unprojectRay, backprojectZDepth, backprojectWorldCoo;
182 vector<double> depth;
183 double errorSum = 0.0;
184 double errorSum2 = 0.0;
188 double zTemp, depthTemp;
189 for (
int j = 0; j < numPoints; j++) {
195 ray[0] *= zCorr[j] / ray[2];
196 ray[1] *= zCorr[j] / ray[2];
197 ray[2] *= zCorr[j] / ray[2];
202 unprojectRay.push_back(ray);
205 errorSum += (ray - points3D[j]).NormL2();
207 cout <<
"ray[2] == 0 for point " << j <<
" " << ray << endl;
216 camPointTemp = withoutK * points3D[j];
217 zTemp = camPointTemp[2];
220 backprojectZDepth.push_back(temp3D);
221 errorSum2 += (temp3D - points3D[j]).NormL2();
224 temp2D = points2D[j];
225 temp2D[0] -= principalX;
226 temp2D[1] = principalY - temp2D[1];
227 temp2D = K.
Invert() * temp2D;
228 depthTemp = sqrt(sqrt(camPointTemp[0]*camPointTemp[0] - temp2D[1]*temp2D[1]) - temp2D[0]*temp2D[0]);
229 if(depthTemp!=depthTemp) depthTemp = 1.0;
233 backprojectWorldCoo.push_back(temp3D);
235 backprojectWorldCoo.push_back(
HomgPoint3D(0,0,0,1));
236 cout <<
"problem with temp3D[2] " << temp3D << endl;
238 cout <<
"point : " << j << backprojectWorldCoo[j] << endl;
241 cout <<
"error sum " << errorSum << endl;
242 cout <<
"error sum 2 " << errorSum2 << endl;
253 for (
int i = 0; i < numPoints; i++) {
254 points3D[i].Homogenize();
255 threeDOut.AddPoint(points3D[i],
RGBAuc(255, 0, 0, 127));
257 unprojectRay[i].Homogenize();
258 threeDOut.AddPoint(unprojectRay[i],
RGBAuc(0, 255, 255, 127));
260 backprojectZDepth[i].Homogenize();
261 threeDOut.AddPoint(backprojectZDepth[i],
RGBAuc(255, 0, 255, 127));
263 backprojectWorldCoo[i].Homogenize();
264 threeDOut.AddPoint(backprojectWorldCoo[i],
RGBAuc(255, 255, 255, 127));
272 threeDOut.AddLine(start, end,
RGBAuc(255, 0, 0, 127));
273 end.Set(0.0, 1.0, 0.0);
274 threeDOut.AddLine(start, end,
RGBAuc(0, 255, 0, 127));
275 end.Set(0.0, 0.0, 1.0);
276 threeDOut.AddLine(start, end,
RGBAuc(0, 0, 255, 127));
277 threeDOut.VRMLOut(
"test.wrl");
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
void SetXYZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XYZ.
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
Unified output of 3D entities via OpenGL or VRML.
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
void Homogenize()
homogenize class data member elements to W==1 by divison by W
configuration struct for drawing styles of various 3d objects
void SetSkew(const KMATRIX_TYPE &val)
virtual void SetP(const PMatrix &P)
set from P
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
void SetIdealImageSize(unsigned int width, unsigned int height)
virtual void UnProjectToRay(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool ignoreDistortion=false) const
Calculates the view ray, which belongs to the given position on the image plane, in global coordinate...
CameraDrawingStyle CameraStyle
virtual HomgPoint2D Project(const HomgPoint3D &X, bool IgnoreDistortion=false) const
calculates the projection of a point in the world coordinate system to a pixel in the image plane of ...
bool DrawUncertaintyEllipsoids
void InvalidateDecomposition()
to re-Decompose_() after filling with data use this.
LineDrawingStyle LineStyle
BIAS::Vector4< unsigned char > RGBAuc
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
void SetFx(const KMATRIX_TYPE &val)
void SetHy(const KMATRIX_TYPE &val)
void SetFy(const KMATRIX_TYPE &val)
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
void BackprojectWorldCoo(const HomgPoint2D &point, double depth, HomgPoint3D &res)
returns a 3D point res which is located depth away from center of projection in direction given by po...
double GetNormalDistributed(const double mean, const double sigma)
on succesive calls return normal distributed random variable with mean and standard deviation sigma ...
describes a projective 3D -> 2D mapping in homogenous coordinates
void BackprojectByZDepth(const double &x, const double &y, const double &z_depth, HomgPoint3D &res)
Inverts the PMatrix application to a 3D point whose z-component in cameracoordinates and its imagepoi...
PointDrawingStyle PointStyle
void SetHx(const KMATRIX_TYPE &val)
KMatrix Invert() const
returns analyticaly inverted matrix
class for producing random numbers from different distributions
void Compose(const Matrix3x3< double > &K, const Matrix3x3< double > &R, const Vector3< double > &C)
composes this from K, R and C using P = [ K R' | -K R' C ] with R' = transpose(R) ...
class BIASGeometryBase_EXPORT HomgPoint3D