持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的4天,点击查看活动详情
1.报错信息
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/cv2/mat_wrapper/__init__.py in <module> 31 Mat.__module__ = cv.__name__ 32 cv.Mat = Mat ---> 33 cv._registerMatType(Mat) AttributeError: module 'cv2' has no attribute '_registerMatType'
今天使用opencv碰到的,感觉有点怪怪的,后来就github搜索,其实这个问题在2021年就已经有人说了。
2.信息确认
出错了当然第一时间github查了,会特别准确,不建议百度。
3.降级解决
There is mess with versions:
- `_registerMatType` is a part of OpenCV 4.5.4
- but you mention 4.5.1
Please ensure that you have installed one version of OpenCV only.
4.headless解决
I solved this error on Google Colab by downloading the headless open-cv and of a version below 4.3 because [backward compatibility](https://github.com/opencv/opencv-python#backward-compatibility) was dropped since 4.3.0. Try the following command in Google Colab:
`!pip install "opencv-python-headless<4.3"`
Here's a thread from [stack overflow](https://stackoverflow.com/questions/64650877/install-of-opencv-python-headless-takes-a-long-time) on the same issue.
看来大家在codelab上也遇到了。
opencv-python-headless<4.3
5.全部升级法
My problem was related to diferent versions of opencv modules. You can check it with:\
`pip list | grep opencv`
upgrading all modules to the same version solved my error:
pip install --upgrade opencv-python
pip install --upgrade opencv-contrib-python
pip install --upgrade opencv-python-headless
6.总结
建议那就都用最新版本吧,免得这错那错。