@@ -253,7 +253,7 @@ bool Depthmap::loadTiff(const char *tiff, vector<float> &values, uint32_t &w, ui
253
253
// Check if the TIFF is tiled
254
254
uint32_t tileWidth, tileLength;
255
255
if (!TIFFGetField (inTiff, TIFFTAG_TILEWIDTH, &tileWidth) ||
256
- !TIFFGetField (inTiff, TIFFTAG_TILELENGTH, &tileLength)) {
256
+ !TIFFGetField (inTiff, TIFFTAG_TILELENGTH, &tileLength)) {
257
257
return loadStripedTiff (inTiff, values, w, h, bitsPerSample);
258
258
} else {
259
259
return loadTiledTiff (inTiff, values, w, h, tileWidth, tileLength, bitsPerSample);
@@ -453,10 +453,10 @@ bool Depthmap::loadNormals(const char *normals_path){
453
453
int i = x + y * width;
454
454
455
455
normals[i] = Eigen::Vector3f (
456
- (qRed (rgb) / 255 .0f ) * 2 .0f - 1 .0f ,
457
- (qGreen (rgb) / 255 .0f ) * 2 .0f - 1 .0f ,
458
- (qBlue (rgb) / 255 .0f ) * 2 .0f - 1 .0f
459
- );
456
+ (qRed (rgb) / 255 .0f ) * 2 .0f - 1 .0f ,
457
+ (qGreen (rgb) / 255 .0f ) * 2 .0f - 1 .0f ,
458
+ (qBlue (rgb) / 255 .0f ) * 2 .0f - 1 .0f
459
+ );
460
460
}
461
461
}
462
462
@@ -774,7 +774,7 @@ bool OrthoDepthmap::loadXml(const char *xmlPath){
774
774
775
775
776
776
if (originePlaniNodes.isEmpty () || resolutionPlaniNodes.isEmpty () ||
777
- origineAltiNodes.isEmpty () || resolutionAltiNodes.isEmpty ()) {
777
+ origineAltiNodes.isEmpty () || resolutionAltiNodes.isEmpty ()) {
778
778
cerr << " OriginePlani, ResolutionPlani, OrigineAlti, or ResolutionAlti not found in XML." << endl;
779
779
return false ;
780
780
@@ -999,6 +999,40 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
999
999
std::vector<Eigen::Vector3f> imageCloud;
1000
1000
std::vector<float > source;
1001
1001
1002
+ // 1. togliere dalla point tutti i punti che cadono dentro la maschera
1003
+ // 2. aggiungere un campionamento regolare dentro la maschera
1004
+
1005
+ int count = 0 ;
1006
+
1007
+ for (int i = 0 ; i < point_cloud.size (); i++) {
1008
+
1009
+ Eigen::Vector3f point = point_cloud[i];
1010
+ Eigen::Vector3f pixel = realToPixelCoord (point[0 ], point[1 ], point[2 ]);
1011
+
1012
+ int mx = std::max<float >(0 , std::min<float >(width-1 , int (pixel[0 ])));
1013
+ int my = std::max<float >(0 , std::min<float >(height-1 , int (pixel[1 ])));
1014
+
1015
+ bool inside = mask[mx + my*width] == 0 .0f ;
1016
+ if (inside)
1017
+ continue ;
1018
+
1019
+ point_cloud[count++] = point;
1020
+ }
1021
+ point_cloud.resize (count);
1022
+
1023
+
1024
+ int step = 10 ;
1025
+
1026
+ for (int y = 0 ; y < height; y+= step) {
1027
+ for (int x = 0 ; x < width; x += step) {
1028
+ bool inside = mask[x + y*width] == 0 .0f ;
1029
+ if (!inside)
1030
+ continue ;
1031
+ auto point = pixelToRealCoordinates (x, y, elevation[x + y*width]);
1032
+ point_cloud.push_back (point);
1033
+ }
1034
+ }
1035
+
1002
1036
for (size_t i = 0 ; i < point_cloud.size (); i++) {
1003
1037
1004
1038
Eigen::Vector3f realCoord = point_cloud[i];
@@ -1023,14 +1057,19 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
1023
1057
}
1024
1058
1025
1059
GaussianGrid gaussianGrid;
1060
+ gaussianGrid.minSamples = 3 ; // 1, 3, 5
1061
+ gaussianGrid.sideFactor = 1 ; // 0.25, 0.5, 1
1026
1062
gaussianGrid.init (imageCloud, source);
1027
1063
gaussianGrid.imageGrid ((" test.png" ));
1028
1064
1065
+ static float c = 1 .0f ;
1029
1066
float ortho_z = realToPixelCoord (0 ,0 ,z)[2 ];
1030
1067
1031
1068
for (size_t y=0 ; y < height; y++){
1032
1069
for (size_t x=0 ; x < width; x++){
1033
- // if(x,y )
1070
+ if (mask[x + y * width] != 0 .0f ){
1071
+ continue ;
1072
+ }
1034
1073
Eigen::Vector3f r = pixelToRealCoordinates (x, y, ortho_z);
1035
1074
assert (fabs (z-r[2 ]) < 0 .1f );
1036
1075
Eigen::Vector3f p = camera.camera .projectionToImage (r);
@@ -1046,16 +1085,19 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
1046
1085
Eigen::Vector3f d = realToPixelCoord (r[0 ], r[1 ], h);
1047
1086
1048
1087
float w = camera.calculateWeight (px, py);
1049
-
1050
1088
// p0 e p1 devono venire uguale e vedi se depth è ugusle, h dovrebbe venire simile
1089
+
1051
1090
elevation[x + y * width] += w * d[2 ];
1052
- mask[x+ y * width] += w;
1053
- } else {
1091
+
1092
+ weights[x+ y * width] += w;
1093
+
1094
+ }else {
1054
1095
// elevation[x + y*width] = origin[2] + resolution[2] * elevation[x + y*width];
1055
1096
}
1056
1097
}
1057
1098
}
1058
- saveObj (" testElev.obj" );
1099
+
1100
+
1059
1101
}
1060
1102
/* _-----------------------------------------------------------------------------------------*/
1061
1103
void GaussianGrid::fitLinear (std::vector<float > &x, std::vector<float > &y, float &a, float &b) {
@@ -1107,7 +1149,7 @@ float GaussianGrid::bilinearInterpolation(float x, float y) {
1107
1149
}
1108
1150
// fit h = a+b*elev
1109
1151
void GaussianGrid::init (std::vector<Eigen::Vector3f> &cloud, std::vector<float > &source) {
1110
- int side = static_cast <int >(sqrt (cloud.size ())) / 2 ;
1152
+ int side = static_cast <int >(sideFactor * sqrt (cloud.size ()));
1111
1153
sigma = 1 .0f / side;
1112
1154
width = side;
1113
1155
height = side;
@@ -1220,7 +1262,7 @@ float GaussianGrid::value(float x, float y){
1220
1262
float pixelX = x * (width-1 );
1221
1263
float pixelY = y * (height-1 );
1222
1264
1223
- return bilinearInterpolation (pixelX, pixelY);
1265
+ return bilinearInterpolation (pixelX, pixelY);
1224
1266
1225
1267
// return values[pixelX + pixelY * width];
1226
1268
@@ -1247,7 +1289,7 @@ void GaussianGrid::computeGaussianWeightedGrid(std::vector<Eigen::Vector3f> &dif
1247
1289
std::vector<int > count (width*height, 0 );
1248
1290
1249
1291
1250
- float max_distance = 1. 2 * sigma;
1292
+ float max_distance = 2 * sigma;
1251
1293
for (auto &p : differences) {
1252
1294
1253
1295
@@ -1271,14 +1313,14 @@ void GaussianGrid::computeGaussianWeightedGrid(std::vector<Eigen::Vector3f> &dif
1271
1313
}
1272
1314
}
1273
1315
}
1274
- // chiama camere tutte e 4 e vedi come vengono
1316
+ // chiama camere tutte e 4 e vedi come vengono
1275
1317
// pesare per il blanding funzione intervallo 0, 1 * 0, 1 0 ai bordi 1 al centro, che sia una funzione continua
1276
1318
// polinomio di 2 grado in x * pol 2 grado in y. derivata e peso a 0 sul bordo
1277
1319
// fai somma pesata e veedi come vieni
1278
1320
// funz target ritorna valore e peso
1279
1321
1280
1322
for (int i = 0 ; i < values.size (); i++) {
1281
- if (count[i] < 3 )
1323
+ if (count[i] < minSamples )
1282
1324
weights[i] = 0 ;
1283
1325
if (weights[i] != 0 ) {
1284
1326
values[i] /= (weights[i]);
@@ -1290,29 +1332,48 @@ void GaussianGrid::computeGaussianWeightedGrid(std::vector<Eigen::Vector3f> &dif
1290
1332
}
1291
1333
}*/
1292
1334
}
1293
- //
1294
- float Depthmap::calculateWeight (float x, float y) const {
1335
+ // se < 1/4 è -8x^2, else se è < 3/4. 8*(x-1)^2, data una x mi ritorna una x+1
1336
+
1337
+ static float bell (float x){
1338
+ if (x < 0 .25f ){
1339
+ return 8 .0f * x * x;
1340
+ }
1341
+ else if (x< 0 .75f ){
1342
+ return -8 .0f * x *x + 8 .0f * x-1 .0f ;
1343
+ }
1344
+ else {
1345
+ x = 1 .0f - x;
1346
+ return 8 .0f * x * x;
1347
+ }
1295
1348
1296
- x/=width;
1297
- y/= height;
1349
+ }
1298
1350
1299
- float weightX =pow (cos (M_PI * (x-0 .5f )), 2 );
1300
- float weightY = pow (cos (M_PI * (y-0 .5f )), 2 );
1351
+ float Depthmap::calculateWeight (float x, float y) const {
1301
1352
1302
- return weightX * weightY;
1353
+ x /= width;
1354
+ y /= height;
1355
+
1356
+ // float weightX =pow(cos(M_PI * (x-0.5f)), 2);
1357
+ // float weightY = pow(cos(M_PI * (y-0.5f)), 2);
1358
+ return bell (x)*bell (y);
1359
+ // return weightX * weightY;
1303
1360
}
1304
1361
void OrthoDepthmap::beginIntegration (){
1305
- elevation.clear ();
1306
- elevation.resize (width * height, 0 );
1307
- mask.clear ();
1308
- mask.resize (width * height, 0 );
1362
+ for (size_t i =0 ; i < elevation.size (); i++){
1363
+ if (mask[i] == 0 .0f ){
1364
+ elevation[i] = 0 .0f ;
1365
+ }
1366
+ }
1367
+ // elevation.clear();
1368
+ // elevation.resize(width * height, 0);
1369
+ // weights.clear();
1370
+ // weights.resize(width * height, 0);
1309
1371
1310
1372
}
1311
1373
void OrthoDepthmap::endIntegration (){
1312
1374
for (size_t i =0 ; i < elevation.size (); i++){
1313
- if (mask[i]){
1314
- elevation[i] /= mask[i];
1315
- }
1375
+ // if(mask[i] == 0.0f) {// && weights[i] != 0.0f){
1376
+ elevation[i] =4 ; // /= weights[i];
1316
1377
}
1317
1378
}
1318
1379
0 commit comments