cannot import name '_registerMatType' from 'cv2.cv2'
Solution 1
The same thing occurred to me yesterday when I used Colab. A possible reason may be that the version of opencv-python(4.1.2.30) does not match opencv-python-headless(4.5.5.62). Or the latest version 4.5.5 may have something wrong...
I uninstalled opencv-python-headless==4.5.5.62 and installed 4.1.2.30 and it fixed.
Solution 2
The same thing occurred to me. My status:
C:\Windows\system32>pip list |findstr opencv
opencv-python 4.5.2.52
opencv-python-headless 4.5.5.62
The version isn't same. So I first uninstall headless:
pip uninstall opencv-python-headless==4.5.5.62
Then reinstall headless 4.5.2.52 with opencv-python package.
pip install opencv-python-headless==4.5.2.52
The problem is the resolved.
Solution 3
Try uninstall and install(version 4.1.2.30) Headless main modules package
!pip uninstall opencv-python-headless
!pip install opencv-python-headless==4.1.2.30
Solution 4
I've had the same issue and the problem was with opencv versioning:
C:\Windows\system32>pip list |findstr opencv
opencv-python 4.5.2.52
opencv-python-headless 4.5.5.62
As you can see the versions are not the same, so first uninstall headless:
pip uninstall opencv-python==4.5.2.52
And then reinstall opencv-python 4.5.5.62 with opencv-python package:
pip install opencv-python-headless==4.5.5.62
Solution 5
I had the same issue and fixed it by just uninstalling and reinstalling opencv.
pip uninstall opencv-python
pip install opencv-python
Roger Jin
Updated on July 09, 2022Comments
-
Roger Jin almost 2 years
I got below error message when I run
model_main_tf2.py
on Object Detection API:Traceback (most recent call last): File "/content/models/research/object_detection/model_main_tf2.py", line 32, in <module> from object_detection import model_lib_v2 File "/usr/local/lib/python3.7/dist-packages/object_detection/model_lib_v2.py", line 29, in <module> from object_detection import eval_util File "/usr/local/lib/python3.7/dist-packages/object_detection/eval_util.py", line 36, in <module> from object_detection.metrics import lvis_evaluation File "/usr/local/lib/python3.7/dist-packages/object_detection/metrics/lvis_evaluation.py", line 23, in <module> from lvis import results as lvis_results File "/usr/local/lib/python3.7/dist-packages/lvis/__init__.py", line 5, in <module> from lvis.vis import LVISVis File "/usr/local/lib/python3.7/dist-packages/lvis/vis.py", line 1, in <module> import cv2 File "/usr/local/lib/python3.7/dist-packages/cv2/__init__.py", line 9, in <module> from .cv2 import _registerMatType ImportError: cannot import name '_registerMatType' from 'cv2.cv2' (/usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so)
The weird thing is I run the same code before, it worked well but now it gives me an error.
-
Sagar Rathod over 2 yearsThanks @Asaka!! It worked after installing
opencv-python-headless==4.1.2.30
on colab. -
Nguai al over 2 years@Asaka - How did you find out which library was the culprit and which version is the correct one? I have no clue when I get this kind of incompatibility error. Why Colab is not doing a good job with this production compatibility issue?
-
Asaka over 2 years@Nguaial-Actually I just use
!pip list
to check the version of open-cv related packages, and I see the version opencv-python-headless does not match with others. Besides, I once got to know that '_registerMatType' is a new module introduced after 4.5.4, so I think maybe it is the answer. -
Dr.jacky over 2 years
ERROR: No matching distribution found for opencv-python-headless==4.1.2.30