35 #include <Base/Image/ImageIO.hh>
36 #include <Base/ImageUtils/ImageDraw.hh>
37 #include <Base/Image/ImageConvert.hh>
38 #include <Image/Camera.hh>
40 #include <Utils/Param.hh>
41 #include <Utils/TriangleMesh.hh>
42 #include <GLviewer/ThreeDOutOpenSceneGraph.hh>
55 cout <<
"Usage: biasVrmlOutCameraGeometry --projsList projs.lst --texList tex.lst --points3D points3D.txt --projectPoint true"<<endl
57 cout <<
" The tool creates a vrml file with the projections drawn as mesh cameras. " << endl
58 <<
" If specified, it can add textures as images into the cameras, add 3D points to the scene " << endl
59 <<
" and project these 3D points into the images. If drawRays is set to true rays from cam center through 2D point" << endl
60 <<
" to 3D point will be drawn. " << endl
61 <<
" ATTENTION: if projections are set in texture meta data projection list will be ignored!!! " << endl
62 <<
" In case the image should be just white instead of having a texture, set texList to WHITE." << endl
63 <<
" If the image should be black, set texList to BLACK."<< endl
64 <<
" If projsList is set to manualProjs.projection, a params file for projections can be given in the form: " << endl
65 <<
" width height " << endl
66 <<
" focalLength " << endl
67 <<
" centerX_1 centerY_1 centerZ_1 phiX_1 phiY_1 phiZ_1 " << endl
68 <<
" centerX_2 centerY_2 centerZ_2 phiX_2 phiY_2 phiZ_2 " << endl
70 <<
" ATTENTION: in this case texList must either be set to WHITE or BLACK." << endl
71 <<
" ATTENTION: angles are specified in degrees." << endl
72 <<
" See bottom of tool implementation for example files with points and manual cams. " << endl
73 <<
" ATTENTION: only works with unsigned char textures for now." << endl
78 void readPoints(
string& pointsFile, vector<HomgPoint3D>& points3D){
81 filestr.open(pointsFile.c_str(), std::fstream::in);
87 while (!filestr.eof()) {
91 if(x != -100.0 && y !=-100.0 && z != -100.0){
92 cout <<
"read point " << x <<
" " << y <<
" " << z << endl;
103 void parseManualProjections(vector<Projection>& projs){
105 std::fstream filestr;
106 filestr.open(
string(
"manualProjs.projection").c_str(), std::fstream::in);
110 unsigned int width, height;
114 double phiX, phiY, phiZ;
118 filestr >> focalLength;
120 cout <<
"read width " << width <<
" height " << height <<
" focal length " << focalLength << endl;
134 while (!filestr.eof()) {
141 if(x != -100.0 && y !=-100.0 && z != -100.0){
142 cout <<
"read center " << x <<
" " << y <<
" " << z << endl;
143 cout <<
"read rotation " << phiX <<
" " << phiY <<
" " << phiZ << endl;
149 q.
SetXYZ(phiX/180.0*M_PI, phiY/180.0*M_PI, phiZ/180.0*M_PI);
152 projection.
SetC(center);
154 cout <<
"finished projection " << projection << endl;
155 projs.push_back(projection);
170 void createColors(vector<unsigned char>& reds, vector<unsigned char>& greens, vector<unsigned char>& blues){
177 reds.push_back((
unsigned char)200);
178 greens.push_back((
unsigned char)0);
179 blues.push_back((
unsigned char)0);
182 reds.push_back((
unsigned char)0);
183 greens.push_back((
unsigned char)200);
184 blues.push_back((
unsigned char)0);
187 reds.push_back((
unsigned char)0);
188 greens.push_back((
unsigned char)0);
189 blues.push_back((
unsigned char)200);
192 reds.push_back((
unsigned char)200);
193 greens.push_back((
unsigned char)200);
194 blues.push_back((
unsigned char)0);
197 reds.push_back((
unsigned char)200);
198 greens.push_back((
unsigned char)0);
199 blues.push_back((
unsigned char)200);
202 reds.push_back((
unsigned char)0);
203 greens.push_back((
unsigned char)200);
204 blues.push_back((
unsigned char)200);
207 reds.push_back((
unsigned char)150);
208 greens.push_back((
unsigned char)150);
209 blues.push_back((
unsigned char)150);
212 reds.push_back((
unsigned char)70);
213 greens.push_back((
unsigned char)70);
214 blues.push_back((
unsigned char)70);
217 reds.push_back((
unsigned char)130);
218 greens.push_back((
unsigned char)0);
219 blues.push_back((
unsigned char)170);
223 reds.push_back((
unsigned char)255);
224 greens.push_back((
unsigned char)150);
225 blues.push_back((
unsigned char)0);
229 int main(
int argc,
char* argv[]){
235 string *projsList = param.
AddParamString(
"projsList",
"list with projections",
"");
236 string *texList = param.
AddParamString(
"texList",
"list with projection files",
"");
237 string *points3DFile = param.
AddParamString(
"points3D",
"file with 3D points",
"");
238 bool *projectPoints = param.
AddParamBool(
"projectPoints",
"set to true if 3D points are to be projected",
false);
239 string *outFile = param.
AddParamString(
"outFile",
"filename of resulting vrml file",
"scene.wrl");
240 bool *foreGroundLineColorBlack = param.
AddParamBool(
"foreGroundLineColorBlack",
"should foreground line colors be black or white",
false);
241 bool *drawRays = param.
AddParamBool(
"drawRays",
"should rays be drawn?",
false);
242 bool *draw3Dpoints = param.
AddParamBool(
"draw3Dpoints",
"should 3D points be drawn or not",
true);
245 vector<unsigned char> reds;
246 vector<unsigned char> greens;
247 vector<unsigned char> blues;
248 createColors(reds, greens, blues);
262 vector<string> projFiles;
263 vector<Projection> projs;
265 if(*projsList !=
"" && *projsList !=
"manualProjs.projection"){
266 Param::ParseListFile(*projsList, projFiles);
267 for(
unsigned int i=0; i < projFiles.size(); i++){
268 P.
Load(projFiles[i]);
271 }
else if(*projsList ==
"manualProjs.projection"){
272 parseManualProjections(projs);
276 vector<string> texFiles;
277 if(*texList !=
"" && *texList !=
"WHITE" && *texList !=
"BLACK"){
278 Param::ParseListFile(*texList, texFiles);
282 vector<HomgPoint3D> points3D;
283 if(*points3DFile !=
""){
284 readPoints(*points3DFile, points3D);
294 unsigned int numImgs = projs.size();
296 numImgs = texFiles.size();
304 for(
unsigned int i = 0; i < numImgs; i++){
307 bool foundProjection =
false;
308 bool haveTex =
false;
311 bool searchFl =
false;
312 if(texFiles.size() == numImgs){
313 cout <<
"loading image... " << texFiles[i] << endl;
314 if(ImageIO::Load(texFiles[i], texture)!=0) {
315 cout<<
"texture could not be loaded, trying to load float" << texFiles[i] << endl;
316 if(ImageIO::Load(texFiles[i], textureFl)!=0){
317 cout <<
"texture could still not be loaded, aborting" << endl;
322 ImageConvert::ConvertST(textureFl, texture, ImageBase::ST_unsignedchar);
328 cout <<
"done ... parsing meta data..." << endl;
331 if(searchFl ==
false){
335 foundProjection =
true;
337 cout<<
"finished reading texture \n";
343 foundProjection =
true;
345 cout<<
"finished reading texture from fl \n";
352 if(!foundProjection && projs.size() == numImgs) {
353 foundProjection =
true;
358 if(foundProjection ==
true){
359 ppb = projs[i].GetParameters(0);
360 unsigned int width, height;
364 cout <<
"only implemented for perspective case for now, returning" << endl;
368 if(*foreGroundLineColorBlack){
369 vrmlOut.AddPMatrix(pmatrix, width, height,
RGBAuc(0, 0, 0, 128), 1,
"cam"+i);
371 vrmlOut.AddPMatrix(pmatrix, width, height,
RGBAuc(255, 255, 255, 128), 1,
"cam"+i);
377 if(foundProjection && (*texList ==
"WHITE" || *texList ==
"BLACK")){
378 unsigned int width=0, height=0;
381 unsigned char constColor[3];
382 if(*texList ==
"BLACK"){
387 if(*texList ==
"WHITE"){
399 if((*projectPoints) && haveTex && foundProjection){
400 unsigned char* col =
new unsigned char[3];
401 for(
unsigned int j=0; j < points3D.size(); j++){
403 bool projected = projs[i].DoesPointProjectIntoImage(points3D[j], point2D);
405 cout <<
"projected point " << point2D <<
" in image? " << projected << endl;
409 col[1] = greens[j%10];
410 col[2] = blues[j%10];
412 cout <<
"drawing point with color " << (int)rint(point2D[0]) <<
" " << (int)rint(point2D[1]) <<
" color " << (int)reds[j%10] <<
" " << (
int)greens[j%10] <<
" " << (int)blues[j%10] << endl;
415 vrmlOut.AddLine(
HomgPoint3D(projs[i].GetC()), points3D[j],
RGBAuc(reds[j%10], greens[j%10], blues[j%10], 128));
420 cout <<
"might need to save texture now " << endl;
425 if(*texList==
"WHITE" || *texList==
"BLACK"){
426 stringstream texname;
427 texname <<
"projImg_" << i <<
".png";
428 cout <<
"saving texture " << texname.str() << endl;
429 texFiles.push_back(texname.str());
430 ImageIO::Save(texFiles.back(), texture);
436 cout<<
"meshing..."; cout.flush();
439 mesh.GenerateImagePlane(projs[i], texture);
442 vrmlOut.AddTriangleMesh(mesh,
"mesh_from_"+
string(texFiles[i]),
451 for(
unsigned int i=0; i < points3D.size(); i++){
452 cout <<
"adding point with color " << reds[i%10] <<
" " << greens[i%10] <<
" " << blues[i%10] << endl;
453 vrmlOut.AddPoint(points3D[i],
RGBAuc(reds[i%10], greens[i%10], blues[i%10], 128));
457 cout<<
"Writing osg to " << *outFile;
459 vrmlOut.OpenSceneGraphOut(*outFile);
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual void SetPrincipal(const double x, const double y)
Set principal point in pixels relative to top left corner, virtual overload to recalculate K_...
class RGBAuc is asynonym for a Vector4 of corerct type
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
configuration struct for drawing styles of various 3d objects
int ScaleShift(double Scale, double Shift)
scales and shifts image (all channels simultanously)
double WCSAxesLength
<=0 means no visual coordinate axes
int SetXYZ(QUAT_TYPE radX, QUAT_TYPE radY, QUAT_TYPE radZ)
Sets quaternion as concatenated rotations around x,y,z-axis; this = q_x * q_y * q_z (BIAS-RMatrix con...
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
virtual void SetC(const Vector3< double > &C, unsigned int cam=0)
Set center of camera with index cam.
void SetSkew(double skew)
Set the current camera skew factor.
This class hides the underlying projection model, like projection matrix, spherical camera...
Create and represent a 3D triangle mesh.
void FillImageWithConstValue(StorageType Value)
fill grey images
void AddAbsoluteCamera(ProjectionParametersBase *ppb)
Add a camera to the projection,the coordinates of the pose are given in absolute Coordinates, they are transformed to relative coordinates to the first camera internally.
a class for exporting ThreeDOut objects to OSG scene graphs
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
virtual BIAS::PMatrix GetP() const
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
This class Param provides generic support for parameters.
(8bit) unsigned char image storage type
virtual void SetQ(const Quaternion< double > &Q, unsigned int cam=0)
Set rotation quaternion of camera with index cam.
void ShowData(std::ostream &os=std::cout, int grp=GRP_ALL, bool showenhanced=true)
print all data in group grp including current values to os if grp = GRP_ALL, print all values if show...
describes a projective 3D -> 2D mapping in homogenous coordinates
void SetFocalLengthAndAspect(double f, double AspectRatio)
Set the current camera focal length in pixel and the a spect ratio.
PointDrawingStyle PointStyle
drawing simple entities into the image like rectangles or lines As all functions are static they have...
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
const BIAS::Projection & GetProj() const
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
int ParseMetaData(bool bUse2x64bitTS=true)
After ImageIO::Load() operated on AppData_, this method fills P_, Timestamp, DC_*, ...