@@ -211,6 +211,53 @@ void Depthmap::computeNormals() {
211
211
}
212
212
}
213
213
}
214
+
215
+ void Depthmap::projectToCameraDepthMap (const Camera& camera, const QString& outputPath) {
216
+
217
+ QImage depthMapImage (camera.width , camera.height , QImage::Format_RGB888);
218
+ depthMapImage.fill (qRgb (0 , 0 , 0 ));
219
+ // find the minimum and maximum for the Z coordinates
220
+ float minZ = std::numeric_limits<float >::max ();
221
+ float maxZ = std::numeric_limits<float >::lowest ();
222
+ for (int y = 0 ; y < height; y++) {
223
+ for (int x = 0 ; x < width; x++) {
224
+ float pixelZ = elevation[x + y * width];
225
+
226
+ Eigen::Vector3f realCoordinates = pixelToRealCoordinates (x, y, pixelZ);
227
+ Eigen::Vector3f imageCoords = camera.projectionToImage (realCoordinates);
228
+ if (pixelZ > 0 ){
229
+ minZ = std::min (minZ, pixelZ);
230
+ maxZ = std::max (maxZ, pixelZ);
231
+ }
232
+ }
233
+ }
234
+ if (minZ >= maxZ) {
235
+ qWarning (" MinZ and MaxZ invalid. Skip depth map generation." );
236
+ return ;
237
+ }
238
+ for (int y = 0 ; y < height; y++) {
239
+ for (int x = 0 ; x < width; x++) {
240
+ float pixelZ = elevation[x + y * width];
241
+
242
+ if (pixelZ <= 0 ) continue ;
243
+ int pixelValue = (int )round (((pixelZ - minZ) / (maxZ - minZ)) * 255 );
244
+ pixelValue = std::min (std::max (pixelValue, 0 ), 255 );
245
+
246
+ Eigen::Vector3f realCoordinates = pixelToRealCoordinates (x, y, pixelZ);
247
+ Eigen::Vector3f imageCoords = camera.projectionToImage (realCoordinates);
248
+
249
+ int imageX = (int )round (imageCoords[0 ]);
250
+ int imageY= (int )round (imageCoords[1 ]);
251
+ if (imageX >= 0 && imageX < camera.width && imageY >= 0 && imageY < camera.height ) {
252
+ depthMapImage.setPixel (imageX, imageY, qRgb (pixelValue, pixelValue, pixelValue));
253
+ // cout << "Pixel projected (" << x << ", " << y << ") -> (" << imageX << ", " << imageY << "), Z = "
254
+ // << pixelZ << ", pixelValue = " << pixelValue << endl;
255
+ }
256
+ }
257
+ }
258
+ depthMapImage.save (outputPath, " png" );
259
+ }
260
+
214
261
void Depthmap::depthIntegrateNormals (){
215
262
if (normals.empty ()){
216
263
cerr << " Error: no normals found" << endl;
@@ -284,7 +331,7 @@ void Depthmap::resizeNormals (int factorPowerOfTwo, int step = 1) {
284
331
285
332
// QString filename = "/Users/erika/Desktop/testcenterRel_copia/photogrammetry/surface.jpg";
286
333
// saveNormals(filename.toStdString().c_str());
287
- // chiama l'integrale integra le normali e salva il ply
334
+ // chiama l'integrale integra le normali e salva il ply
288
335
// depthIntegrateNormals();
289
336
// QString plyFilename = "/Users/erika/Desktop/testcenterRel_copia/photogrammetry/resize_normals.obj";
290
337
// saveObj(plyFilename.toStdString().c_str());
@@ -325,6 +372,7 @@ void Depthmap::saveObj(const char *filename){
325
372
}
326
373
}
327
374
}
375
+
328
376
// prendi x=160,14 e y=140 dell'img
329
377
// le coordinate del passo del pixel 0,016 sono nel xml della depth map Z_num ecc.
330
378
@@ -488,7 +536,7 @@ bool Camera::loadInternParameters(const QString &internePath){
488
536
// ritorna pixel x e y img di l12 ori coord di pixel devono finire nell'ori-rel
489
537
// Pc = Rk(Pg − Ok)
490
538
// Pg = Ground point Pc = point camera. x y z orientati come la camera, moltiplica la matrice. Poi fai la proiezione.
491
- Eigen::Vector3f Camera::projectionToImage (Eigen::Vector3f realPosition){
539
+ Eigen::Vector3f Camera::projectionToImage (Eigen::Vector3f realPosition) const {
492
540
// centre origine
493
541
// r matrice
494
542
// matrice r inversa rotation
@@ -513,7 +561,7 @@ Eigen::Vector3f Camera::projectionToImage(Eigen::Vector3f realPosition){
513
561
514
562
}
515
563
516
- Eigen::Vector3f Camera::applyIntrinsicCalibration (Eigen::Vector3f& uvz) {
564
+ Eigen::Vector3f Camera::applyIntrinsicCalibration (Eigen::Vector3f& uvz) const {
517
565
518
566
float u = uvz.x ();
519
567
float v = uvz.y ();
@@ -539,9 +587,3 @@ Eigen::Vector3f Camera::applyRadialDistortion(Eigen::Vector3f& uvz) {
539
587
540
588
return Eigen::Vector3f (u_dist, v_dist, uvz.z ());
541
589
}
542
-
543
-
544
-
545
-
546
-
547
-
0 commit comments