#include <Image/ProjectionMapping.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Image/Image.hh>
#include <Base/Debug/TimeMeasure.hh>
#include <Base/Math/Vector3.hh>
#include <Base/Math/Vector.hh>
#include <Utils/Param.hh>
#include <Utils/ThreeDOut.hh>
#include <Geometry/ProjectionParametersSpherical.hh>
#include <Image/Camera.hh>
using namespace BIAS;
using namespace std;
void GetSequenceAngle(
unsigned int & sequence ,
Projection p1,
Projection p2,
const bool yaxis,
double & rotationAngle)
{
unsigned int width1,height1,width2,height2;
double angle1, angle2,focalLength;
if (pPPP!=NULL){
if(!yaxis) angle1 = 2*atan(width1/(2*focalLength));
else angle1 = 2*atan(height1/(2*focalLength));
}
else{
cout<<"Hat nicht geklappt. Kamera 1 ist weder Perspektivisch, noch Spherisch.";
return;
}
if (pPPP!=NULL){
if(!yaxis) angle2 = 2*atan(width2/(2*focalLength));
else angle2 = 2*atan(height2/(2*focalLength));
}
else{
cout<<"Hat nicht geklappt. Kamera 2 ist weder Perspektivisch, noch Spherisch.";
return;
}
if(sequence == 0){
sequence =(unsigned int)(angle1/angle2);
rotationAngle = angle2;
}
else{
rotationAngle = (angle1-angle2)/((double)sequence-1);
}
cout << "Abgedeckter Winkel: " << (rotationAngle*(sequence-1)*180/M_PI) << " Winkel der OriginalKamera: " << (angle1*180/M_PI) << " Winkel der ZielKamera: " << (angle2*180/M_PI) << endl;
}
{
}
{
}
int main(int argc, char *argv[])
{
string sourceImage,sourceCam,sinkCam;
unsigned int sequence;
double rotationAngle;
"Absolute path to the source Image",
"",
'i');
"Absolute path to the sink Image",
"image_projection_trilinear",
'o');
"Absolute path to the source Camera calibration XML",
"",
'c');
"Angle to rotate around v in RAD (e.g. 0.1)",
0.0,
0.0,
2*M_PI,
'w');
"Absolute path to the sink Camera calibration XML",
"",
's');
"A Vector to rotate (e.g. 0.0 1.0 0.0)",
"0.0 1.0 0.0",
'v');
"Give a number of images to create a sequence",
1,
1,
1000,
'S');
"Create a mosaic from Image?",
false,
'm');
if(sourceImage == "" || sourceCam == "")
{
BIASERR(argv[0]<<" -i<image-file> -c<SourceCamera-file>" <<
"-vaSs[Rotation-Vector Rotation-Angle] [Sequence] [SinkCamera-file]");
return -1;
}
BIASERR("error loading "<<sourceImage);
return -2;
}
BIASERR("Error reading "<<sourceCam);
return -3;
}
}
if(sinkCam == "") {
GenerateProjection(p2);
} else {
BIASERR("Error reading "<<sinkCam);
return -3;
}
}
}
rotationVector.
MultiplyIP(1.0/rotationVector.NormL2());
SetRotation(p2,v,rotationAngle);
cout << rotationVector.Length() << endl;
unsigned int width, height;
if(sequence > 1 && !mosaic)
{
GetSequenceAngle(sequence,p1,p2,false,rotationAngle);
}
cout<<
"ROI of source image is "<<*im.
GetROI()
<<" while image size is "<<width<<" x "<<height<<endl;
cout<<"timing ..."<<endl<<flush;
stringstream filename;
for(unsigned int i=0;i<50;i++){
cout<<"Run: "<<i<<"/50"<<endl;
SetRotation(p2,v,(0.03*((double)i-(49.0/2.0))));
filename.str("");
char tmpStr[8];
sprintf(tmpStr, "%03i", i);
filename << "/datapc/sieg/oniemann/data/images/find/find_image_"<<tmpStr<<".mip";
BIASERR("error image");
}
}
if(!mosaic)
{
for (unsigned int i=0; i<sequence; i++) {
if(sequence > 1){
v[0] = 0.0;
v[1] = 1.0;
v[2] = 0.0;
cout << "Run "<<i<<endl;
cout << "RotationAngle: " << rotationAngle*((double)i-(((double)sequence-1)/2.0))*180/M_PI << endl;
SetRotation(p2,v,(rotationAngle*((double)i-(((double)sequence-1)/2.0))));
}
else{
cout << "Angle: " << (rotationAngle*180/M_PI) << endl;
}
filename.str("");
char tmpStr[8];
sprintf(tmpStr, "%03i", i);
filename << "/datapc/sieg/oniemann/data/images/reference/reference_image_000_"<<tmpStr<<".mip";
BIASERR("error image");
}
}
}
else
{
double rotationAngle2;
unsigned int sequence2;
sequence = 0;
sequence2 = 0;
GetSequenceAngle(sequence,p1,p2,false,rotationAngle);
GetSequenceAngle(sequence2,p1,p2,true,rotationAngle2);
for ( unsigned int j=0; j<sequence2; j++) {
R3=
RMatrix(v2, (rotationAngle2*((
double)j-(((
double)sequence2-1.0)/2.0))));
for (unsigned int i=0; i<sequence; i++) {
if(j%2==0){
R2=
RMatrix(v, (rotationAngle*((
double)i-(((
double)sequence-1.0)/2.0))));
}
else{
R2=
RMatrix(v, (rotationAngle*((
double)i+0.5-(((
double)sequence-1.0)/2.0))));
}
cout << "Run " << i <<" " << j <<endl;
filename.str("");
char tmpStr[8];
sprintf(tmpStr, "%03i_%03i", j, i);
filename << "/datapc/sieg/oniemann/data/images/reference/reference_image_"<<tmpStr<<".mip";
BIASERR("error image");
}
}
}
}
cout <<"Trilinear mapping took "
<<" ms,"<<endl;
return 0;
}