Skip to content

Commit ae577e6

Browse files
author
Erika
committed
modified integretedCamera function with issues
1 parent 56b61f9 commit ae577e6

File tree

3 files changed

+75
-14
lines changed

3 files changed

+75
-14
lines changed

depthmap/depthmap.cpp

+72-12
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ bool Depthmap::loadNormals(const char *normals_path){
461461

462462
return true;
463463
}
464-
void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &w, uint32_t &h, uint32_t bitsPerSample){
464+
void Depthmap::saveTiff(const char *mask_path,const vector<float> &values, uint32_t w, uint32_t h, uint32_t bitsPerSample) const{
465465
//save e scrive la maschera
466466

467467
TIFF* maskTiff = TIFFOpen(mask_path, "w");
@@ -540,7 +540,7 @@ void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &
540540
}
541541

542542

543-
void Depthmap::saveDepth(const char *depth_path){
543+
void Depthmap::saveDepth(const char *depth_path) const{
544544
saveTiff(depth_path, elevation, width, height, 32);
545545
}
546546

@@ -975,10 +975,10 @@ void OrthoDepthmap::verifyPointCloud(){
975975
if (pixelX < 0 || pixelX >= width || pixelY < 0 || pixelY >= height) {
976976
continue;
977977
}
978-
cerr << "point inside the image limits "
978+
/* cerr << "point inside the image limits "
979979
<< "Point 3D: (" << realX << ", " << realY << ", " << pixelCoord[2] << "), "
980980
<< "Coordinate pixel: (" << pixelX << ", " << pixelY << " " << elevation[pixelX + pixelY * width]<< ")\n";
981-
981+
*/
982982
}
983983

984984

@@ -996,30 +996,86 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
996996
auto u = camera.camera.projectionToImage(Eigen::Vector3f(1, 0, z));
997997
float pixel_size = 1 / (u[0] - o[0]);
998998

999+
9991000
QTextStream out(&outFile);
10001001
std::vector<Eigen::Vector3f> differences;
10011002
for (size_t i = 0; i < point_cloud.size(); i++) {
10021003

10031004
Eigen::Vector3f& realCoord = point_cloud[i];
1004-
Eigen::Vector3f imageCoords = camera.camera.projectionToImage(realCoord);
1005+
float h = realCoord[2];
10051006
Eigen::Vector3f pixelCoord = realToPixelCoord(realCoord[0], realCoord[1], realCoord[2]);
1006-
1007+
// project from ortho plane to camera plane, hence the fixed z
1008+
realCoord[2] = z;
1009+
Eigen::Vector3f imageCoords = camera.camera.projectionToImage(realCoord);
10071010
int pixelX = static_cast<int>(round(imageCoords[0]));
10081011
int pixelY = static_cast<int>(round(imageCoords[1]));
10091012

1013+
10101014
if (pixelX >= 0 && pixelX < camera.width && pixelY >= 0 && pixelY < camera.height) {
1011-
float depthValue = camera.elevation[pixelX + pixelY * camera.width]* pixel_size;
1012-
float h = realCoord[2];
1013-
differences.push_back(Eigen::Vector3f(imageCoords[0]/camera.width, imageCoords[1]/camera.height, h + depthValue));
1015+
float depthValue = z - camera.elevation[pixelX + pixelY * camera.width]* pixel_size;
1016+
1017+
if(fabs(pixelCoord[0] - 170) < 3 && fabs(pixelCoord[1] - 150) < 3){
1018+
cout << "elevation: " << elevation[int(pixelCoord[0]) + int(pixelCoord[1]) *width] << endl;
1019+
1020+
cout << "PixelX: " << pixelCoord[0] << ", PixelY: " << pixelCoord[1] << "pixelZ " << pixelCoord[2] << endl;
1021+
cout << "h: " << h << endl;
1022+
cout << "depthValue: " << depthValue << endl;
1023+
cout << "Image Coords X: " << imageCoords[0] << ", Y: " << imageCoords[1] << endl;
1024+
cout << "Camera Width: " << camera.width << ", Camera Height: " << camera.height << endl;
1025+
}
1026+
1027+
1028+
differences.push_back(Eigen::Vector3f(imageCoords[0]/camera.width, imageCoords[1]/camera.height, h - depthValue));
10141029
out << depthValue << "\t" << h << "\t" << imageCoords[0]/camera.width << "\t" << imageCoords[1]/camera.height <<"\n"; //red e green
10151030

10161031
}
10171032
}
1033+
10181034
GaussianGrid gaussianGrid;
10191035
gaussianGrid.init(differences);
10201036
gaussianGrid.imageGrid(("test.png"));
10211037

1038+
float ortho_z = realToPixelCoord(0,0,z)[2];
1039+
1040+
for(int y=0; y< height/2; y++){
1041+
for(int x=0; x<width; x++){
1042+
//if(x,y )
1043+
Eigen::Vector3f r = pixelToRealCoordinates(x, y, ortho_z);
1044+
assert(fabs(z-r[2]) < 0.1f);
1045+
Eigen::Vector3f p = camera.camera.projectionToImage(r);
1046+
1047+
int px = round(p[0]);
1048+
int py = round(p[1]);
1049+
1050+
if(px >= 0 && px< camera.width && py >= 0 && py< camera.height){
1051+
float depthValue = z - camera.elevation[px + py * camera.width]* pixel_size;
1052+
p[0] /= camera.width;
1053+
p[1] /= camera.height;
1054+
float h = gaussianGrid.value(p[0], p[1]) + depthValue;
1055+
Eigen::Vector3f d = realToPixelCoord(r[0], r[1], h);
1056+
1057+
//p0 e p1 devono venire uguale e vedi se depth è ugusle, h dovrebbe venire simile
1058+
if (fabs(x - 170) < 1 && fabs(y - 150) < 1){
1059+
cout << "Real Coord r:" << r[0] << endl;
1060+
cout << "Projected Coords p:" << p[0] << endl;
1061+
cout << "comparison:" << endl;
1062+
cout << "PixelX: " << px << ", PixelY: " << py << endl;
1063+
cout << "p[0]: " << p[0] << ", p[1]: " << p[1] << endl;
1064+
cout << "Depth Value: " << depthValue << endl;
1065+
cout <<"gaussian grid" << gaussianGrid.value(p[0], p[1]) << endl;
1066+
cout << "elevation: " << elevation[x+y * width] << endl;
1067+
cout << " h: " << h << endl;
1068+
cout << " d: " << d << endl;
1069+
}
1070+
elevation[x + y * width] = d[2];
1071+
1072+
1073+
}
1074+
}
1075+
1076+
}
10221077
}
1078+
10231079
//fit h = a+b*elev
10241080
void GaussianGrid::init(std::vector<Eigen::Vector3f> &differences){
10251081
int side = static_cast<int>(sqrt(differences.size())) / 2;
@@ -1120,7 +1176,11 @@ void GaussianGrid::fillLaplacian(float precision){
11201176
}
11211177

11221178
float GaussianGrid::value(float x, float y){
1123-
1179+
//bicubic interpolation
1180+
//nearest
1181+
int pixelX = std::max(0, std::min(width-1, (int)(x * (width-1))));
1182+
int pixelY = std::max(0, std::min(height-1, (int)(y * (height-1))));
1183+
return values[pixelX + pixelY * width];
11241184
}
11251185

11261186
void GaussianGrid::computeGaussianWeightedGrid(std::vector<Eigen::Vector3f> &differences) {
@@ -1166,11 +1226,11 @@ void GaussianGrid::computeGaussianWeightedGrid(std::vector<Eigen::Vector3f> &dif
11661226
values[i] /= (weights[i]);
11671227
}
11681228
}
1169-
for (int i = 0; i < height; i++) {
1229+
/*for (int i = 0; i < height; i++) {
11701230
for (int j = 0; j < width; j++) {
11711231
qDebug() << "z_grid[" << i << "][" << j << "] = " << values[i * height +j];
11721232
}
1173-
}
1233+
}*/
11741234
}
11751235

11761236

depthmap/depthmap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Depthmap {
4141
bool loadDepth(const char *depth_path);
4242
bool loadMask(const char *mask_path);
4343
bool loadNormals(const char *normals_path);
44-
void saveDepth(const char *depth_path);
44+
void saveDepth(const char *depth_path) const;
4545
void saveMask(const char *depth_path);
4646
void saveNormals(const char *normals_path);
4747

@@ -57,7 +57,7 @@ class Depthmap {
5757
bool loadTiledTiff(TIFF* inTiff, std::vector<float> &elevation, uint32_t w, uint32_t h,
5858
uint32_t tileWidth, uint32_t tileLength, uint32_t bitsPerSample);
5959
bool loadStripedTiff(TIFF* inTiff, std::vector<float> &elevation, uint32_t& w, uint32_t& h, uint32_t bitsPerSample);
60-
void saveTiff(const char *mask_path, std::vector<float> &values, uint32_t &w, uint32_t &h, uint32_t bitsPerSample);
60+
void saveTiff(const char *mask_path, const std::vector<float> &values, uint32_t w, uint32_t h, uint32_t bitsPerSample) const;
6161

6262
};
6363
class GaussianGrid {

depthmap/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ int main(int argc, char *argv[]) {
6666
return -1;
6767
}
6868
ortho.integratedCamera(depthCam, qPrintable(output_points));
69+
ortho.saveDepth(qPrintable(base + "testcenterRel_copia/photogrammetry/testDepth.tiff"));
6970
// sqrt
7071

7172

0 commit comments

Comments
 (0)