I’m trying to use opencv within a blender plugin, so I need to import the opencv .pyd locally so as to not force users to install via pip.
I managed to get the standard opencv library working in blender:
after placing the windows installation local to my plugin directory and commenting out
#if hasattr(sys, 'OpenCV_LOADER'): #print(sys.path) #raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
in opencv\build\python\cv2\ init .py
This seemed to be flagging a recursion error since opencv was already installed via pip.
Unfortunately, the function I require (SIFT) is only included in opencv-python-contrib, and so I then went about trying to get this build of the opencv .pyd working in blender.
Here I had more problems, it seems there was no pre-built version of opencv-python-contrib as there was the standard opencv from sourceforge. I tried using the .pyd file that pip places in the site-packages folder though this gave various errors when trying to work into blender.
Why is the pre-built windows version of opencv only 6MB when the version pip installation is 60MB?
Secondly, why does the opencv init.py file have the line import .cv2? This seems to be causing the recursion errors, in that opencv was trying to import itself.
I was getting errors such as
ModuleNotFoundError: No module named 'cv2.cv2'
and also errors regarding the recursion issue that the prior commented out check guards for. I believe it relates somewhat to this:
if DEBUG: print("Relink everything from native cv2 module to cv2 package") py_module = sys.modules.pop("cv2") native_module = importlib.import_module("cv2")
I’d really appreciate if someone could explain how exactly the opencv init.py file works and why its so hard to just import the opencv .pyd file without all these issues from it trying to include itself.