25 #include <Base/Common/BIASpragma.hh>
27 #include <Base/Image/ImageBase.hh>
28 #include <Base/Image/ImageIO.hh>
29 #include <Base/ImageUtils/ImageDraw.hh>
33 #include "Geometry/PMatrix.hh"
34 #include "Image/Camera.hh"
36 #include <Base/Common/BIASpragma.hh>
49 cout <<
"Usage: biasprojection -p file [options] files"<<endl;
50 cout <<
" Options: "<< endl
51 <<
" -s : search next smaller(string compare) PMatrix file"<<endl
52 <<
" -b : assume bbc camera file format"<<endl
53 <<
" -p file : file containing 3d points"<<endl
55 cout <<
"This program opens the image files given by the command line"
56 <<
", e.g. image037.pgm, looks at the command line for a file "
57 <<
" image037.pgm.mat and projects 3d points into the images."<<endl
58 <<
" using the pmatrices."<<endl
59 <<
" cutouts are written around the projection."<<endl
60 <<
"Returns: 0 on success, 1 if errors occured."<<endl<<endl;
68 EndOfPrefix = fn.rfind(
'.');
70 suffix = fn.substr(EndOfPrefix+1,fn.length());
81 int main (
int argc,
char *argv[])
83 bool Nearest =
false, BBC =
false;
84 vector<HomgPoint3D> Points;
87 while ((i<argc) && (param)) {
89 if (!strcmp(
"-s",argv[i])) {
90 std::cout <<
"Using nearest P from command line also."<<endl;
95 if (!strcmp(
"-b",argv[i])) {
96 std::cout <<
"Trying to load BBC camera data."<<endl;
101 if (!strcmp(
"-p",argv[i])) {
104 cerr<<
"error, no point file given after -p"<<endl;
107 std::cout <<
"loading points from "<< argv[i]<<endl;
108 ifstream infile(argv[i++], ios::in);
109 if (infile.eof() || !infile.good()){
110 cerr<<
"error opening point file"<<endl;
115 while (!infile.eof()) {
116 infile >> thepoint[0];
117 infile >> thepoint[1];
118 infile >> thepoint[2];
119 if (infile.eof() || !infile.good())
break;
120 Points.push_back(thepoint);
121 cout<<
"Read 3D point "<<thepoint<<endl;
128 if (i>=argc || Points.size()==0) {
134 bool ErrorFlag =
false;
139 map<string, PMatrix> mapP;
140 for (
int j=i; j<argc; j++) {
141 if (strstr(argv[j],
".mat")!=NULL) {
142 cout<<
"arg "<<j<<
" is .mat";
150 cout <<
"P is "<<P<<endl;
154 if (mapP.size()==0) {
155 BIASERR(
"No matrices found !");
159 const int cosize = 40;
164 if (strstr(argv[i],
".mat")!=NULL)
continue;
165 cout<<
"Trying "<<argv[i]<<endl;
166 if (DetermineFiletype(argv[i], FileType)!=0) {
167 BIASERR(
"Skipping current file because of unknown/unsuported format: "
168 <<argv[i]<<endl<<
"PMatrix can be written to mip,pgm,ppm,pnm");
176 BIASERR(
"Error reading "<< argv[i]);
181 ss << argv[i] <<
".mat";
182 if (mapP.find(ss.str())!=mapP.end()) {
183 cout<<
"Found a mat file for "<<argv[i]<<endl;
187 cout <<
"Found NO mat file for "<<argv[i]<<
" !!!!! SKIPPING"<<endl;
190 map<string,PMatrix>::iterator it = mapP.lower_bound(ss.str());
191 if (it != mapP.begin()) it--;
192 else cout<<
"First element, cant use smaller, must use larger !";
194 cout <<
"Found next mat file for "<<argv[i]<<
": "<<it->first<<endl;
208 bool simplecopy =
false;
209 for (
unsigned int p=0; p<Points.size(); p++) {
217 if (x[0]<cosize || x[0]>= CurImage.
GetWidth()-cosize ||
218 x[1]<cosize || x[1]>= CurImage.
GetWidth()-cosize)
continue;
220 CurImage.
SetROI(
int(x[0]-cosize),
int(x[1]-cosize),
221 int(x[0]+cosize+1),
int(x[1]+cosize+1));
223 K[0][2] += x[0]-cosize;
224 K[1][2] += x[1]-cosize;
227 float dx = 0, dy = 0;
229 for (
int xx=-cosize; xx<=cosize; xx++) {
230 for (
int yy=-cosize; yy<=cosize; yy++) {
236 if (value<0.0) value = 0.0;
237 if (value>255.0) value = 255.0;
239 (
unsigned char) value;
250 string filename = argv[i];
251 unsigned int pos = filename.rfind(
"/");
252 if (pos!=string::npos) filename = filename.substr(pos+1);
253 stringstream filenamess;
254 filenamess<<filename<<
"_"<<p;
275 BIASERR(
"Error writing "<< filenamess.str());
282 if (ErrorFlag) cout <<
"There were errors." <<endl;
283 if (ErrorFlag)
return 1;
int GetCopyOfROI(ImageBase ©) const
returns a copy of ROI (a new image) lower right point excluded, only interleaved images ! ...
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
double BilinearInterpolation(const double x, const double y, const unsigned short int channel=0) const
Generic bilinear interpolation.
bool Load(const std::string &filename)
overload Load because it has to invalidate decomposition! JW 09/2003
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
int SetP(const PMatrix &matP)
int GetR(Matrix3x3< double > &R)
unsigned int GetWidth() const
static int RectangleCorners(Image< StorageType > &im, const int minx, const int miny, const int maxx, const int maxy, const StorageType value[])
rectangles
int LoadBBC(const std::string &filename, const double &AddCenterPointShiftX=0.0, const double &AddCenterPointShiftY=0.0)
Load calibration data file from BBC-Free-D system.
void SetZero()
Sets all values to zero.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
TFileFormat
format specifier when writing an image to a file Do NOT change order or associated enum value because...
void SetC(const Vector3< double > &C)
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
int SetROI(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
deprecated, use SetROICorners()
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
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
int UpdateMetaData()
copy P_ and co.
int GetC(Vector3< double > &C)
computes translation vector origin world coo -> origin camera coo (center), uses decomposition, which is cached
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
describes a projective 3D -> 2D mapping in homogenous coordinates
void SetK(const KMatrix &K)
void SetMetaData(const MetaData &m)
void SetR(const RMatrix &R)
int GetK(KMatrix &K)
calibration matrix
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase