opencv python debug记录

        本文将持续记录opencv-python使用过程中出现的常见错误和解决方案。

1  window.cpp:1274: error: (-2:Unspecified error) The function is not implemented

        该错误通常表现为连最基本的cv2.imshow都无法使用。报错内容为:window.cpp:1274: error: (-2:Unspecified error) The function is not implemented.

Traceback (most recent call last):
File “/home/data/PJS/test_bed/img_show.py”, line 18, in
cv2.imshow(‘img’, img)
cv2.error: OpenCV(4.5.3) /tmp/pip-req-build-9gwtlx3c/opencv/modules/highgui/src/window.cpp:1274: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function ‘cvShowImage’
        解决方法:

import cv2
print(cv2.__file__)
#删除打印出来的cv2文件夹即可
#如果不行,卸载并重新安装opencv-python就可以了

2 error: (-215:Assertion failed) iDepth == CV_8U || iDepth == CV_8S in function 'cv::connectedComponents_sub1'

        出现这个错误,通常原因是图像矩阵的元素不是整数,所以报的是数据格式相关的错误提示。

image = image.astype(np.uint8)

更多三维、二维感知算法和金融量化分析算法请关注“乐乐感知学堂”微信公众号,并将持续进行更新。

猜你喜欢

转载自blog.csdn.net/suiyingy/article/details/125459380