@@ -698,55 +698,56 @@ void Depthmap::resizeNormals (int factorPowerOfTwo, int step) {
698
698
// depthIntegrateNormals();
699
699
700
700
}
701
- void Depthmap::loadPointCloud (const char *textPath, std::vector<float > &points){
702
701
703
- // apri file di testo e scarta tutto quello che non è un numero. fai un char vettore di punti
704
- QFile file (textPath);
705
- if (!file.open (QIODevice::ReadOnly | QIODevice::Text)) {
706
- throw QString (" Error opening input file: " )+ textPath;
707
- }
708
702
709
- QTextStream in (&file);
703
+ /*
710
704
711
- while (!in.atEnd ()) {
712
- QString line = in.readLine ().trimmed ();
713
- QStringList parts = line.split (QRegularExpression (" \\ s+" ), Qt::SkipEmptyParts);
714
- if (line.isEmpty () || (!line[0 ].isDigit () && line[0 ] != ' -' && line[0 ] != ' +' ) || parts.size () != 6 ) {
715
- continue ;
716
- }
705
+ void Depthmap::depth(const char *depth_path){
706
+ std::vector<float> depthValues;
707
+ if (!load(depth_path)) {
708
+ cerr << "Failed to load depth map." << endl;
709
+ return;
710
+ }
711
+ for (size_t i = 0; i < depthValues.size(); i++) {
712
+ float realX = depthValues[i];
713
+ float realY = depthValues[++i];
714
+ float realZ = depthValues[++i];
717
715
718
- // check the line if the line not begin with float number break
719
- bool isValid = true ;
720
- float v[3 ];
721
- for (int i = 0 ; i < 3 ; ++i) {
722
- bool isNumber = false ;
723
- v[i] = parts[i].toFloat (&isNumber);
724
- if (!isNumber) {
725
- isValid = false ;
726
- break ;
727
- }
728
- }
729
- if (!isValid)
730
- throw QString (" Invalide ply" );
716
+ Eigen::Vector3f pixelCoords = realToPixelCoord(realX, realY, realZ);
717
+ int pixelX = pixelCoords[0];
718
+ int pixelY = pixelCoords[1];
719
+ float calcZ = pixelCoords[2];
720
+
721
+ Eigen::Vector3f = projectToCameraDepthMap(pixelCoord);
731
722
732
- for (int i = 0 ; i < 3 ; ++i){
733
- points.push_back (v[i]);
734
- }
735
723
}
736
724
737
725
}
738
726
739
727
//funzione inversa da 3d a xyh; xy z=0 h? pixel,pixel, h
740
- void Depthmap::t3DToCamera (P ){
728
+ void Depthmap::t3DToCamera(float h, ){
741
729
//xyz coord 3d fai l'inversa: aperi txt, x e y. prendi funz 3d la trosformi in x y e h e poi applichi quella già fatta camerato3d e deve venire uguale
742
730
//poi prendi apericloud e vedi se coincide con la depth
743
731
//2. scrivi la funzione inversa da un punto in 3d ci trova la x e la y in pixel e la h dalla depth del mic mac
744
732
//3. verifica se la h trovata per i punti di aperi corrisponde all h della depth map
745
733
734
+ for (size_t i = 0; i < points.size(); i += 3) {
735
+ float realX = points[i];
736
+ float realY = points[i + 1];
737
+ float realZ = points[i + 2];
746
738
747
- }
739
+ Eigen::Vector3f pixelCoords = realToPixelCoordinates(realX, realY, realZ);
740
+
741
+ int pixelX = pixelCoords[0];
742
+ int pixelY = pixelCoords[1];
743
+ float calcZ = pixelCoords[2];
748
744
749
745
746
+ float invH= (h - origin[2]) / resolution[2];
747
+ }
748
+ }
749
+
750
+ */
750
751
// take the x=160,14 e y=140
751
752
// the coordinates of the pixel step 0.016 are in the depth map xml Z_num etc.
752
753
@@ -897,14 +898,145 @@ void OrthoDepthmap::projectToCameraDepthMap(const Camera& camera, const QString&
897
898
}
898
899
depthMapImage.save (outputPath, " png" );
899
900
}
901
+
900
902
void OrthoDepthmap::resizeNormals (int factorPowerOfTwo, int step) {
901
903
int factor = 1 << factorPowerOfTwo;
902
904
Depthmap::resizeNormals (factorPowerOfTwo, step);
903
905
resolution *= factor;
904
906
origin /= factor;
905
907
}
906
908
909
+ void OrthoDepthmap::loadPointCloud (const char *textPath){
907
910
911
+ // apri file di testo e scarta tutto quello che non è un numero. fai un char vettore di punti
912
+ QFile file (textPath);
913
+ if (!file.open (QIODevice::ReadOnly | QIODevice::Text)) {
914
+ throw QString (" Error opening input file: " )+ textPath;
915
+ }
916
+
917
+ QTextStream in (&file);
918
+
919
+
920
+ while (!in.atEnd ()) {
921
+ QString line = in.readLine ().trimmed ();
922
+ QStringList parts = line.split (QRegularExpression (" \\ s+" ), Qt::SkipEmptyParts);
923
+ if (line.isEmpty () || (!line[0 ].isDigit () && line[0 ] != ' -' && line[0 ] != ' +' ) || parts.size () != 6 ) {
924
+ continue ;
925
+ }
926
+
927
+ // check the line if the line not begin with float number break
928
+ bool isValid = true ;
929
+ Eigen::Vector3f v;
930
+ for (int i = 0 ; i < 3 ; ++i) {
931
+ bool isNumber = false ;
932
+ v[i] = parts[i].toFloat (&isNumber);
933
+ if (!isNumber) {
934
+ isValid = false ;
935
+ break ;
936
+ }
937
+ }
938
+ if (!isValid)
939
+ throw QString (" Invalide ply" );
940
+
941
+ point_cloud.push_back (v);
942
+
943
+ }
944
+
945
+
946
+ }
947
+
948
+ Eigen::Vector3f OrthoDepthmap::realToPixelCoord (float realX, float realY, float realZ){
949
+ float pixelX = (realX - origin[0 ]) / resolution[0 ];
950
+ float pixelY = (realY - origin[1 ]) / resolution[1 ];
951
+ float h = (realZ - origin[2 ]) / resolution[2 ];
952
+ return Eigen::Vector3f (pixelX, pixelY, h);
953
+
954
+ }
955
+
956
+ void OrthoDepthmap::verifyPointCloud (){
957
+
958
+ for (const auto & point : point_cloud){
959
+
960
+ float realX = point[0 ];
961
+ float realY = point[1 ];
962
+ float realZ = point[2 ];
963
+
964
+ Eigen::Vector3f pixelCoord = realToPixelCoord (realX, realY, realZ);
965
+
966
+ Eigen::Vector3f realCoord = pixelToRealCoordinates (pixelCoord[0 ], pixelCoord[1 ], pixelCoord[2 ]);
967
+
968
+
969
+ // int pixelX = static_cast<int>(round(pixelCoord[0]));
970
+ // int pixelY = static_cast<int>(round(pixelCoord[1]));
971
+
972
+ int pixelX = static_cast <int >(round (pixelCoord[0 ]));
973
+ int pixelY = static_cast <int >(round (pixelCoord[1 ]));
974
+
975
+ if (pixelX < 0 || pixelX >= width || pixelY < 0 || pixelY >= height) {
976
+ continue ;
977
+ }
978
+ cerr << " point inside the image limits "
979
+ << " Point 3D: (" << realX << " , " << realY << " , " << pixelCoord[2 ] << " ), "
980
+ << " Coordinate pixel: (" << pixelX << " , " << pixelY << " " << elevation[pixelX + pixelY * width]<< " )\n " ;
981
+
982
+ }
983
+
984
+
985
+ }
986
+ void OrthoDepthmap::integratedCamera (const CameraDepthmap& camera){
987
+ int count =0 ;
988
+ for (size_t i = 0 ; i < point_cloud.size (); i++) {
989
+
990
+ Eigen::Vector3f& realCoord = point_cloud[i];
991
+ Eigen::Vector3f imageCoords = camera.camera .projectionToImage (realCoord);
992
+ Eigen::Vector3f pixelCoord = realToPixelCoord (realCoord[0 ], realCoord[1 ], realCoord[2 ]);
993
+
994
+ int pixelX = static_cast <int >(round (imageCoords[0 ]));
995
+ int pixelY = static_cast <int >(round (imageCoords[1 ]));
996
+
997
+ if (pixelX >= 0 && pixelX < camera.width && pixelY >= 0 && pixelY < camera.height ) {
998
+ float depthValue = elevation[pixelX + pixelY * camera.width ];
999
+ float h = pixelCoord[2 ];
1000
+ count++;
1001
+ cout << depthValue << h << endl;
1002
+
1003
+
1004
+ }
1005
+ }
1006
+ cout << count << endl;
1007
+ }
1008
+ // fit h = a+b*elev
1009
+
1010
+ void OrthoDepthmap::fitLinearRegressionFromPairs () {
1011
+ float sumElevation = 0 ; // Somma delle elevazioni (x)
1012
+ float sumH = 0 ; // Somma dei valori h (y)
1013
+ float sumElevationH = 0 ; // Somma delle moltiplicazioni elevation * h
1014
+ float sumElevationSquared = 0 ; // Somma delle elevazioni al quadrato
1015
+ size_t n = point_cloud.size (); // Numero di punti nella nuvola di punti
1016
+
1017
+ // Ciclo sui punti per raccogliere i dati
1018
+ for (const auto & point : point_cloud) {
1019
+ float elevation = point[0 ]; // Elevation (x)
1020
+ float h = point[2 ]; // Altezza (y)
1021
+
1022
+ sumElevation += elevation;
1023
+ sumH += h;
1024
+ sumElevationH += elevation * h;
1025
+ sumElevationSquared += elevation * elevation;
1026
+ }
1027
+
1028
+ float b = (n * sumElevationH - sumElevation * sumH) / (n * sumElevationSquared - sumElevation * sumElevation);
1029
+ float a = (sumH - b * sumElevation) / n;
1030
+
1031
+ for (const auto & point : point_cloud) {
1032
+ float elevation = point[0 ];
1033
+ float hCalculated = a + b * elevation;
1034
+ cout << " For elevation:" << elevation << " calculated h:" << hCalculated << endl;
1035
+ }
1036
+
1037
+ }
1038
+ // Real to Pixel Coordinates: (-0.981, 2.041, -11.132) -> Pixel: (110.688, 65.4375, -27.75)
1039
+ // point outside the image limits Point 3D: (-0.981, 2.041, -11.132), Coordinate pixel: (-1, 2)
908
1040
909
1041
910
1042
/* ---------------------------------------------------------------------------------------------------------------------------*/
0 commit comments