Import cv2 causes 'segmentation fault (core dump)'

I am using jetpack 4.5.1 and cv2 which was built (without qt5) using instructions at Install OpenCV 4.5 on Jetson Nano - Q-engineering
its currently using cv2 4.5.1 (just an attempt to see if a downgrade helped the issue)
Simply put, in Python3 if import cv2 is put first it works - if put anywhere else it gives ‘segmentation fault (core dump)’
… working

import cv2
import dlib
import face_recognition   
print ('cv2.__version__ = ' + cv2.__version__)
print('dlib.DLIB_USE_CUDA = ' + str(dlib.DLIB_USE_CUDA))
print('dlib version = ' + dlib.__version__ )
print('dlib compiled = ' + dlib.__time_compiled__)
print('face_recognition.__version__ = ' + face_recognition.__version__ )
# print (cv2.getBuildInformation())

…failing

import dlib
import face_recognition   
import cv2
print ('cv2.__version__ = ' + cv2.__version__)
print('dlib.DLIB_USE_CUDA = ' + str(dlib.DLIB_USE_CUDA))
print('dlib version = ' + dlib.__version__ )
print('dlib compiled = ' + dlib.__time_compiled__)
print('face_recognition.__version__ = ' + face_recognition.__version__ )
# print (cv2.getBuildInformation())

I was led to believe that in python the order of these did not matter.
Can anybody explain this behaviour ?
Thanks JC

Hi,
Not sure but probably there is dependency between the packages. May see if other users know it and can share information.

It should be fine to import cv2 first.

Not sure, but maybe cv2 and dlib are importing different versions of numpy.
You may check in each case the numpy version with:

numpy.version.version

Also note that opencv may import numpy as np.

Honey, I dont think I understand your suggestion.
you have to import cv2 to see numpy.version.version (or numpy.__version__)
If you try to view that after only import cv2 or imprt dlib then you get an error.
What I can see is that there is only one version numpy on the machine (1.13.3) and that seems to be the default. This was installed early in the build and then both cv2 and dlib have been built after that. cv2 will tell me what its using but I cant see a way to get the same info from dlib. But dlib list this as a python dependancy rather than a build/link module,

Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.6.9)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.6m.so (ver 3.6.9)
    numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.13.3)
    install path:                lib/python3.6/dist-packages/cv2/python-3.6

Thanks
JC

Try this to find out what’s wrong:

$ LD_DEBUG=files python -c "import cv2"

MtHiker,
Sorry for the late reply - I am sure you know how things can get in the way of active investigations.
Anyway I am back on Jetson now
the output of command 'LD_DEBUG=files python3 -c "import cv2"''
(note ‘python3’ not just ‘python’ which goes to python2)
is in debug_out_just_import_cv2.txt its over 3000 lines so I haven’t pasted it.
BUT just importing cv2 does not cause an error
What does is the following python code

> import numpy as np
> import dlib
> import face_recognition   
> import cv2
> print ('cv2.__version__ = ' + cv2.__version__)
> print ('np.__version__ = ' + np.__version__)
> print('dlib.DLIB_USE_CUDA = ' + str(dlib.DLIB_USE_CUDA))
> print('dlib version = ' + dlib.__version__ )
> print('dlib compiled = ' + dlib.__time_compiled__)
> print('face_recognition.__version__ = ' + face_recognition.__version__ )

invoking this with
LD_DEBUG=files python3 ~/OpenCV_jet/check_lib_versions3.py
gives the segfault_debug_trace1.txt file, it is a couple of thousand lines too.
I have no idea what to look for in here - could you please give me a hint?

JC
debug_out_just_import_cv2.txt (152.7 KB)

segfault_debug_trace1.txt (132.4 KB)

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.