Skip to content

Commit 3dd942b

Browse files
added functions to save Mask and Depth, and refactored
1 parent dc1018c commit 3dd942b

File tree

6 files changed

+73
-45
lines changed

6 files changed

+73
-45
lines changed

depthmap/depthmap.cpp

+24-12
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool Camera::loadXml(const QString &pathXml){
6565
return false;
6666
}
6767
QString internePath = fileInterneNode.text();
68-
QFileInfo fileInfo(fileInterneNode.text());
68+
QFileInfo fileInfo(pathXml);
6969
QString dirPath = fileInfo.path();
7070
QDir dir(dirPath);
7171
dir.cd("..");
@@ -255,12 +255,6 @@ bool Depthmap::loadTiff(const char *tiff, vector<float> &values, uint32_t &w, ui
255255
} else {
256256
return loadTiledTiff(inTiff, values, w, h, tileWidth, tileLength, bitsPerSample);
257257
}
258-
tsize_t tileSize = TIFFTileSize(inTiff);
259-
if (tileSize == 0) {
260-
cerr << "Error computing tile size." << endl;
261-
TIFFClose(inTiff);
262-
return 1;
263-
}
264258

265259
return true;
266260

@@ -351,6 +345,7 @@ bool Depthmap::loadTiledTiff(TIFF* inTiff, vector<float> &values, uint32_t w, ui
351345
}
352346
delete[] tileData;
353347
}
348+
TIFFClose(inTiff);
354349
return true;
355350
}
356351

@@ -404,6 +399,7 @@ bool Depthmap::loadStripedTiff(TIFF* inTiff, std::vector<float> &values, uint32_
404399
}
405400
delete[] stripData;
406401
}
402+
TIFFClose(inTiff);
407403
return true;
408404
}
409405

@@ -412,7 +408,7 @@ bool Depthmap::loadDepth(const char *tiff) {
412408
cerr << "Failed to load TIFF file: " << tiff << endl;
413409
return false;
414410
}
415-
411+
return true;
416412
}
417413

418414
bool Depthmap::loadMask(const char *tifPath){
@@ -464,7 +460,7 @@ bool Depthmap::loadNormals(const char *normals_path){
464460

465461
return true;
466462
}
467-
void Depthmap::saveMask(const char *mask_path, vector<float> &values, uint32_t &w, uint32_t &h, uint32_t bitsPerSample){
463+
void Depthmap::saveTiff(const char *mask_path, vector<float> &values, uint32_t &w, uint32_t &h, uint32_t bitsPerSample){
468464
//save e scrive la maschera
469465

470466
TIFF* maskTiff = TIFFOpen(mask_path, "w");
@@ -521,6 +517,12 @@ void Depthmap::saveMask(const char *mask_path, vector<float> &values, uint32_t &
521517
}
522518
TIFFClose(maskTiff);
523519
}
520+
void Depthmap::saveDepth(const char *depth_path){
521+
saveTiff(depth_path, elevation, width, height, 32);
522+
}
523+
void Depthmap::saveMask(const char *depth_path){
524+
saveTiff(depth_path, mask, width, height, 1);
525+
}
524526
void Depthmap::saveNormals(const char *filename) {
525527

526528
QImage img(width, height, QImage::Format::Format_ARGB32);
@@ -727,11 +729,21 @@ bool OrthoDepthmap::loadXml(const char *xmlPath){
727729

728730
}
729731

730-
bool OrthoDepthmap::load(const char *filepath){
732+
bool OrthoDepthmap::load(const char *depth_path, const char *mask_path){
731733

732-
QString tiffPath = QString(filepath);
733-
QString xmlPath = tiffPath.left(tiffPath.lastIndexOf('.')) + ".xml";
734+
QString qdepth_path = QString(depth_path);
735+
if(!loadDepth(qdepth_path.toStdString().c_str())){
736+
cerr << "Failed to load tiff file: " << qdepth_path.toStdString() << endl;
737+
return false;
738+
}
739+
740+
QString qmask_path = QString(mask_path);
741+
if(!loadMask(qmask_path.toStdString().c_str())){
742+
cerr << "Failed to load tiff file: " << qmask_path.toStdString() << endl;
743+
return false;
744+
}
734745

746+
QString xmlPath = qdepth_path.left(qdepth_path.lastIndexOf('.')) + ".xml";
735747
if (!loadXml(xmlPath.toStdString().c_str())) {
736748
cerr << "Failed to load XML file: " << xmlPath.toStdString() << endl;
737749
return false;

depthmap/depthmap.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Depthmap {
4242
bool loadMask(const char *mask_path);
4343
bool loadNormals(const char *normals_path);
4444
void saveDepth(const char *depth_path);
45-
void saveMask(const char *mask_path, std::vector<float> &values, uint32_t &w, uint32_t &h, uint32_t bitsPerSample);
45+
void saveMask(const char *depth_path);
4646
void saveNormals(const char *normals_path);
4747

4848
float calculateMeanDepth(const std::vector<float>& values);
@@ -56,6 +56,7 @@ class Depthmap {
5656
bool loadTiledTiff(TIFF* inTiff, std::vector<float> &elevation, uint32_t w, uint32_t h,
5757
uint32_t tileWidth, uint32_t tileLength, uint32_t bitsPerSample);
5858
bool loadStripedTiff(TIFF* inTiff, std::vector<float> &elevation, uint32_t& w, uint32_t& h, uint32_t bitsPerSample);
59+
void saveTiff(const char *mask_path, std::vector<float> &values, uint32_t &w, uint32_t &h, uint32_t bitsPerSample);
5960

6061
};
6162
class CameraDepthmap:
@@ -74,7 +75,7 @@ class OrthoDepthmap:
7475
Eigen::Vector3f origin;
7576

7677
Eigen::Vector3f pixelToRealCoordinates(int pixelX, int pixelY, float pixelZ);
77-
bool load(const char *filepath);
78+
bool load(const char *depth_path, const char *mask_path);
7879
bool loadXml(const char *xmlPath);
7980
void saveObj(const char *filename);
8081
void projectToCameraDepthMap(const Camera& camera, const QString& outputPath);

depthmap/depthmap.pro

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ SOURCES += \
1313
../src/bni_normal_integration.cpp \
1414
depthmap.cpp \
1515
main.cpp
16-
INCLUDEPATH += /opt/homebrew/include \
17-
/opt/homebrew/Cellar/eigen/3.4.0_1/include/eigen3
16+
mac:INCLUDEPATH += /opt/homebrew/include
17+
unix:INCLUDEPATH += ../external/eigen-3.3.9
1818

1919
# Default rules for deployment.
2020
qnx: target.path = /tmp/$${TARGET}/bin

depthmap/main.cpp

+41-27
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,54 @@ int main(int argc, char *argv[]) {
1414
return 1;
1515
}*/
1616
//input
17-
QString depthmapPath = "/Users/erika/Desktop/testcenterRel_copia/photogrammetry/Malt/Z_Num7_DeZoom4_STD-MALT.tif";
18-
QString orientationXmlPath = "/Users/erika/Desktop/testcenterRel_copia/photogrammetry/Ori-Relative/Orientation-L05C12.tif.xml";
19-
QString maskPath = "/Users/erika/Desktop/testcenterRel_copia/photogrammetry/Malt/Masq_STD-MALT_DeZoom4.tif";
17+
//#define MACOS 1
18+
#ifdef MACOS
19+
QString base = "/User/erika/Desktop/";
20+
#else
21+
QString base = "/home/erika/";
22+
#endif
23+
24+
QString depthmapPath = base + "testcenterRel_copia/photogrammetry/Malt/Z_Num7_DeZoom4_STD-MALT.tif";
25+
QString orientationXmlPath = base + "testcenterRel_copia/photogrammetry/Ori-Relative/Orientation-L05C12.tif.xml";
26+
QString maskPath = base + "testcenterRel_copia/photogrammetry/Malt/Masq_STD-MALT_DeZoom4.tif";
27+
2028

2129
//output
22-
QString outputPath = "/Users/erika/Desktop/testcenterRel_copia/photogrammetry/depthmap_projectL05C13.png";
30+
QString outputPath = base + "testcenterRel_copia/photogrammetry/depthmap_projectL05C13.png";
31+
QString output_mask = base + "testcenterRel_copia/photogrammetry/mask_test.png";
32+
QString output_depth = base + "testcenterRel_copia/photogrammetry/depth_test.png";
2333
Depthmap depth;
2434
OrthoDepthmap ortho;
2535

26-
depth.loadDepth(qPrintable(depthmapPath));
27-
depth.computeNormals();
28-
depth.loadNormals("/Users/erika/Desktop/testcenterRel_copia/rti/L05C12/means.png");
29-
depth.saveNormals("/Users/erika/Desktop/testcenterRel_copia/photogrammetry/original.obj");
30-
ortho.saveObj("/Users/erika/Desktop/testcenterRel_copia/photogrammetry/original.obj");
36+
if(!ortho.load(qPrintable(depthmapPath), qPrintable(maskPath))){
37+
cout <<"accidenti" << endl;
38+
return -1;
39+
}
40+
//ortho.computeNormals();
41+
//ortho.saveNormals(qPrintable(base + "testcenterRel_copia/photogrammetry/original.png"));
42+
//ortho.saveObj(qPrintable(base + "testcenterRel_copia/photogrammetry/original.obj"));
43+
ortho.saveDepth(qPrintable(output_depth));
44+
ortho.saveMask(qPrintable(output_mask));
45+
46+
Camera camera;
47+
camera.loadXml(orientationXmlPath);
48+
//int pixelX = 165;
49+
//int pixelY = 144;
50+
//float pixelZ = 4.5;
51+
ortho.projectToCameraDepthMap(camera, outputPath);
52+
53+
Eigen::Matrix3f rotationMatrix;
54+
Eigen::Vector3f center;
3155

32-
depth.loadMask(qPrintable(maskPath));
33-
depth.saveDepth(qPrintable(depthmapPath));
56+
// depth.loadMask(qPrintable(maskPath));
57+
// depth.saveDepth(qPrintable(depthmapPath));
3458
// depth.saveMask(qPrintable(maskPath));
35-
//QString maskObjPath = "/Users/erika/Desktop/testcenterRel_copia/photogrammetry/mask.obj";
36-
ortho.saveObj("/Users/erika/Desktop/testcenterRel_copia/photogrammetry/depthmap_projectL05C13.obj");
59+
//QString maskObjPath = base + "testcenterRel_copia/photogrammetry/mask.obj";
60+
// ortho.saveObj(qPrintable(base + "testcenterRel_copia/photogrammetry/depthmap_projectL05C13.obj"));
3761

3862

39-
depth.depthIntegrateNormals();
40-
ortho.saveObj("/Users/erika/Desktop/testcenterRel_copia/photogrammetry/integrated.obj");
63+
//depth.depthIntegrateNormals();
64+
// ortho.saveObj(qPrintable(base + "testcenterRel_copia/photogrammetry/integrated.obj"));
4165

4266

4367

@@ -78,21 +102,11 @@ fai la formula inversa, inverti la matrice. interpola bilinarmente dati 4 valori
78102
/*int factorPowerOfTwo = 1;
79103
depth.resizeNormals(factorPowerOfTwo, 2);
80104
depth.depthIntegrateNormals();
81-
depth.saveNormals("/Users/erika/Desktop/testcenterRel_copia/photogrammetry/resized_integrated2.jpg");
82-
depth.saveObj("/Users/erika/Desktop/testcenterRel_copia/photogrammetry/resized_integrated2.obj");*/
83-
105+
depth.saveNormals(base + "testcenterRel_copia/photogrammetry/resized_integrated2.jpg");
106+
depth.saveObj(base + "testcenterRel_copia/photogrammetry/resized_integrated2.obj");*/
84107

85108

86109

87-
Camera camera;
88-
camera.loadXml(orientationXmlPath);
89-
//int pixelX = 165;
90-
//int pixelY = 144;
91-
//float pixelZ = 4.5;
92-
ortho.projectToCameraDepthMap(camera, outputPath);
93-
94-
Eigen::Matrix3f rotationMatrix;
95-
Eigen::Vector3f center;
96110

97111
//depth.getOrientationVector(orientationXmlPath, rotationMatrix, center);
98112
//Eigen::Vector3f realCoordinates = depth.pixelToRealCoordinates(pixelX, pixelY, pixelZ);

relight-pano/exiftransplant.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "exiftransplant.h"
2-
#include <iostream>
32
#include <stdio.h>
43
#include <unistd.h>
54
#include <string>
5+
#include <stdint.h>
66
using namespace std;
77

88
static void swap16(uint16_t &us) {
@@ -17,6 +17,7 @@ bool ExifTransplant::transplant(const char *src_path, const char *dst_path) {
1717
return false;
1818
}
1919

20+
2021
unsigned int exif_size;
2122
unsigned char *exif = getExif(src, exif_size);
2223
fclose(src);

relight-pano/relight-pano.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ HEADERS += \
2222
panobuilder.h
2323

2424
mac:INCLUDEPATH += /opt/homebrew/include/eigen3
25-
25+
unix:INCLUDEPATH += ../external/eigen-3.3.9
2626

2727
# Default rules for deployment.
2828
qnx: target.path = /tmp/$${TARGET}/bin

0 commit comments

Comments
 (0)