alicevision / AliceVision

Photogrammetric Computer Vision Framework
http://alicevision.org
Other
2.97k stars 824 forks source link

Segfault in aliceVision_featureMatching when built with OpenCV #1460

Closed sjuxax closed 1 year ago

sjuxax commented 1 year ago

When I build with -DALICEVISION_USE_OPENCV=ON, I reliably get this backtrace from aliceVision_featureMatching. This run was done with OMP_NUM_THREADS=1 for simplicity.

#0  0x00007ffff7db19b8 in std::_Sp_counted_ptr<aliceVision::camera::DistortionRadialK3*, (__gnu_cxx::_Lock_policy)2>::_M_dispose() (this=<optimized out>) at /usr/lib/gcc/x86_64-pc-linux-gnu/12.3.0/include/c++/bits/shared_ptr_base.h:428
#1  0x00007ffff7f225cc in aliceVision::camera::IntrinsicsScaleOffsetDisto::removeDistortion(Eigen::Matrix<double, 2, 1, 0, 2, 1> const&) const (p=..., this=0x5555574961d0)
    at /usr/src/debug/alice-vision-git/alice-vision-git/src/aliceVision/camera/IntrinsicsScaleOffsetDisto.hpp:87
#2  aliceVision::camera::IntrinsicsScaleOffsetDisto::get_ud_pixel(Eigen::Matrix<double, 2, 1, 0, 2, 1> const&) const (this=0x5555574961d0, p=<optimized out>)
    at /usr/src/debug/alice-vision-git/alice-vision-git/src/aliceVision/camera/IntrinsicsScaleOffsetDisto.cpp:47
#3  0x000055555558ae1f in aliceVision::matchingImageCollection::fillMatricesWithUndistortFeaturesMatches<Eigen::Block<Eigen::Matrix<double, -1, -1, 0, -1, -1>, -1, -1, false>, std::unique_ptr<aliceVision::feature::Regions, std::default_delete<aliceVision::feature::Regions> > >(std::vector<aliceVision::matching::IndMatch, std::allocator<aliceVision::matching::IndMatch> > const&, aliceVision::camera::IntrinsicBase const*, std::unique_ptr<aliceVision::feature::Regions, std::default_delete<aliceVision::feature::Regions> > const&, aliceVision::camera::IntrinsicBase const*, std::unique_ptr<aliceVision::feature::Regions, std::default_delete<aliceVision::feature::Regions> > const&, Eigen::Block<Eigen::Matrix<double, -1, -1, 0, -1, -1>, -1, -1, false>&, Eigen::Block<Eigen::Matrix<double, -1, -1, 0, -1, -1>, -1, -1, false>&)
    (putativeMatches=std::vector of length 195, capacity 228 = {...}, cam_I=cam_I@entry=0x5555574961d0, feature_I=std::unique_ptr<aliceVision::feature::Regions> = {...}, cam_J=cam_J@entry=0x5555574961d0, feature_J=std::unique_ptr<aliceVision::feature::Regions> = {...}, x_I=..., x_J=...) at /usr/src/debug/alice-vision-git/alice-vision-git/src/aliceVision/matchingImageCollection/geometricFilterUtils.hpp:58
#4  0x000055555558b3df in aliceVision::matchingImageCollection::fillMatricesWithUndistortFeaturesMatches<Eigen::Matrix<double, -1, -1, 0, -1, -1>, aliceVision::feature::MapRegionsPerDesc>(aliceVision::matching::MatchesPerDescType const&, aliceVision::camera::IntrinsicBase const*, aliceVision::camera::IntrinsicBase const*, aliceVision::feature::MapRegionsPerDesc const&, aliceVision::feature::MapRegionsPerDesc const&, std::vector<aliceVision::feature::EImageDescriberType, std::allocator<aliceVision::feature::EImageDescriberType> > const&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&)
    (putativeMatchesPerType=..., cam_I=cam_I@entry=0x5555574961d0, cam_J=cam_J@entry=0x5555574961d0, features_I=..., features_J=..., descTypes=std::vector of length 1, capacity 1 = {...}, x_I=<optimized out>, x_J=<optimized out>)
    at /usr/src/debug/alice-vision-git/alice-vision-git/src/aliceVision/matchingImageCollection/geometricFilterUtils.hpp:119
#5  0x000055555559c4b4 in aliceVision::matchingImageCollection::GeometricFilterMatrix_F_AC::geometricEstimation<aliceVision::feature::MapRegionsPerDesc>(aliceVision::feature::MapRegionsPerDesc const&, aliceVision::feature::MapRegionsPerDesc const&, aliceVision::camera::IntrinsicBase const*, aliceVision::camera::IntrinsicBase const*, std::pair<unsigned long, unsigned long> const&, std::pair<unsigned long, unsigned long> const&, aliceVision::matching::MatchesPerDescType const&, std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>&, aliceVision::matching::MatchesPerDescType&)
    (this=this@entry=0x7fffffff93c0, regionI=..., regionJ=..., camI=0x5555574961d0, camJ=0x5555574961d0, imageSizeI={...}, imageSizeJ={...}, putativeMatchesPerType=..., randomNumberGenerator=..., out_geometricInliersPerType=...)
    at /usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:968
#6  0x000055555559f7ff in aliceVision::matchingImageCollection::GeometricFilterMatrix_F_AC::geometricEstimation<aliceVision::feature::RegionsPerView>(aliceVision::sfmData::SfMData const*, aliceVision::feature::RegionsPerView const&, std::pair<unsigned int, unsigned int> const&, aliceVision::matching::MatchesPerDescType const&, std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>&, aliceVision::matching::MatchesPerDescType&) (out_geometricInliersPerType=..., randomNumberGenerator=..., putativeMatchesPerType=..., pairIndex={...}, regionsPerView=<optimized out>, sfmData=0x7fffffffc830, this=0x7fffffff93c0)
    at /usr/src/debug/alice-vision-git/alice-vision-git/src/aliceVision/matchingImageCollection/GeometricFilterMatrix_F_AC.hpp:74
#7  _ZN11aliceVision23matchingImageCollection21robustModelEstimationINS0_26GeometricFilterMatrix_F_ACEEEvRSt3mapISt4pairIjjENS_8matching18MatchesPerDescTypeESt4lessIS5_ESaIS4_IKS5_S7_EEEPKNS_7sfmData7SfMDataERKNS_7feature14RegionsPerViewERKT_RKSD_RSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEbd._omp_fn.0(void) () at /usr/src/debug/alice-vision-git/alice-vision-git/src/aliceVision/matchingImageCollection/GeometricFilter.hpp:72
#8  0x00007ffff73e1e26 in GOMP_parallel
    (fn=fn@entry=0x55555559f260 <_ZN11aliceVision23matchingImageCollection21robustModelEstimationINS0_26GeometricFilterMatrix_F_ACEEEvRSt3mapISt4pairIjjENS_8matching18MatchesPerDescTypeESt4lessIS5_ESaIS4_IKS5_S7_EEEPKNS_7sfmData7SfMDataERKNS_7feature14RegionsPerViewERKT_RKSD_RSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEbd._omp_fn.0(void)>, data=data@entry=0x7fffffff94f0, num_threads=0x1, 
    num_threads@entry=0x0, flags=flags@entry=0x0) at /usr/src/debug/gcc/gcc/libgomp/parallel.c:178
#9  0x000055555557c13d in aliceVision::matchingImageCollection::robustModelEstimation<aliceVision::matchingImageCollection::GeometricFilterMatrix_F_AC>(std::map<std::pair<unsigned int, unsigned int>, aliceVision::matching::MatchesPerDescType, std::less<std::pair<unsigned int, unsigned int> >, std::allocator<std::pair<std::pair<unsigned int, unsigned int> const, aliceVision::matching::MatchesPerDescType> > >&, aliceVision::sfmData::SfMData const*, aliceVision::feature::RegionsPerView const&, aliceVision::matchingImageCollection::GeometricFilterMatrix_F_AC const&, std::map<std::pair<unsigned int, unsigned int>, aliceVision::matching::MatchesPerDescType, std::less<std::pair<unsigned int, unsigned int> >, std::allocator<std::pair<std::pair<unsigned int, unsigned int> const, aliceVision::matching::MatchesPerDescType> > > const&, std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>&, bool, double)
    (out_geometricMatches=std::map with 0 elements, sfmData=sfmData@entry=0x7fffffffc830, regionsPerView=..., functor=..., putativeMatches=std::map with 153 elements = {...}, randomNumberGenerator=..., guidedMatching=0x1, distanceRatio=distanceRatio@entry=0.59999999999999998) at /usr/lib/gcc/x86_64-pc-linux-gnu/12.3.0/include/c++/bits/new_allocator.h:90
#10 0x0000555555574ac4 in aliceVision_main(int, char**) (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/alice-vision-git/alice-vision-git/src/software/pipeline/main_featureMatching.cpp:456
#11 0x000055555556dcf9 in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/alice-vision-git/alice-vision-git/src/aliceVision/system/main.hpp:37

Works fine when not built with OpenCV. It doesn't look like the crash occurs in OpenCV, but I rebuilt without Arch's default -Wp,-D_GLIBCXX_ASSERTIONS flag just in case, and doesn't seem to make any difference.

Here's my opencv_version just in case something's relevant in there:


General configuration for OpenCV 4.7.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /tmp/zr0/makepkg/opencv/src/opencv_contrib-4.7.0/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2023-06-08T15:07:30Z
    Host:                        Linux 6.3.2-arch1-1-kvm-local x86_64
    CMake:                       3.26.4
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX AVX2
      requested:                 DETECT
      required:                  SSE2
      disabled:                  SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (0 files):          + 
      SSE4_2 (0 files):          + 
      FP16 (0 files):            + 
      AVX (0 files):             + 
      AVX2 (0 files):            + 
      AVX512_SKX (5 files):      + AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /usr/bin/g++-12  (ver 12.3.0)
    C++ flags (Release):         -O2 -pipe -mtune=native -march=native -fstack-protector -fno-plt -fcf-protection -fno-sanitize=all -fstack-clash-protection -fPIC -Wno-error=deprecated-declarations -fdiagnostics-color -Wp,-D_FORTIFY_SOURCE=2  -fuse-linker-plugin -flto=auto -fuse-ld=mold -fno-fat-lto-objects -ggdb3 -gdwarf -fno-omit-frame-pointer -g3 -ggdb3 -gdwarf -gz -ffile-prefix-map=/tmp/zr0/makepkg/opencv/src=/usr/src/debug/opencv   -fno-lto   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -O2 -pipe -mtune=native -march=native -fstack-protector -fno-plt -fcf-protection -fno-sanitize=all -fstack-clash-protection -fPIC -Wno-error=deprecated-declarations -fdiagnostics-color -Wp,-D_FORTIFY_SOURCE=2  -fuse-linker-plugin -flto=auto -fuse-ld=mold -fno-fat-lto-objects -ggdb3 -gdwarf -fno-omit-frame-pointer -g3 -ggdb3 -gdwarf -gz -ffile-prefix-map=/tmp/zr0/makepkg/opencv/src=/usr/src/debug/opencv   -fno-lto   -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/gcc-12
    C flags (Release):           -O2 -pipe -mtune=native -march=native -fstack-protector -fno-plt -fcf-protection -fno-sanitize=all -fstack-clash-protection -fPIC -Wno-error=deprecated-declarations -fdiagnostics-color -Wp,-D_FORTIFY_SOURCE=2 -fuse-linker-plugin -flto=auto -fuse-ld=mold -fno-fat-lto-objects -ggdb3 -gdwarf -fno-omit-frame-pointer -g3 -ggdb3 -gdwarf -gz -ffile-prefix-map=/tmp/zr0/makepkg/opencv/src=/usr/src/debug/opencv   -fno-lto   -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -O2 -pipe -mtune=native -march=native -fstack-protector -fno-plt -fcf-protection -fno-sanitize=all -fstack-clash-protection -fPIC -Wno-error=deprecated-declarations -fdiagnostics-color -Wp,-D_FORTIFY_SOURCE=2 -fuse-linker-plugin -flto=auto -fuse-ld=mold -fno-fat-lto-objects -ggdb3 -gdwarf -fno-omit-frame-pointer -g3 -ggdb3 -gdwarf -gz -ffile-prefix-map=/tmp/zr0/makepkg/opencv/src=/usr/src/debug/opencv   -fno-lto   -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -g  -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now   -fno-lto  -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
    Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now   -fno-lto  -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
    ccache:                      YES
    Precompiled headers:         NO
    Extra dependencies:          m pthread cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/opt/cuda/lib64 -L/lib64
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform java line_descriptor mcc ml objdetect optflow ovis phase_unwrapping photo plot python2 python3 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab viz wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 julia matlab ts
    Applications:                examples apps
    Documentation:               NO
    Non-free algorithms:         YES

  GUI:                           QT6
    QT:                          YES (ver 6.5.1 )
      QT OpenGL support:         YES (Qt6::OpenGL )
    GTK+:                        YES (ver 3.24.38)
      GThread :                  YES (ver 2.76.3)
      GtkGlExt:                  YES (ver 1.2.0)
    OpenGL support:              YES (/lib64/libGL.so /lib64/libGLU.so)
    VTK support:                 YES (ver 9.2.6)

  Media I/O: 
    ZLib:                        /lib64/lib/libz.so (ver 1.2.13)
    JPEG:                        /lib64/libjpeg.so (ver 80)
    WEBP:                        /lib64/libwebp.so (ver encoder: 0x020f)
    PNG:                         /lib64/libpng.so (ver 1.6.39)
    TIFF:                        /lib64/libtiff.so (ver 42 / 4.5.0)
    JPEG 2000:                   OpenJPEG (ver 2.5.0)
    OpenEXR:                     OpenEXR::OpenEXR (ver 3.1.8)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      YES (2.2.7)
    FFMPEG:                      YES
      avcodec:                   YES (60.16.100)
      avformat:                  YES (60.5.100)
      avutil:                    YES (58.12.100)
      swscale:                   YES (7.3.100)
      avresample:                NO
    GStreamer:                   YES (1.22.3)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            TBB (ver 2021.8 interface 12080)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   /tmp/zr0/makepkg/opencv/src/build-cuda/3rdparty/ippicv/ippicv_lnx/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                /tmp/zr0/makepkg/opencv/src/build-cuda/3rdparty/ippicv/ippicv_lnx/iw
    VA:                          YES
    Lapack:                      YES (/usr/lib/liblapack.so /usr/lib/libblas.so /usr/lib/libcblas.so)
    Eigen:                       YES (ver 3.4.0)
    Custom HAL:                  NO
    Protobuf:                    /lib64/libprotobuf.so (3.21.12)

  NVIDIA CUDA:                   YES (ver 12.1, CUFFT CUBLAS)
    NVIDIA GPU arch:             52 53 60 61 62 70 72 75 80 86 87 89 90 90
    NVIDIA PTX archs:            90

  cuDNN:                         YES (ver 8.8.0)

  Vulkan:                        YES
    Include path:                /tmp/zr0/makepkg/opencv/src/opencv-4.7.0/3rdparty/include
    Link libraries:              Dynamic load

  OpenCL:                        YES (INTELVA)
    Include path:                /tmp/zr0/makepkg/opencv/src/opencv-4.7.0/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  ONNX:                          NO

  Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.18)
    Libraries:                   /lib64/libpython2.7.so (ver 2.7.18)
    numpy:                       /usr/lib/python2.7/site-packages/numpy/core/include (ver 1.16.6)
    install path:                lib/python2.7/site-packages

  Python 3:
    Interpreter:                 /home/jeff/.local/bin/python3 (ver 3.11.3)
    Libraries:                   /lib64/libpython3.11.so (ver 3.11.3)
    numpy:                       /home/jeff/.local/lib/python3.11/site-packages/numpy/core/include (ver 1.24.3)
    install path:                lib/python3.11/site-packages

  Python (for build):            /usr/bin/python2.7

  Java:                          
    ant:                         /bin/ant (ver 1.10.12)
    JNI:                         /usr/lib/jvm/default/include /usr/lib/jvm/default/include/linux /usr/lib/jvm/default/include
    Java wrappers:               YES
    Java tests:                  NO

  Install to:                    /usr
-----------------------------------------------------------------
sjuxax commented 1 year ago

This was coming from system-installed CCTag not having the corresponding CCTAG_EIGEN_MEMORY_ALIGNMENT=ON flag, so its CMake script was automatically adding -DEIGEN_MAX_ALIGN_BYTES=0 -DEIGEN_MAX_STATIC_ALIGN_BYTES=0 contrary to the AliceVision flag. Rebuilt with CCTag with an explicit -DCCTAG_EIGEN_MEMORY_ALIGNMENT=ON, rebuilt AliceVision against new CCTag, no longer get crashes. Not sure why this wasn't getting set by default on CCTag build, but situation is resolved. Thanks.