partially initialized module ‘cv2‘;module ‘cv2‘ has no attribute;cv2.error: OpenCV(4.7.0) D:\a\pencv

在使用超像素语义分割时会遇到的错误:

AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipeli

AttributeError: module ‘cv2’ has no attribute ‘ximgproc’

cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\ml\src\svm.cpp:1630: error: (-5:Bad argument) in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses in function ‘cv::ml::SVMImpl::train’

这些错误的原因是opencv-contrib-pythonopencv-python两个库之间的版本不兼容所造成的,如果你按照某一个错误原因去查询解决方案,那么你大概率会在这几次个错误之间反复跳转,并且无法解决

解决办法如下

先对两个包进行卸载:

pip uninstall opencv-contrib-python

pip uninstall opencv-python

然后选择相对应的版本进行安装:

pip install opencv-contrib-python==3.4.2.16

pip install opencv-python==3.4.2.16

目前能够使用的版本号如下:
version = 3.4.0.14, 3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.14.51, 3.4.14.53, 3.4.15.55, 3.4.16.57, 3.4.16.59, 3.4.17.61, 3.4.17.63, 3.4.18.65, 4.3.0.38, 4.4.0.40, 4.4.0.42, 4.4.0.44, 4.4.0.46, 4.5.1.48, 4.5.2.52, 4.5.2.54, 4.5.3.56, 4.5.4.58, 4.5.4.60, 4.5.5.62, 4.5.5.64, 4.6.0.66, 4.7.0.68, 4.7.0.72

SLIC分割的代码如下:

import skimage.segmentation as seg
import skimage.color as color
import matplotlib.pyplot as plt

# 读取图像
img = plt.imread('00002.jpg')

# SLIC超像素分割
num_segments = 2000
compactness = 10
segments = seg.slic(img, n_segments=num_segments, compactness=compactness)

# 显示结果
fig, ax = plt.subplots(1, 2, figsize=(10, 5))
ax[0].imshow(img)
ax[1].imshow(color.label2rgb(segments, img, kind='avg'))
plt.show()

在使用这段代码时可能会提示没有‘six’模块,直接 pip install 就行了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yokon_D

您的鼓励将是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值