@@ -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
@@ -981,7 +981,73 @@ void OrthoDepthmap::verifyPointCloud(){
981
981
*/
982
982
}
983
983
}
984
+ // #define PRESERVE_INTERIOR
984
985
986
+ void OrthoDepthmap::beginIntegration (){
987
+
988
+ bool use_depthmap = false ;
989
+ if (use_depthmap) {
990
+ // 1. togliere dalla point tutti i punti che cadono dentro la maschera
991
+ // 2. aggiungere un campionamento regolare dentro la maschera
992
+ int count = 0 ;
993
+ for (size_t i = 0 ; i < point_cloud.size (); i++) {
994
+
995
+ Eigen::Vector3f point = point_cloud[i];
996
+ Eigen::Vector3f pixel = realToPixelCoord (point[0 ], point[1 ], point[2 ]);
997
+
998
+ int mx = std::max<float >(0 , std::min<float >(width-1 , int (pixel[0 ])));
999
+ int my = std::max<float >(0 , std::min<float >(height-1 , int (pixel[1 ])));
1000
+
1001
+ bool inside = mask[mx + my*width] == 0 .0f ;
1002
+ if (inside)
1003
+ continue ;
1004
+
1005
+ point_cloud[count++] = point;
1006
+ }
1007
+ point_cloud.resize (count);
1008
+
1009
+ int step = 1 ;
1010
+
1011
+ for (int y = 0 ; y < height; y+= step) {
1012
+ for (int x = 0 ; x < width; x += step) {
1013
+ bool inside = (mask[x + y*width] != 0 .0f );
1014
+ if (!inside)
1015
+ continue ;
1016
+ auto point = pixelToRealCoordinates (x, y, elevation[x + y*width]);
1017
+ point_cloud.push_back (point);
1018
+ }
1019
+ }
1020
+ }
1021
+
1022
+ for (size_t i =0 ; i < elevation.size (); i++) {
1023
+ #ifdef PRESERVE_INTERIOR
1024
+ if (mask[i] == 0 .0f ){
1025
+ #endif
1026
+ elevation[i] = 0 .0f ;
1027
+ #ifdef PRESERVE_INTERIOR
1028
+ }
1029
+ #endif
1030
+ }
1031
+ // elevation.clear();
1032
+ // elevation.resize(width * height, 0);
1033
+ weights.clear ();
1034
+ weights.resize (width * height, 0 );
1035
+
1036
+ }
1037
+
1038
+ void OrthoDepthmap::endIntegration (){
1039
+ for (size_t i =0 ; i < elevation.size (); i++){
1040
+ #ifdef PRESERVE_INTERIOR
1041
+ if (mask[i] == 0 .0f ) {
1042
+ #endif
1043
+ if (weights[i] != 0 .0f ) {
1044
+ elevation[i] /= weights[i];
1045
+ }
1046
+ #ifdef PRESERVE_INTERIOR
1047
+ }
1048
+ #endif
1049
+ }
1050
+ }
985
1051
986
1052
void OrthoDepthmap::integratedCamera (const CameraDepthmap& camera, const char *outputFile){
987
1053
@@ -999,40 +1065,6 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
999
1065
std::vector<Eigen::Vector3f> imageCloud;
1000
1066
std::vector<float > source;
1001
1067
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
-
1036
1068
for (size_t i = 0 ; i < point_cloud.size (); i++) {
1037
1069
1038
1070
Eigen::Vector3f realCoord = point_cloud[i];
@@ -1047,11 +1079,9 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
1047
1079
1048
1080
if (pixelX >= 0 && pixelX < camera.width && pixelY >= 0 && pixelY < camera.height ) {
1049
1081
float depthValue = camera.elevation [pixelX + pixelY * camera.width ];
1050
- cout << pixelX << " " << pixelY << " " << depthValue << endl;
1051
1082
imageCloud.push_back (Eigen::Vector3f (imageCoords[0 ]/camera.width , imageCoords[1 ]/camera.height , h));
1052
1083
source.push_back (depthValue);
1053
1084
out << depthValue << " \t " << h << " \t " << imageCoords[0 ]/camera.width << " \t " << imageCoords[1 ]/camera.height <<" \n " ; // red e green
1054
-
1055
1085
}
1056
1086
1057
1087
}
@@ -1062,14 +1092,15 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
1062
1092
gaussianGrid.init (imageCloud, source);
1063
1093
gaussianGrid.imageGrid ((" test.png" ));
1064
1094
1065
- static float c = 1 .0f ;
1066
1095
float ortho_z = realToPixelCoord (0 ,0 ,z)[2 ];
1067
1096
1068
1097
for (size_t y=0 ; y < height; y++){
1069
1098
for (size_t x=0 ; x < width; x++){
1099
+ #ifdef PRESERVE_INTERIOR
1070
1100
if (mask[x + y * width] != 0 .0f ){
1071
1101
continue ;
1072
1102
}
1103
+ #endif
1073
1104
Eigen::Vector3f r = pixelToRealCoordinates (x, y, ortho_z);
1074
1105
assert (fabs (z-r[2 ]) < 0 .1f );
1075
1106
Eigen::Vector3f p = camera.camera .projectionToImage (r);
@@ -1081,6 +1112,7 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
1081
1112
float depthValue = camera.elevation [px + py * camera.width ];
1082
1113
p[0 ] = px / float (camera.width );
1083
1114
p[1 ] = py / float (camera.height );
1115
+
1084
1116
float h = gaussianGrid.target (p[0 ], p[1 ], depthValue);
1085
1117
Eigen::Vector3f d = realToPixelCoord (r[0 ], r[1 ], h);
1086
1118
@@ -1091,7 +1123,7 @@ void OrthoDepthmap::integratedCamera(const CameraDepthmap& camera, const char *o
1091
1123
1092
1124
weights[x+ y * width] += w;
1093
1125
1094
- }else {
1126
+ } else {
1095
1127
// elevation[x + y*width] = origin[2] + resolution[2] * elevation[x + y*width];
1096
1128
}
1097
1129
}
@@ -1358,24 +1390,6 @@ float Depthmap::calculateWeight(float x, float y) const{
1358
1390
return bell (x)*bell (y);
1359
1391
// return weightX * weightY;
1360
1392
}
1361
- void OrthoDepthmap::beginIntegration (){
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);
1371
-
1372
- }
1373
- void OrthoDepthmap::endIntegration (){
1374
- for (size_t i =0 ; i < elevation.size (); i++){
1375
- // if(mask[i] == 0.0f) {// && weights[i] != 0.0f){
1376
- elevation[i] =4 ; // /= weights[i];
1377
- }
1378
- }
1379
1393
1380
1394
void GaussianGrid::imageGrid (const char * filename) {
1381
1395
0 commit comments