cdcseacave / openMVS

open Multi-View Stereo reconstruction library
http://cdcseacave.github.io
GNU Affero General Public License v3.0
3.3k stars 905 forks source link

ReconstructMesh on mac getting Segmantation fault #927

Open bryanjjohnson opened 1 year ago

bryanjjohnson commented 1 year ago

I compiled openMVS on my Mac using these commands:

cmake .. -DOpenMVS_USE_CUDA=OFF -DVCG_ROOT=../../vcglib -DCMAKE_BUILD_TYPE=Release -DOpenMVS_USE_SSE=OFF
cmake --build . -j4

It completed successfully. I started a sample project in COLMAP, then used InterfaceCOLMAP to move to using openMVS to finish. DensifyPointCloud ran successfully and produced a proj_dense.mvs and a proj_dense.ply successfully (I'm able to see the dense point cloud in MeshLab). But when I run $oMVS/ReconstructMesh proj_dense.mvs I get the following output:

12:42:58 [App     ] Build date: Jan 10 2023, 08:35:17
12:42:58 [App     ] CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz (8 cores)
12:42:58 [App     ] RAM: 16.00GB Physical Memory 16.00GB Virtual Memory
12:42:58 [App     ] OS: Darwin 21.6.0 (x86_64)
12:42:58 [App     ] Disk: 
12:42:58 [App     ] SSE & AVX compatible CPU & OS detected
12:42:58 [App     ] Command line: ReconstructMesh proj_dense.mvs
12:42:59 [App     ] Scene loaded (1s34ms):
    11 images (11 calibrated) with a total of 16.79 MPixels (1.53 MPixels/image)
    1205040 points, 0 vertices, 0 faces
Points inserted 1205040 (100%, 6s142ms)           
Segmentation fault: 11

Any ideas on how to fix this?

apurvazaveri commented 1 year ago

I am getting similar problem:

ReconstructMesh --working-folder /Users/apzaveri/Documents/calib_output/colmap_output/dense/0 --export-type ply --max-threads 0 --verbosity 5 --input-file model_colmap_dense.mvs --output-file model_colmap_dense_mesh.mvs --min-point-distance 8.3 --integrate-only-roi 0 --constant-weight 1 --free-space-support 0 --thickness-factor 1 --quality-factor 1 --decimate 1 --target-face-num 0 --remove-spurious 20 --remove-spikes 1 --close-holes 10 --smooth 2 --edge-length 0 --roi-border 0 --crop-to-roi 1 --archive-type 0
15:54:26 [App     ] Build date: Nov 30 2022, 09:52:03
15:54:26 [App     ] CPU: Intel(R) Xeon(R) W-3245 CPU @ 3.20GHz (32 cores)
15:54:26 [App     ] RAM: 128.00GB Physical Memory 128.00GB Virtual Memory
15:54:26 [App     ] OS: Darwin 22.2.0 (x86_64)
15:54:26 [App     ] Disk:
15:54:26 [App     ] SSE & AVX compatible CPU & OS detected
15:54:26 [App     ] Command line: ReconstructMesh --working-folder /Users/apzaveri/Documents/calib_output/colmap_output/dense/0 --export-type ply --max-threads 0 --verbosity 5 --input-file model_colmap_dense.mvs --output-file model_colmap_dense_mesh.mvs --min-point-distance 8.3 --integrate-only-roi 0 --constant-weight 1 --free-space-support 0 --thickness-factor 1 --quality-factor 1 --decimate 1 --target-face-num 0 --remove-spurious 20 --remove-spikes 1 --close-holes 10 --smooth 2 --edge-length 0 --roi-border 0 --crop-to-roi 1 --archive-type 0
15:54:26 [App     ] Scene loaded (63ms):
    14 images (14 calibrated) with a total of 7.02 MPixels (0.50 MPixels/image)
    96178 points, 0 vertices, 0 faces
Points inserted 96178 (100%, 551ms)
[1]    80904 segmentation fault   --working-folder  --export-type ply --max-threads 0 --verbosity 5      8.3

Here's the way I build it.

cmake .. -DCMAKE_TOOLCHAIN_FILE=../../vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release

cmake --build . -j4
apurvazaveri commented 1 year ago

I debugged it a little bit and here's where it seg faults: link

Is this an Eigen compatibility issue? If so any idea how to fix it?

otool -L /Users/apzaveri/Documents/openMVS/make/bin/ReconstructMesh
    /usr/local/lib/libomp.dylib (compatibility version 5.0.0, current version 5.0.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2022.44.149)
    /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0)
    /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
    /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
    /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1463.4.2)
    /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
    /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 905.6.0)
apurvazaveri commented 1 year ago

FYI: I downgraded Eigen to 3.3.9 from 3.40 and build OpenMVS again and that did not work (same behavior). I also downgraded Eigen to 3.2.1 and that seems to be too old now and does not build.

Any recommendation on what I should try next?

cdcseacave commented 1 year ago

I saw strange behavior in Eigen code before on mac and linux, and did not find a solution however pls run this in Debug mode so we can see detailed crash info

bryanjjohnson commented 1 year ago

@cdcseacave Is there a specific debug flag to use when running, or do I need to try and run cmake in BUILD_TYPE=Debug?

cdcseacave commented 1 year ago

pls compile in Debug mode

bryanjjohnson commented 1 year ago

setup vcpkg and remade the project using:

cmake .. -DOpenMVS_USE_CUDA=OFF -DCMAKE_BUILD_TYPE=Debug -DOpenMVS_USE_SSE=OFF -DOpenMVS_USE_OPENMP=OFF
cmake --build . -j4

Got the following output running ReconstructMesh

11:55:54 [App     ] Build date: Feb 10 2023, 11:46:04
11:55:54 [App     ] CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz (8 cores)
11:55:54 [App     ] RAM: 16.00GB Physical Memory 16.00GB Virtual Memory
11:55:54 [App     ] OS: Darwin 21.6.0 (x86_64)
11:55:54 [App     ] Disk: 
11:55:54 [App     ] SSE & AVX compatible CPU & OS detected
11:55:54 [App     ] Command line: ReconstructMesh proj_dense.mvs -v 5
11:56:07 [App     ] Scene loaded (13s249ms):
    11 images (11 calibrated) with a total of 16.79 MPixels (1.53 MPixels/image)
    1163829 points, 0 vertices, 0 faces
11:58:29 [App     ] Delaunay tetrahedralization completed: 1163829 points -> 487564 vertices, 3123220 (+182) cells, 6246531 (+273) faces (2m21s708ms)
12:38:27 [App     ]     weighting completed in 39m43s392ms
12:38:27 [App     ] Delaunay tetrahedras weighting completed: 3123402 cells, 6246804 faces (39m58s379ms)
12:38:54 [App     ] Delaunay tetrahedras graph-cut completed (301431 flow): 474408 vertices, 949234 faces (26s446ms)
12:39:16 [App     ] Fixed 62/100 non-manifold edges/vertices and 341 faces removed: 39 pyramid3 and 56 pyramid4 (21s677ms)
12:39:37 [App     ] Fixed 15/40 non-manifold edges/vertices and 99 faces removed: 5 pyramid3 and 21 pyramid4 (21s265ms)
12:39:58 [App     ] Fixed 2/10 non-manifold edges/vertices and 19 faces removed: 1 pyramid3 and 4 pyramid4 (21s476ms)
12:40:20 [App     ] Fixed 1/2 non-manifold edges/vertices and 4 faces removed: 0 pyramid3 and 1 pyramid4 (21s302ms)
12:40:20 [App     ] Mesh reconstruction completed: 474514 vertices, 948980 faces (44m12s477ms)
12:40:20 [App     ] Mesh saved: 474514 vertices, 948980 faces (186ms)
12:40:20 [App     ] Removed 0 zero-area faces
12:40:21 [App     ] Removed 14 duplicate faces
12:40:21 [App     ] Removed 0 unreferenced vertices
12:40:23 [App     ] Removed 2 non-manifold faces
12:40:23 [App     ] Removed 0 degenerate vertices
12:40:24 [App     ] Removed 72 duplicate vertices
12:40:27 [App     ] Split 70 non-manifold vertices
12:40:30 [App     ] Split 0 non-manifold vertices
12:40:31 [App     ] Removed 1018 faces with edges longer than 0.508619
12:40:34 [App     ] Removed 25 connected components out of 36
Assertion failed: (f->FFp(z)->FFp(f->FFi(z))==f), function FlipF, file pos.h, line 198.
Abort trap: 6

Looks like there was an abort message sent and though a proj_dense_mesh_raw.ply was outputted, no proj_dense_mesh.mvs was outputted.

Oddly enough, the ReconstructMesh seems to go further when I compile under Debug, then when I compile under Release.

cdcseacave commented 1 year ago

if compiling in release, there are no asserts!

bryanjjohnson commented 1 year ago

What I mean, is when I compile under release, I don't even get a proj_dense_mesh_raw.ply, but when I compile in debug, it goes get to the point of generating that file.

cdcseacave commented 1 year ago

pls supply a small dataset that reproduces the problem

bryanjjohnson commented 1 year ago

Here is the workspace file with the sample set I've been using https://drive.google.com/file/d/1EeDVxfUhbSbkBf3l9tFW5Ml59wRZlTb1/view?usp=sharing

The build process I've been using so far includes:

$colDir feature_extractor --database_path database.db --image_path .
$colDir exhaustive_matcher --database_path database.db

mkdir sparse

$colDir mapper --database_path $workDir/database.db --image_path . --output_path $workDir/sparse
$colDir image_undistorter --image_path . --input_path ./sparse/0/ --output_path myundist

cd myundist

$oMVS/InterfaceCOLMAP -i $workDir/myundist -o proj.mvs
$oMVS/DensifyPointCloud proj.mvs
$oMVS/ReconstructMesh proj_dense.mvs

$colDir points to the COLMAP location and oMVS points to the location of the openMVS build

cdcseacave commented 1 year ago

on windows it works fine, and I do not have a mac now to debug, pls help with the debug ifd u can

D:\Datasets\skydio\Farm_Area_Scan\run4\08-mvs_export\Castle\myundist>ReconstructMesh.exe proj_dense.mvs                                                                        06:44:02 [App     ] Build date: Jan 30 2023, 13:28:21                                                                                                                          06:44:02 [App     ] CPU: 11th Gen Intel(R) Core(TM) i9-11950H @ 2.60GHz (16 cores)                                                                                             06:44:02 [App     ] RAM: 63.73GB Physical Memory 128.00TB Virtual Memory                                                                                                       06:44:02 [App     ] OS: Windows 8 x64                                                                                                                                          06:44:02 [App     ] Disk: 231.34GB (634.76GB) space                                                                                                                            06:44:02 [App     ] SSE & AVX compatible CPU & OS detected                                                                                                                     06:44:02 [App     ] Command line: ReconstructMesh proj_dense.mvs                                                                                                               06:44:03 [App     ] MapSMtoCores for SM 8.6 is undefined; default to use 64 cores/SM                                                                                           06:44:03 [App     ] CUDA device 0 initialized: NVIDIA RTX A2000 Laptop GPU (compute capability 8.6; memory 4.00GB)                                                             06:44:04 [App     ] Scene loaded (1s76ms):                                                                                                                                             11 images (11 calibrated) with a total of 16.79 MPixels (1.53 MPixels/image)                                                                                                   1166159 points, 0 vertices, 0 faces                                                                                                                                    Points inserted 1166159 (100%, 6s124ms)                                                                                                                                        06:44:11 [App     ] Delaunay tetrahedralization completed: 1166159 points -> 489820 vertices, 3138517 (+114) cells, 6277091 (+171) faces (6s504ms)                             Points weighted 489820 (100%, 6s176ms)                                                                                                                                         06:44:19 [App     ] Delaunay tetrahedras weighting completed: 3138631 cells, 6277262 faces (8s159ms)                                                                           06:44:26 [App     ] Delaunay tetrahedras graph-cut completed (300821 flow): 477306 vertices, 954965 faces (6s492ms)                                                            06:44:35 [App     ] Mesh reconstruction completed: 477385 vertices, 954765 faces (30s949ms)                                                                                    06:44:40 [App     ] Cleaned mesh: 477067 vertices, 953460 faces (4s558ms)                                                                                                      06:44:43 [App     ] Cleaned mesh: 477069 vertices, 953464 faces (3s87ms)                                                                                                       06:44:44 [App     ] Cleaned mesh: 477069 vertices, 953464 faces (1s456ms)                                                                                                      06:44:45 [App     ] Scene saved (479ms):                                                                                                                                               11 images (11 calibrated)                                                                                                                                                      0 points, 477069 vertices, 953464 faces                                                                                                                                06:44:45 [App     ] Mesh saved: 477069 vertices, 953464 faces (119ms)                                                                                                          06:44:45 [App     ] MEMORYINFO: {                                                                                                                                              06:44:45 [App     ]     PageFaultCount 1130525                                                                                                                                 06:44:45 [App     ]     PeakWorkingSetSize 1.19GB                                                                                                                              06:44:45 [App     ]     WorkingSetSize 248.09MB                                                                                                                                06:44:45 [App     ]     QuotaPeakPagedPoolUsage 299.26KB                                                                                                                       06:44:45 [App     ]     QuotaPagedPoolUsage 299.15KB                                                                                                                           06:44:45 [App     ]     QuotaPeakNonPagedPoolUsage 24.16KB                                                                                                                     06:44:45 [App     ]     QuotaNonPagedPoolUsage 23.10KB                                                                                                                         06:44:45 [App     ]     PagefileUsage 248.44MB                                                                                                                                 06:44:45 [App     ]     PeakPagefileUsage 1.24GB                                                                                                                               06:44:45 [App     ] } ENDINFO 
bryanjjohnson commented 1 year ago

Here's the latest output after running with debug build

21:54:51 [App     ] Build date: Feb 12 2023, 21:51:44
21:54:51 [App     ] CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz (8 cores)
21:54:51 [App     ] RAM: 16.00GB Physical Memory 16.00GB Virtual Memory
21:54:51 [App     ] OS: Darwin 21.6.0 (x86_64)
21:54:51 [App     ] Disk: 
21:54:51 [App     ] SSE & AVX compatible CPU & OS detected
21:54:51 [App     ] Command line: ReconstructMesh proj_dense.mvs
21:55:06 [App     ] Scene loaded (14s372ms):
    11 images (11 calibrated) with a total of 16.79 MPixels (1.53 MPixels/image)
    1166159 points, 0 vertices, 0 faces
Points inserted 1166159 (100%, 2m44s799ms)           
21:58:02 [App     ] Delaunay tetrahedralization completed: 1166159 points -> 489237 vertices, 3135216 (+114) cells, 6270489 (+171) faces (2m56s537ms)
Points weighted 321034 (65.62%, 30m31s, ETA 15m)...Assertion failed: (facets.empty() && inter.type == intersection_t::VERTEX && inter.v1 == vi), function ReconstructMesh, file SceneReconstruct.cpp, line 1009.
Abort trap: 6
cdcseacave commented 1 year ago

disable that assert, and see where it actually crashes

bryanjjohnson commented 1 year ago

Commented out that assert, rebuilt in debug, and it seemed to execute. Here is the output:

08:40:47 [App     ] Build date: Feb 12 2023, 21:51:44
08:40:47 [App     ] CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz (8 cores)
08:40:47 [App     ] RAM: 16.00GB Physical Memory 16.00GB Virtual Memory
08:40:47 [App     ] OS: Darwin 21.6.0 (x86_64)
08:40:47 [App     ] Disk: 
08:40:47 [App     ] SSE & AVX compatible CPU & OS detected
08:40:47 [App     ] Command line: ReconstructMesh proj_dense.mvs -v 4
08:41:02 [App     ] Scene loaded (14s768ms):
    11 images (11 calibrated) with a total of 16.79 MPixels (1.53 MPixels/image)
    1166159 points, 0 vertices, 0 faces
Points inserted 1166159 (100%, 2m27s284ms)           
08:43:40 [App     ] Delaunay tetrahedralization completed: 1166159 points -> 489237 vertices, 3135216 (+114) cells, 6270489 (+171) faces (2m38s151ms)
Points weighted 489237 (100%, 50m44s75ms)            
09:34:41 [App     ]     weighting completed in 50m44s77ms
09:34:41 [App     ] Delaunay tetrahedras weighting completed: 3135330 cells, 6270660 faces (51m1s63ms)
09:35:07 [App     ] Delaunay tetrahedras graph-cut completed (300502 flow): 476693 vertices, 953765 faces (26s7ms)
09:35:31 [App     ] Fixed 69/80 non-manifold edges/vertices and 309 faces removed: 35 pyramid3 and 51 pyramid4 (23s301ms)
09:35:53 [App     ] Fixed 12/19 non-manifold edges/vertices and 50 faces removed: 2 pyramid3 and 11 pyramid4 (22s703ms)
09:36:15 [App     ] Fixed 1/5 non-manifold edges/vertices and 3 faces removed: 1 pyramid3 and 0 pyramid4 (21s683ms)
09:36:37 [App     ] Fixed 0/0 non-manifold edges/vertices and 0 faces removed: 0 pyramid3 and 0 pyramid4 (21s709ms)
09:36:37 [App     ] Mesh reconstruction completed: 476781 vertices, 953565 faces (55m34s838ms)
09:36:37 [App     ] Mesh saved: 476781 vertices, 953565 faces (193ms)
09:36:37 [App     ] Removed 4 zero-area faces
09:36:38 [App     ] Removed 8 duplicate faces
09:36:38 [App     ] Removed 6 unreferenced vertices
09:36:40 [App     ] Removed 1 non-manifold faces
09:36:40 [App     ] Removed 0 degenerate vertices
09:36:41 [App     ] Removed 58 duplicate vertices
09:36:45 [App     ] Split 56 non-manifold vertices
09:36:48 [App     ] Split 2 non-manifold vertices
09:36:51 [App     ] Split 1 non-manifold vertices
09:36:54 [App     ] Split 0 non-manifold vertices
09:36:56 [App     ] Removed 1006 faces with edges longer than 0.512205
09:36:58 [App     ] Removed 19 connected components out of 26
09:37:03 [App     ] Removed 18 spikes
09:37:05 [App     ] Closed 14 holes and added 70 new faces
09:37:07 [App     ] Smoothed 476455 vertices
09:37:07 [App     ] Cleaned mesh: 476455 vertices, 952222 faces (29s786ms)
09:37:07 [App     ] Removed 0 zero-area faces
09:37:08 [App     ] Removed 0 duplicate faces
09:37:08 [App     ] Removed 0 unreferenced vertices
09:37:10 [App     ] Removed 0 non-manifold faces
09:37:10 [App     ] Removed 0 degenerate vertices
09:37:11 [App     ] Removed 0 duplicate vertices
09:37:14 [App     ] Split 5 non-manifold vertices
09:37:17 [App     ] Split 0 non-manifold vertices
09:37:24 [App     ] Removed 4 spikes
09:37:26 [App     ] Closed 4 holes and added 8 new faces
09:37:26 [App     ] Cleaned mesh: 476456 vertices, 952226 faces (19s137ms)
09:37:26 [App     ] Removed 0 zero-area faces
09:37:27 [App     ] Removed 0 duplicate faces
09:37:27 [App     ] Removed 0 unreferenced vertices
09:37:29 [App     ] Removed 0 non-manifold faces
09:37:29 [App     ] Removed 0 degenerate vertices
09:37:29 [App     ] Removed 0 duplicate vertices
09:37:32 [App     ] Split 0 non-manifold vertices
09:37:34 [App     ] Cleaned mesh: 476456 vertices, 952226 faces (7s814ms)
09:37:39 [App     ] Scene saved (5s634ms):
    11 images (11 calibrated)
    0 points, 476456 vertices, 952226 faces
09:37:40 [App     ] Mesh saved: 476456 vertices, 952226 faces (195ms)

I'm going to rebuild in Release and see how that goes

bryanjjohnson commented 1 year ago

For whatever reason, the Debug build is succeeding now, but the new Release build is still giving me the same Segmentation Fault: 11 message.

cdcseacave commented 1 year ago

strange, must be some optimization done by the compiler in Release that breaks the code, not sure how to fix this

balaclava9 commented 12 months ago

I'm having this same segmentation fault issue as in #972 and #931 for tl:dr; see Update 7. I'm working around the issue.

13:06:11 [App     ] OpenMVS x64 v2.2.0
13:06:11 [App     ] Build date: Sep 27 2023, 13:02:12
13:06:11 [App     ] CPU: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz (8 cores)
13:06:11 [App     ] RAM: 32.00GB Physical Memory 32.00GB Virtual Memory
13:06:11 [App     ] OS: Darwin 22.6.0 (x86_64)
13:06:11 [App     ] Disk: 
13:06:11 [App     ] SSE & AVX compatible CPU & OS detected
13:06:11 [App     ] Command line: ReconstructMesh scene_dense.mvs
13:06:21 [App     ] Scene loaded (10s58ms):
    32 images (32 calibrated) with a total of 133.28 MPixels (4.17 MPixels/image)
    18310688 points, 0 vertices, 0 faces
Points inserted 18310688 (100%, 1m4s348ms)           
zsh: segmentation fault  ../../../workspace/openMVS_build/bin/ReconstructMesh scene_dense.mvs

I rebuilt in DEBUG mode like you guys did.

cmake ../openMVS -DOpenMVS_USE_CUDA=OFF -DVCG_ROOT=../vcglib -DCMAKE_BUILD_TYPE=Debug
cmake --build . -j4 

It got a lot slower as you can see from the time counts on the same data. and then hit an assertion abort.

13:12:00 [App     ] OpenMVS x64 v2.2.0
13:12:00 [App     ] Build date: Sep 27 2023, 13:10:24
13:12:00 [App     ] CPU: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz (8 cores)
13:12:00 [App     ] RAM: 32.00GB Physical Memory 32.00GB Virtual Memory
13:12:00 [App     ] OS: Darwin 22.6.0 (x86_64)
13:12:00 [App     ] Disk: 
13:12:00 [App     ] SSE & AVX compatible CPU & OS detected
13:12:00 [App     ] Command line: ReconstructMesh scene_dense.mvs
13:13:12 [App     ] Scene loaded (1m12s397ms):
    32 images (32 calibrated) with a total of 133.28 MPixels (4.17 MPixels/image)
    18310688 points, 0 vertices, 0 faces
Points inserted 18310688 (100%, 27m32s750ms)           
13:42:52 [App     ] Delaunay tetrahedralization completed: 18310688 points -> 6837286 vertices, 43685323 (+250) cells, 87370771 (+375) faces (29m38s595ms)
Points weighted 3884 (0.06%, 26s, ETA 12h59m)...Assertion failed: (facets.empty() && inter.type == intersection_t::VERTEX && inter.v1 == vi), function ReconstructMesh, file SceneReconstruct.cpp, line 1009.
zsh: abort      ../../../workspace/openMVS_build/bin/ReconstructMesh scene_dense.mvs

I commented out line 1009 and recompiled in debug mode and now it's chugging along with 12h40m (!) remaining.

Update 1: It finished successfully:

14:31:50 [App     ] OpenMVS x64 v2.2.0
14:31:50 [App     ] Build date: Sep 27 2023, 14:30:22
14:31:50 [App     ] CPU: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz (8 cores)
14:31:50 [App     ] RAM: 32.00GB Physical Memory 32.00GB Virtual Memory
14:31:50 [App     ] OS: Darwin 22.6.0 (x86_64)
14:31:50 [App     ] Disk: 
14:31:50 [App     ] SSE & AVX compatible CPU & OS detected
14:31:50 [App     ] Command line: ReconstructMesh scene_dense.mvs
14:33:01 [App     ] Scene loaded (1m10s593ms):
    32 images (32 calibrated) with a total of 133.28 MPixels (4.17 MPixels/image)
    18310688 points, 0 vertices, 0 faces
Points inserted 18310688 (100%, 27m57s666ms)           
15:03:05 [App     ] Delaunay tetrahedralization completed: 18310688 points -> 6837286 vertices, 43685323 (+250) cells, 87370771 (+375) faces (30m3s278ms)
Points weighted 6837286 (100%, 9h41m19s888ms)            
00:46:55 [App     ]     weighting completed in 9h41m19s888ms
00:47:02 [App     ] Delaunay tetrahedras weighting completed: 43685573 cells, 87371146 faces (9h43m56s524ms)
00:51:43 [App     ] Delaunay tetrahedras graph-cut completed (1.44013e+07 flow): 5093177 vertices, 10191015 faces (4m41s414ms)
00:54:31 [App     ] Fixed 1928/1884 non-manifold edges/vertices and 9769 faces removed: 1991 pyramid3 and 949 pyramid4 (2m47s303ms)
00:57:19 [App     ] Fixed 143/456 non-manifold edges/vertices and 336 faces removed: 48 pyramid3 and 48 pyramid4 (2m47s295ms)
01:00:07 [App     ] Fixed 4/64 non-manifold edges/vertices and 22 faces removed: 2 pyramid3 and 4 pyramid4 (2m48s346ms)
01:02:57 [App     ] Fixed 0/4 non-manifold edges/vertices and 7 faces removed: 1 pyramid3 and 1 pyramid4 (2m49s850ms)
01:02:57 [App     ] Mesh reconstruction completed: 5094629 vertices, 10184927 faces (10h29m55s728ms)
01:02:58 [App     ] Mesh saved: 5094629 vertices, 10184927 faces (1s275ms)
01:03:01 [App     ] Removed 18 zero-area faces
...
01:10:11 [App     ] Removed 0 duplicate vertices
01:10:32 [App     ] Split 0 non-manifold vertices
01:10:44 [App     ] Cleaned mesh: 5088362 vertices, 10173695 faces (1m419ms)
01:10:58 [App     ] Scene saved (13s985ms):
    32 images (32 calibrated)
    0 points, 5088362 vertices, 10173695 faces
01:11:00 [App     ] Mesh saved: 5088362 vertices, 10173695 faces (1s257ms)

But it was insanely slow!

strange, must be some optimization done by the compiler in Release that breaks the code, not sure how to fix this

maybe there's another compiler I can use somehow? Or a compile flag that makes it more like a gcc?

Update 2: I tried using -D CMAKE_C_COMPILER=gcc-13 -D CMAKE_CXX_COMPILER=c++-13

and I get a source code error:

../openMVS/libs/MVS/SceneDensify.cpp:2212:83: internal compiler error: in reference_binding, at cp/call.cc:2020
 2212 |                         const PointCloud::Point::EVec D((PointCloud::Point::EVec&)X-cone.ray.m_pOrig);
      |                                                                                   ^

I changed X-cone.ray.m_pOrig to cone.ray.m_pOrig. There was nothing called X-cone declared as far as I could see, but a Cone cone was declared. After that change it compiled, but then the compiler choked with a bunch of other errors that were too much for me. IIRC ld threw the error.

Update 3: Built openMVS with vcpkg instead on Mac, like mentioned in build instructions. it's difficult. homebrew is much better.

I still needed used Homebrew stuff to get vcpkg to build all the dependencies.

brew install autoconf automake libtool pkg-config autoconf-archive

I had to integrate manually:

cmake ../openMVS -DCMAKE_BUILD_TYPE=Release -DVCG_ROOT="../vcglib" -DOpenMVS_USE_CUDA=OFF --toolchain "../vcpkg/scripts/buildsystems/vcpkg.cmake"

and add cmake and vcpkg to my PATH:

export PATH=/Users/me/photogrammetry/vcpkg/downloads/tools/cmake-3.27.1-osx/cmake-3.27.1-macos-universal/CMake.app/Contents/bin:$PATH
export PATH=/Users/me/photogrammetry/vcpkg/:$PATH 

Still segmentation fault for ReconstructMesh like the Homebrew built version above.

Update 4:

My VCPKG built Debug version managed to do it in a very slow 25 hours.

21:18:16 [App     ] OpenMVS x64 v2.2.0
21:18:16 [App     ] Build date: Sep 28 2023, 17:52:43
21:18:16 [App     ] CPU: Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz (8 cores)
21:18:16 [App     ] RAM: 16.00GB Physical Memory 16.00GB Virtual Memory
21:18:16 [App     ] OS: Darwin 20.6.0 (x86_64)
21:18:16 [App     ] Disk: 
21:18:16 [App     ] SSE & AVX compatible CPU & OS detected
21:18:16 [App     ] Command line: TextureMesh scene_dense_mesh.mvs
21:19:01 [App     ] Scene loaded (44s500ms):
    32 images (32 calibrated) with a total of 723.05 MPixels (22.60 MPixels/image)
    0 points, 5088362 vertices, 10173695 faces
[ INFO:0@144.383] global registry_parallel.impl.hpp:96 ParallelBackendRegistry core(parallel): Enabled backends(3, sorted by priority): ONETBB(1000); TBB(990); OPENMP(980)
Initialized views 32 (100%, 25m48s233ms)          
00:19:03 [App     ]      0. e: 1.71799e+10  d: 2.55805e+09  t: 9m41s649ms
00:27:12 [App     ]      1. e: 1.46218e+10  d: 1.41378e+09  t: 8m9s9ms
...
13:41:20 [App     ]     99. e: 3.06534e+09  d: 110592   t: 8m8s94ms
13:49:39 [App     ]     100. e: 3.06523e+09 d: 481792   t: 8m18s442ms
13:49:39 [App     ] Inference aborted (energy increased): 101 iterations, 3.06475e+09 energy (13h40m20s92ms)
13:52:21 [App     ] Assigning the best view to each face completed: 10173695 faces (16h33m20s312ms)
14:18:13 [App     ]     global seam leveling completed (25m31s431ms)
17:22:42 [App     ]     local seam leveling completed (3h4m29s147ms)
22:08:10 [App     ]     packing texture completed: 127743 patches, 16384 texture-size (4h42m31s674ms)
22:09:00 [App     ] Generating texture atlas and image completed: 127743 patches, 16384 image size (8h16m39s86ms)
22:09:02 [App     ] Mesh texturing completed: 5088362 vertices, 10173695 faces (1d50m1s8ms)
22:21:22 [App     ] Scene saved (12m19s998ms):
    32 images (32 calibrated)
    0 points, 5088362 vertices, 10173695 faces
22:22:57 [App     ] Mesh saved: 5088362 vertices, 10173695 faces (1m35s407ms)

My homebrew built Debug version hit an assertion at line 1233 of SceneTexture.cpp commenting it out and trying it again.

12:40:24 [App     ] OpenMVS x64 v2.2.0
12:40:24 [App     ] Build date: Sep 27 2023, 14:30:22
12:40:24 [App     ] CPU: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz (8 cores)
12:40:24 [App     ] RAM: 32.00GB Physical Memory 32.00GB Virtual Memory
12:40:24 [App     ] OS: Darwin 22.6.0 (x86_64)
12:40:24 [App     ] Disk: 
12:40:24 [App     ] SSE & AVX compatible CPU & OS detected
12:40:24 [App     ] Command line: TextureMesh scene_dense_mesh.mvs
12:40:37 [App     ] Scene loaded (13s720ms):
    32 images (32 calibrated) with a total of 723.05 MPixels (22.60 MPixels/image)
    0 points, 5088362 vertices, 10173695 faces
Initialized views 32 (100%, 15m52s103ms)          
Assertion failed: (components.empty() || components[f] == components[fAdj]), function FaceViewSelection, file SceneTexture.cpp, line 1233.
zsh: abort      ../../../workspace/openMVS_build/bin/TextureMesh scene_dense_mesh.mvs

Update 5 My homebrew built Debug version completes after commenting out assertion after a slightly better 15 hours.

10:52:42 [App     ] OpenMVS x64 v2.2.0
10:52:42 [App     ] Build date: Oct  2 2023, 10:50:44
10:52:42 [App     ] CPU: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz (8 cores)
10:52:42 [App     ] RAM: 32.00GB Physical Memory 32.00GB Virtual Memory
10:52:42 [App     ] OS: Darwin 22.6.0 (x86_64)
10:52:42 [App     ] Disk: 
10:52:42 [App     ] SSE & AVX compatible CPU & OS detected
10:52:42 [App     ] Command line: TextureMesh scene_dense_mesh.mvs
10:52:55 [App     ] Scene loaded (13s470ms):
    32 images (32 calibrated) with a total of 723.05 MPixels (22.60 MPixels/image)
    0 points, 5088362 vertices, 10173695 faces
Initialized views 32 (100%, 15m7s839ms)          
12:34:28 [App     ]      0. e: 1.71799e+10  d: 2.55805e+09  t: 4m53s665ms
12:39:24 [App     ]      1. e: 1.46218e+10  d: 1.41379e+09  t: 4m56s256ms
...
20:47:01 [App     ]     99. e: 3.06523e+09  d: 28672    t: 4m56s464ms
20:51:57 [App     ]     100. e: 3.0652e+09  d: 532736   t: 4m56s573ms
20:51:57 [App     ] Inference aborted (energy increased): 101 iterations, 3.06467e+09 energy (8h22m24s112ms)
20:52:46 [App     ] Assigning the best view to each face completed: 10173695 faces (9h59m50s48ms)
21:10:30 [App     ]     global seam leveling completed (17m31s951ms)
23:00:55 [App     ]     local seam leveling completed (1h50m24s899ms)
02:04:36 [App     ]     packing texture completed: 127742 patches, 16384 texture-size (3h2m36ms)
02:04:37 [App     ] Generating texture atlas and image completed: 127742 patches, 16384 image size (5h11m51s844ms)
02:04:38 [App     ] Mesh texturing completed: 5088362 vertices, 10173695 faces (15h11m42s368ms)
02:08:26 [App     ] Scene saved (3m48s472ms):
    32 images (32 calibrated)
    0 points, 5088362 vertices, 10173695 faces
02:08:56 [App     ] Mesh saved: 5088362 vertices, 10173695 faces (29s439ms)

Update 6:

Trying a new dataset which confirms the Debug slowdown.

The Release compiled version is fast:

Scene loaded (3s253ms):
Points inserted 5757188 (100%, 19s689ms)           
zsh: segmentation fault  ../../openmvs-space/openMVS_build/bin/ReconstructMesh 

The Debug compiled version runs, but is much slower:

Scene loaded (23s254ms):
Points inserted 5757188 (100%, 8m40s751ms)           

Update 7:

I rebuilt my vcpkg build with -DCMAKE_BUILD_TYPE=Release and then edited CMakeCache.txt and replaced the optimization flag -O3 with -O1 like so::

//Flags used by the CXX compiler during RELEASE builds.
CMAKE_CXX_FLAGS_RELEASE:STRING=-O1 -DNDEBUG
//Flags used by the C compiler during RELEASE builds.
CMAKE_C_FLAGS_RELEASE:STRING=-O1 -DNDEBUG

On the original data set I went from the debug build Points inserted 18310688 (100%, 27m32s750ms) to Points inserted 18310688 (100%, 11m3s216ms)

On my homebrew build changing the optimization flag to -O1 still hits a segmentation fault, now it's working but still very slowly with the settings like this:

//Flags used by the CXX compiler during RELEASE builds.
CMAKE_CXX_FLAGS_RELEASE:STRING=-O0 -DNDEBUG
//Flags used by the C compiler during RELEASE builds.
CMAKE_C_FLAGS_RELEASE:STRING=-O2 -DNDEBUG

also @cdcseacave mentioned somewhere in a windows bug thread that he hadn't tried VisualStudio 2017 and recommended upgrading. So I thought I might try to update the compiler to C++20. I couldn't just set CMAKE_CXX_STANDARD on the command line. I went to openMVS/build/Utils.cmake and at line 403 you can see where they set that CMAKE variable. I changed c++11 to c++14, c++14 to c++17, and c++17 to c++20. Now cmake finds C++ 20 while it sets up the build. Not sure if this made a difference. But I have been running InterfaceCOLMAP, DensifyPointCloud, RefineMesh, and TextureMesh with the normal release build; only ReconstructMesh needs this reduced optimization build.

it's just like @cdcseacave says. it appears to be a funny optimization problem. This is all way beyond my level of understanding.

Update 8:

I've done three more meshes with these builds. ReconstructMesh for something the order of 30 22Mpix images, it's 5 hours or so. Not so different from my Regard3D times or my Meshroom on Ubuntu times, IIRC, but the best quality I've gotten so far, especially with not so great input images.

Update 9:

I rebuilt with OpenMP. Now it's much faster because ReconstructMesh and RefineMesh are now using every CPU core. This is on my Intel Coffe Lake hackintosh with only the integrated GPU.

brew install libomp to install OpenMP and do the two export commands homebrew suggests. Then since it is keg-only you have to link it so the compiler can find it. brew link libomp --force

This is working on my homebrew build. My vcpkg build still couldn't find libomp and I'm not yet sure why. So now my homebrew build is much faster.

MichaelRZ commented 7 months ago

I found the root cause for Mac, without switching over to gcc or out of vcpkg, (for vcpkg, you can edit the source in the buildtree folder, do vcpkg remove openmvs, then install openmvs with the —editable flag) this line in plane.inl under the tfrustum::Set function:

M.template topLeftCorner<3,4>() = m;

which is this in the vcpkg version under the ifdef gnu section:

M.topLeftCorner(3,4) = m;

It apparently fails when assigning an m value to M directly on the second and fourth columns. So, topLeftCorner and block() won’t work, it only worked when I wrote it like this, confirming it’s an optimization / memory alignment / SSE issue or similar with Eigen or appleclang (im using 3.4 since I couldn’t figure out how to force 3.2):

std::string stopGap = “1”; for(int z = 0; z<12;z++){ double temp = m(z/4,z%4); M(z/4,z%4) = temp; stopGap += “0”; }

Obviously this isn’t a production ready fix, but it lets my MacBook run the release mode reconstruct method in two minutes compared to the hour+ debug mode commenting out the facet assert line. I imagine AppleClang is unrolling the loop and putting the assigns together, even with the -O0 flag, since this still fails when stopGap is a double. Thanks Apple…