@@ -163,7 +163,7 @@ Eigen::Vector3f Camera::projectionToImage(Eigen::Vector3f realPosition) const{
163
163
164
164
// proiezione
165
165
if (cameraCoords.z () == 0 ) {
166
- cerr << " Warning: Z è zero, impossibile proiettare il punto." << endl;
166
+ cerr << " Z è zero, impossibile proiettare il punto." << endl;
167
167
return Eigen::Vector3f (0 , 0 , 0 );
168
168
}
169
169
// Normalize by dividing by the z coordinate to get the image coordinates u and v as projected 2D coordinates
@@ -1001,7 +1001,7 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
1001
1001
1002
1002
for (size_t i = 0 ; i < point_cloud.size (); i++) {
1003
1003
1004
- Eigen::Vector3f& realCoord = point_cloud[i];
1004
+ Eigen::Vector3f realCoord = point_cloud[i];
1005
1005
float h = realCoord[2 ];
1006
1006
Eigen::Vector3f pixelCoord = realToPixelCoord (realCoord[0 ], realCoord[1 ], realCoord[2 ]);
1007
1007
// project from ortho plane to camera plane, hence the fixed z
@@ -1013,17 +1013,7 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
1013
1013
1014
1014
if (pixelX >= 0 && pixelX < camera.width && pixelY >= 0 && pixelY < camera.height ) {
1015
1015
float depthValue = camera.elevation [pixelX + pixelY * camera.width ];
1016
- if (fabs (pixelCoord[0 ] - 170 ) < 3 && fabs (pixelCoord[1 ] - 150 ) < 3 ){
1017
- cout << " elevation: " << elevation[int (pixelCoord[0 ]) + int (pixelCoord[1 ]) *width] << endl;
1018
-
1019
- cout << " PixelX: " << pixelCoord[0 ] << " , PixelY: " << pixelCoord[1 ] << " pixelZ " << pixelCoord[2 ] << endl;
1020
- cout << " h: " << h << endl;
1021
- cout << " depthValue: " << depthValue << endl;
1022
- cout << " Image Coords X: " << imageCoords[0 ] << " , Y: " << imageCoords[1 ] << endl;
1023
- cout << " Camera Width: " << camera.width << " , Camera Height: " << camera.height << endl;
1024
- }
1025
-
1026
-
1016
+ cout << pixelX << " " << pixelY << " " << depthValue << endl;
1027
1017
imageCloud.push_back (Eigen::Vector3f (imageCoords[0 ]/camera.width , imageCoords[1 ]/camera.height , h));
1028
1018
source.push_back (depthValue);
1029
1019
out << depthValue << " \t " << h << " \t " << imageCoords[0 ]/camera.width << " \t " << imageCoords[1 ]/camera.height <<" \n " ; // red e green
@@ -1050,31 +1040,24 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
1050
1040
1051
1041
if (px >= 0 && px< camera.width && py >= 0 && py< camera.height ){
1052
1042
float depthValue = camera.elevation [px + py * camera.width ];
1053
- p[0 ] /= camera.width ;
1054
- p[1 ] /= camera.height ;
1043
+ p[0 ] = px / float ( camera.width ) ;
1044
+ p[1 ] = py / float ( camera.height ) ;
1055
1045
float h = gaussianGrid.target (p[0 ], p[1 ], depthValue);
1056
1046
Eigen::Vector3f d = realToPixelCoord (r[0 ], r[1 ], h);
1057
1047
1048
+ float w = camera.calculateWeight (px, py);
1049
+
1058
1050
// p0 e p1 devono venire uguale e vedi se depth è ugusle, h dovrebbe venire simile
1059
- if (fabs (x - 170 ) < 1 && fabs (y - 150 ) < 1 ){
1060
- cout << " Real Coord r:" << r[0 ] << endl;
1061
- cout << " Projected Coords p:" << p[0 ] << endl;
1062
- cout << " comparison:" << endl;
1063
- cout << " PixelX: " << px << " , PixelY: " << py << endl;
1064
- cout << " p[0]: " << p[0 ] << " , p[1]: " << p[1 ] << endl;
1065
- cout << " Depth Value: " << depthValue << endl;
1066
- cout <<" gaussian grid" << gaussianGrid.value (p[0 ], p[1 ]) << endl;
1067
- cout << " elevation: " << elevation[x+y * width] << endl;
1068
- cout << " h: " << h << endl;
1069
- cout << " d: " << d << endl;
1070
- }
1071
- elevation[x + y * width] = d[2 ];
1051
+ elevation[x + y * width] += w * d[2 ];
1052
+ mask[x+ y * width] += w;
1072
1053
} else {
1073
1054
// elevation[x + y*width] = origin[2] + resolution[2] * elevation[x + y*width];
1074
1055
}
1075
1056
}
1076
1057
}
1058
+ saveObj (" testElev.obj" );
1077
1059
}
1060
+ /* _-----------------------------------------------------------------------------------------*/
1078
1061
void GaussianGrid::fitLinear (std::vector<float > &x, std::vector<float > &y, float &a, float &b) {
1079
1062
if (x.size () != y.size ()) {
1080
1063
cout << " Errore: i vettori x e y devono avere la stessa lunghezza." << endl;
@@ -1096,6 +1079,32 @@ void GaussianGrid::fitLinear(std::vector<float> &x, std::vector<float> &y, float
1096
1079
b = (sum_y - a * sum_x) / n;
1097
1080
}
1098
1081
1082
+ float GaussianGrid::bilinearInterpolation (float x, float y) {
1083
+
1084
+ float x1 = floor (x);
1085
+ float y1 = floor (y);
1086
+ float x2 = x1+1 ;
1087
+ float y2 = y1 +1 ;
1088
+
1089
+
1090
+ if (x1 < 0 || x2 >= width || y1 < 0 || y2 >= height) {
1091
+ cerr << " Coordinate fuori dai limiti della griglia!" << endl;
1092
+ return 0 .0f ;
1093
+ }
1094
+
1095
+
1096
+ float Q11 = values[x1 + y1 * width];
1097
+ float Q12 = values[x1 + y2 * width];
1098
+ float Q21 = values[x2 + y1 * width];
1099
+ float Q22 = values[x2 + y2 * width];
1100
+
1101
+ float R1 = (x2 - x) * Q11 + (x - x1) * Q21;
1102
+ float R2 = (x2 - x) * Q12 + (x - x1) * Q22;
1103
+
1104
+ float P = (y2 - y) * R1 + (y - y1 ) * R2;
1105
+
1106
+ return P;
1107
+ }
1099
1108
// fit h = a+b*elev
1100
1109
void GaussianGrid::init (std::vector<Eigen::Vector3f> &cloud, std::vector<float > &source) {
1101
1110
int side = static_cast <int >(sqrt (cloud.size ())) / 2 ;
@@ -1113,6 +1122,7 @@ void GaussianGrid::init(std::vector<Eigen::Vector3f> &cloud, std::vector<float>
1113
1122
for (size_t i = 0 ; i < cloud.size (); i++) {
1114
1123
cloud[i][2 ] -= depthmapToCloud (source[i]);
1115
1124
}
1125
+
1116
1126
computeGaussianWeightedGrid (cloud);
1117
1127
fillLaplacian (precision);
1118
1128
}
@@ -1207,14 +1217,18 @@ void GaussianGrid::fillLaplacian(float precision){
1207
1217
float GaussianGrid::value (float x, float y){
1208
1218
// bicubic interpolation
1209
1219
// nearest
1210
- int pixelX = std::max (0 , std::min (width-1 , (int )(x * (width-1 ))));
1211
- int pixelY = std::max (0 , std::min (height-1 , (int )(y * (height-1 ))));
1212
- return values[pixelX + pixelY * width];
1220
+ float pixelX = x * (width-1 );
1221
+ float pixelY = y * (height-1 );
1222
+
1223
+ return bilinearInterpolation (pixelX, pixelY);
1224
+
1225
+ // return values[pixelX + pixelY * width];
1226
+
1213
1227
}
1214
1228
1215
1229
float GaussianGrid::target (float x, float y, float h) {
1216
1230
h = depthmapToCloud (h);
1217
- return h - value (x, y);
1231
+ return h + value (x, y);
1218
1232
}
1219
1233
1220
1234
void GaussianGrid::computeGaussianWeightedGrid (std::vector<Eigen::Vector3f> &differences) {
@@ -1230,8 +1244,10 @@ void GaussianGrid::computeGaussianWeightedGrid(std::vector<Eigen::Vector3f> &dif
1230
1244
values.resize (width * height, 0 );
1231
1245
weights.resize (width * height, 0 );
1232
1246
1247
+ std::vector<int > count (width*height, 0 );
1233
1248
1234
- float max_distance = 3 * sigma;
1249
+
1250
+ float max_distance = 1.2 * sigma;
1235
1251
for (auto &p : differences) {
1236
1252
1237
1253
@@ -1240,22 +1256,30 @@ void GaussianGrid::computeGaussianWeightedGrid(std::vector<Eigen::Vector3f> &dif
1240
1256
int y_start = std::max (0 , static_cast <int >((p[1 ] - max_distance - y_min) / y_step));
1241
1257
int y_end = std::min (height - 1 , static_cast <int >((p[1 ] + max_distance - y_min) / y_step));
1242
1258
1243
- for (int i = x_start; i <= x_end; i ++) {
1244
- for (int j = y_start; j <= y_end; j ++) {
1245
- float xg = x_min + i * x_step;
1246
- float yg = y_min + j * y_step;
1259
+ for (int x = x_start; x <= x_end; x ++) {
1260
+ for (int y = y_start; y <= y_end; y ++) {
1261
+ float xg = x_min + x * x_step;
1262
+ float yg = y_min + y * y_step;
1247
1263
1248
1264
float distance = sqrt ((p[0 ] - xg) * (p[0 ] - xg) + (p[1 ] - yg) * (p[1 ] - yg));
1249
1265
if (distance <= max_distance) {
1250
1266
float weight = exp (-(distance * distance) / (2 * sigma * sigma));
1251
- values[i * width + j] += weight * p[2 ];
1252
- weights[i * width + j] += weight;
1267
+ values[y * width + x] += weight * p[2 ];
1268
+ weights[y * width + x] += weight;
1269
+ count[y*width + x]++;
1253
1270
}
1254
1271
}
1255
1272
}
1256
1273
}
1274
+ // chiama camere tutte e 4 e vedi come vengono
1275
+ // pesare per il blanding funzione intervallo 0, 1 * 0, 1 0 ai bordi 1 al centro, che sia una funzione continua
1276
+ // polinomio di 2 grado in x * pol 2 grado in y. derivata e peso a 0 sul bordo
1277
+ // fai somma pesata e veedi come vieni
1278
+ // funz target ritorna valore e peso
1257
1279
1258
1280
for (int i = 0 ; i < values.size (); i++) {
1281
+ if (count[i] < 3 )
1282
+ weights[i] = 0 ;
1259
1283
if (weights[i] != 0 ) {
1260
1284
values[i] /= (weights[i]);
1261
1285
}
@@ -1266,7 +1290,31 @@ void GaussianGrid::computeGaussianWeightedGrid(std::vector<Eigen::Vector3f> &dif
1266
1290
}
1267
1291
}*/
1268
1292
}
1293
+ //
1294
+ float Depthmap::calculateWeight (float x, float y) const {
1295
+
1296
+ x/=width;
1297
+ y/= height;
1298
+
1299
+ float weightX =pow (cos (M_PI * (x-0 .5f )), 2 );
1300
+ float weightY = pow (cos (M_PI * (y-0 .5f )), 2 );
1301
+
1302
+ return weightX * weightY;
1303
+ }
1304
+ void OrthoDepthmap::beginIntegration (){
1305
+ elevation.clear ();
1306
+ elevation.resize (width * height, 0 );
1307
+ mask.clear ();
1308
+ mask.resize (width * height, 0 );
1269
1309
1310
+ }
1311
+ void OrthoDepthmap::endIntegration (){
1312
+ for (size_t i =0 ; i < elevation.size (); i++){
1313
+ if (mask[i]){
1314
+ elevation[i] /= mask[i];
1315
+ }
1316
+ }
1317
+ }
1270
1318
1271
1319
void GaussianGrid::imageGrid (const char * filename) {
1272
1320
0 commit comments