How this occurred: I wrote import cv2 in jupyter notebook code cell and run,then ImportError occurred.
What I have tried: I have tried to uninstall opencv-python and opencv-contrib-python
and reinstall opencv-python, but it didn't work.
Detailed Error:
ImportError Traceback (most recent call last)
<ipython-input-1-7660ed0d4d71> in <module>
----> 1 import cv2
2 import numpy as np
3 import os
4 from matplotlib import pyplot as plt
5 import time
D:\Anaconda3\lib\site-packages\cv2\__init__.py in <module>
7
8 from .cv2 import *
----> 9 from .cv2 import _registerMatType
10 from . import mat_wrapper
11 from . import gapi
ImportError: cannot import name '_registerMatType' from 'cv2.cv2' (D:\Anaconda3\lib\site-packages\cv2\cv2.cp38-win_amd64.pyd)
CodePudding user response:
As you have reinstalled opencv-python, I believe you have the latest version, 4.5.5.62.
Simply make sure that you have the corresponding version of opencv-python-headless, which is also the latest version, 4.5.5.62. If your opencv-python-headless is not the latest version, I recommend you uninstalling it, and then reinstalling it.
CodePudding user response:
I created an environment named tf1 in conda before, and I tried to reinstall opencv-python and opencv-python-headless many times. I also checked the version problems between them, and there was no problem. My problem occurred in jupyter notebook. Although I have modified it to use the tf1 kernel, the kernel in the notebook is still used by the system, so I directly use pip list in cmd to check the version, and finally found The versions of opencv-python and opencv-python-headless of the system do not correspond, and they work normally after the last update.
