opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
75.95k stars 55.61k forks source link

python cv2.norm() on any images hangs - deadlock? #25521

Closed mcdamo closed 2 weeks ago

mcdamo commented 2 weeks ago

System Information

OpenCV python version: 4.5.4+dfsg-9ubuntu4 (system) / 4.9.0.80 (pip) Operating System / Platform: Ubuntu 22.04.4 Python version: 3.10.12

Detailed description

Running cv2.norm(img1, img2) on two images hangs indefinitely.

Using gdb to inspect process shows:

Thread 1 "python3" received signal SIGINT, Interrupt.
__futex_abstimed_wait_common64 (private=<optimised out>, cancel=true, abstime=0x7fffffffbe70, op=393, expected=0, futex_word=0x555557ad2528) at ./nptl/futex-internal.c:57
57      ./nptl/futex-internal.c: No such file or directory.

Steps to reproduce

import cv2

img = cv2.imread('test.jpg')
n = cv2.norm(img, img)

I don't think the choice of image has an impact, but here's an example anyway.

Issue submission checklist

LaurentBerger commented 2 weeks ago

No problem

Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
>>> img =cv.imread(cv.samples.findFile("baboon.jpg"))
[ WARN:0@31.380] global samples.cpp:61 cv::samples::findFile cv::samples::findFile('baboon.jpg') => 'C:\lib\opencv\samples/data\baboon.jpg'
>>> cv.norm(img,img)
0.0
>>>

Did you install opencv and opencv_contrib? If yes uninstall everything and install only opencv-contrib-python

Did you checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution? NO

mcdamo commented 2 weeks ago

Removed system packages and installed opencv-contrib-python in a venv. Same issue.

LaurentBerger commented 2 weeks ago

post print(cv2.getBuildInformation())

mcdamo commented 2 weeks ago
>>> print(cv2.getBuildInformation())                                                                                                                             

General configuration for OpenCV 4.9.0 =====================================    
  Version control:               4.9.0-dirty                                                                                                                     

  Extra modules:                                                                                                                                                 
    Location (extra):            /io/opencv_contrib/modules
    Version control (extra):     4.9.0                                                                                                                           

  Platform:                                                                                                                                                      
    Timestamp:                   2023-12-31T11:19:02Z                           
    Host:                        Linux 5.15.0-1053-azure x86_64
    CMake:                       3.28.1                                         
    CMake generator:             Unix Makefiles
    CMake build tool:            /bin/gmake
    Configuration:               Release          

  CPU/HW features:                 
    Baseline:                    SSE SSE2 SSE3
      requested:                 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 (16 files):         + SSSE3 SSE4_1                  
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (8 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (36 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2                                                                                 
      AVX512_SKX (5 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX                                               

  C/C++:                            
    Built as dynamic libs?:      NO 
    C++ standard:                11                                             
    C++ Compiler:                /opt/rh/devtoolset-10/root/usr/bin/c++  (ver 10.2.1)                                                                            
    C++ flags (Release):         -Wl,-strip-all   -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 -Wim
plicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse
2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -Wl,-strip-all   -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 -Wim
plicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse
2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG                                                                                
    C Compiler:                  /opt/rh/devtoolset-10/root/usr/bin/cc
    C flags (Release):           -Wl,-strip-all   -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declaratio
ns -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overfl
ow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEB
UG  -DNDEBUG                            
    C flags (Debug):             -Wl,-strip-all   -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declaratio
ns -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overfl
ow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -D
DEBUG -D_DEBUG                                                                  
    Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -L/ffmpeg_build/lib  -Wl,--gc-sections -Wl,--as-needed -Wl,--no-und
efined                                                                          
    Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -L/ffmpeg_build/lib  -Wl,--gc-sections -Wl,--as-needed -Wl,--no-und
efined                              
    ccache:                      YES                                            
    Precompiled headers:         NO  
    Extra dependencies:          /lib64/libopenblas.so Qt5::Test Qt5::Concurrent /usr/local/lib/libpng.so /lib64/libz.so Qt5::Core Qt5::Gui Qt5::Widgets Iconv::I
conv dl m pthread rt                                                            
    3rdparty dependencies:       libprotobuf ade ittnotify libjpeg-turbo libwebp libtiff libopenjp2 IlmImf ippiw ippicv                                          

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

  GUI:                           QT5                                            
    QT:                          YES (ver 5.15.0 )
      QT OpenGL support:         NO     
    GTK+:                        NO
    VTK support:                 NO                                             

  Media I/O:                                                                    
    ZLib:                        /lib64/libz.so (ver 1.2.7)                 
    JPEG:                        libjpeg-turbo (ver 2.1.3-62)    
    WEBP:                        build (ver encoder: 0x020f) 
    PNG:                         /usr/local/lib/libpng.so (ver 1.6.40)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.5.0)                                                                                                               
    OpenEXR:                     build (ver 2.3.0)                                                                                                               
    HDR:                         YES                                            
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES                                            

  Video I/O:                                                                                                                                                     
    DC1394:                      NO                                                                                                                              
    FFMPEG:                      YES                                                                                                                             
      avcodec:                   YES (59.37.100)                               
      avformat:                  YES (59.27.100)                                                                                                                 
      avutil:                    YES (57.28.100)                                                                                                                 
      swscale:                   YES (6.7.100)                                                                                                                   
      avresample:                NO                                                                                                                              
    GStreamer:                   NO                                             
    v4l/v4l2:                    YES (linux/videodev2.h)                                                                                                         

  Parallel framework:            pthreads                                                                                                                        

  Trace:                         YES (with Intel ITT)                                                                                                            

  Other third-party libraries:                                                                                                                                   
    Intel IPP:                   2021.10.0 [2021.10.0]                          
           at:                   /io/_skbuild/linux-x86_64-3.7/cmake-build/3rdparty/ippicv/ippicv_lnx/icv                                                        
    Intel IPP IW:                sources (2021.10.0)                            
              at:                /io/_skbuild/linux-x86_64-3.7/cmake-build/3rdparty/ippicv/ippicv_lnx/iw                                                         
    VA:                          NO 
    Lapack:                      YES (/lib64/libopenblas.so)                    
    Eigen:                       NO  
    Custom HAL:                  NO                                                                                                                              
    Protobuf:                    build (3.19.1)                                 
    Flatbuffers:                 builtin/3rdparty (23.5.9)                                                                                                       

  OpenCL:                        YES (no extra features)                        
    Include path:                /io/opencv/3rdparty/include/opencl/1.2                                                                                          
    Link libraries:              Dynamic load                                                                                                                    

  Python 3:                                                                     
    Interpreter:                 /opt/python/cp37-cp37m/bin/python3.7 (ver 3.7.17)                                                                               
    Libraries:                   libpython3.7m.a (ver 3.7.17)                                                                                                    
    numpy:                       /home/ci/.local/lib/python3.7/site-packages/numpy/core/include (ver 1.17.0)                                                     
    install path:                python/cv2/python-3                            

  Python (for build):            /opt/python/cp37-cp37m/bin/python3.7           

  Java:                                                                         
    ant:                         NO                                             
    Java:                        NO     
    JNI:                         NO
    Java wrappers:               NO                                             
    Java tests:                  NO     

  Install to:                    /io/_skbuild/linux-x86_64-3.7/cmake-install
-----------------------------------------------------------------
LaurentBerger commented 2 weeks ago

May be you should clean your post :

Python version: 3.10.12

and

/opt/python/cp37-cp37m/bin/python3.7 (ver 3.7.17)

@asmorkalov What is

Version control: 4.9.0-dirty

mcdamo commented 2 weeks ago
>>> print(sys.version)
3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
LaurentBerger commented 2 weeks ago

Sorry I understand now. I use same version ubuntu WSL2 and there is still no problem. of course there is no problem with norm. It is your configuration You can try

cv2.setNumThreads(0)
img = cv2.imread('test.jpg')
n = cv2.norm(img, img)

and

cv2.ocl.setUseOpenCL(False)
img = cv2.imread('test.jpg')
n = cv2.norm(img, img)
mcdamo commented 2 weeks ago

Thankyou, it runs with cv2.ocl.setUseOpenCL(False) so there must be an issue with OpenCL on this system.