@@ -461,7 +461,7 @@ bool Depthmap::loadNormals(const char *normals_path){
461
461
462
462
return true ;
463
463
}
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 {
465
465
// save e scrive la maschera
466
466
467
467
TIFF* maskTiff = TIFFOpen (mask_path, " w" );
@@ -540,7 +540,7 @@ void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &
540
540
}
541
541
542
542
543
- void Depthmap::saveDepth (const char *depth_path){
543
+ void Depthmap::saveDepth (const char *depth_path) const {
544
544
saveTiff (depth_path, elevation, width, height, 32 );
545
545
}
546
546
@@ -975,10 +975,10 @@ void OrthoDepthmap::verifyPointCloud(){
975
975
if (pixelX < 0 || pixelX >= width || pixelY < 0 || pixelY >= height) {
976
976
continue ;
977
977
}
978
- cerr << " point inside the image limits "
978
+ /* cerr << "point inside the image limits "
979
979
<< "Point 3D: (" << realX << ", " << realY << ", " << pixelCoord[2] << "), "
980
980
<< "Coordinate pixel: (" << pixelX << ", " << pixelY << " " << elevation[pixelX + pixelY * width]<< ")\n";
981
-
981
+ */
982
982
}
983
983
984
984
@@ -996,30 +996,86 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
996
996
auto u = camera.camera .projectionToImage (Eigen::Vector3f (1 , 0 , z));
997
997
float pixel_size = 1 / (u[0 ] - o[0 ]);
998
998
999
+
999
1000
QTextStream out (&outFile);
1000
1001
std::vector<Eigen::Vector3f> differences;
1001
1002
for (size_t i = 0 ; i < point_cloud.size (); i++) {
1002
1003
1003
1004
Eigen::Vector3f& realCoord = point_cloud[i];
1004
- Eigen::Vector3f imageCoords = camera. camera . projectionToImage ( realCoord) ;
1005
+ float h = realCoord[ 2 ] ;
1005
1006
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);
1007
1010
int pixelX = static_cast <int >(round (imageCoords[0 ]));
1008
1011
int pixelY = static_cast <int >(round (imageCoords[1 ]));
1009
1012
1013
+
1010
1014
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));
1014
1029
out << depthValue << " \t " << h << " \t " << imageCoords[0 ]/camera.width << " \t " << imageCoords[1 ]/camera.height <<" \n " ; // red e green
1015
1030
1016
1031
}
1017
1032
}
1033
+
1018
1034
GaussianGrid gaussianGrid;
1019
1035
gaussianGrid.init (differences);
1020
1036
gaussianGrid.imageGrid ((" test.png" ));
1021
1037
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
+ }
1022
1077
}
1078
+
1023
1079
// fit h = a+b*elev
1024
1080
void GaussianGrid::init (std::vector<Eigen::Vector3f> &differences){
1025
1081
int side = static_cast <int >(sqrt (differences.size ())) / 2 ;
@@ -1120,7 +1176,11 @@ void GaussianGrid::fillLaplacian(float precision){
1120
1176
}
1121
1177
1122
1178
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];
1124
1184
}
1125
1185
1126
1186
void GaussianGrid::computeGaussianWeightedGrid (std::vector<Eigen::Vector3f> &differences) {
@@ -1166,11 +1226,11 @@ void GaussianGrid::computeGaussianWeightedGrid(std::vector<Eigen::Vector3f> &dif
1166
1226
values[i] /= (weights[i]);
1167
1227
}
1168
1228
}
1169
- for (int i = 0 ; i < height; i++) {
1229
+ /* for (int i = 0; i < height; i++) {
1170
1230
for (int j = 0; j < width; j++) {
1171
1231
qDebug() << "z_grid[" << i << "][" << j << "] = " << values[i * height +j];
1172
1232
}
1173
- }
1233
+ }*/
1174
1234
}
1175
1235
1176
1236
0 commit comments