解决报错ValueError: not enough values to unpack (expected 3, got 2)

这篇具有很好参考价值的文章主要介绍了解决报错ValueError: not enough values to unpack (expected 3, got 2)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

解决报错ValueError: not enough values to unpack (expected 3, got 2)

错误提示:
Traceback (most recent call last):
  File "E:/workspace/code/detect/ShapeDetect.py", line 86, in <module>
    ld.analysis(src)
  File "E:/workspace/code/detect/ShapeDetect.py", line 18, in analysis
    out_binary, contours, hierarchy = cv.findContours(binary, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)  #
ValueError: not enough values to unpack (expected 3, got 2)


进程已结束,退出代码为 1

在使用opencv进行关键点识别、边缘轮廓提取的时候,提示以上错误,报错原因是函数定义的返回值数量和调用函数时实际赋予的返回值数量不一致。导致这个问题,实际是因为opencv版本不一致引起的,新版opencv(opencv4)在调用findContours时只需要两个参数,需要删掉第一个参数(本文中错误行代码的out_binary),只需要删除一个参数就可以完美解决;opencv3需要三个参数,修改运行环境,使用opencv3.6也可解决。

解决方法
方法1

删除第一个参数,即代码改为:
contours, hierarchy = cv.findContours(binary, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)

方法2

修改opencv版本,降至opencv3文章来源地址https://www.toymoban.com/news/detail-504232.html

到了这里,关于解决报错ValueError: not enough values to unpack (expected 3, got 2)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • ValueError:too many values to unpack (expected 2)

    【学习参考】:成功解决ValueError:too many values to unpack (expected 2)_叫我李嘉图的博客-CSDN博客 ValueError: too many values to unpack (expected 3)_归来-依旧-是-少年的博客-CSDN博客 解决思路: (1).首先理解错误类型: ValueError–ValueError:函数或方法虽然接受了正确的【类型】的参数,但是该参数

    2024年02月12日
    浏览(30)
  • 规避ValueError:too many values to unpack (expected 2)错误

    之前我也写过有关这个错误的文章,但不是单独开的,今天单独开以便来者更快解决问题   错误示例: dict指的是字典 解析:ValueError:too many values to unpack (expected 2)      很明显:出错的在 v 这个值上.可能是出于值不是一个简单的数据类型,比如值是一个字典,元组,或者更复杂的嵌

    2024年02月13日
    浏览(36)
  • ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 128]

    因为用到了BatchNorm,所以batch_size要大于1,drop_last 参数设置为True。 如果是两个GPU训练,batch_size改为4。 参考 ValueError: Expected more than 1 value per channel when training, got input size [1, 16, 1, 1](解决方案) Pytorch遇到报错Expected more than 1 value per channel when training, got input size torch.Size

    2024年01月16日
    浏览(29)
  • 【Python】成功解决ValueError: could not convert string to float: ‘ ignoring input‘

    【Python】成功解决ValueError: could not convert string to float: ’ ignoring input’ 🌈 个人主页:高斯小哥 🔥 高质量专栏:Matplotlib之旅:零基础精通数据可视化、Python基础【高质量合集】、PyTorch零基础入门教程👈 希望得到您的订阅和支持~ 💡 创作高质量博文(平均质量分92+),分享更

    2024年04月15日
    浏览(36)
  • 解决:python+appium报错ValueError: Timeout value connect was <...>, but it must be an int, float or None.

    pip install --force-reinstall -v \\\"selenium==4.8.0\\\" 参考: python - Running an keyword on Robotframework throw an error: ValueError: Timeout value connect was object object at 0x106cc5b50 - Stack Overflow ValueError: Timeout value connect was object object at 0x7f7515f84420, but it must be an int, float or None. · Issue #863 · appium/python-client

    2024年02月11日
    浏览(61)
  • DefaultCPUAllocator: not enough memory: you tried to allocate

    DefaultCPUAllocator: not enough memory: you tried to allocate XXX 问题:系统内存不足。 解决方案(1):重启电脑/使用任务管理器关闭多余应用释放系统内存(临时方案) 任务管理器启用方式:ctrl+alt+del 到达进程页面-右键进程结束任务 解决方案(2):增加电脑虚拟内存(建议选该方案

    2024年02月12日
    浏览(29)
  • pandas字段分列遇到ValueError: Length of values does not match length of index

    在使用pandas针对字段进行分列时遇到这个问题,ValueError: Length of values does not match length of index。 问题描述 例如:针对字段进行分列 data[\\\'time\\\'] = data[\\\'time\\\'].astype(str) data[\\\'day\\\'] = data[\\\'time\\\'].str.split(\\\" \\\")[0] data[\\\'hour\\\'] = data[\\\'time\\\'].str.split(\\\" \\\")[1] 原来是语句写错了,这里只需要改成:

    2023年04月12日
    浏览(34)
  • RuntimeError: DefaultCPUAllocator: not enough memory: you tried to allocate 1105920 bytes.

    问题 RuntimeError: [enforce fail at ..c10coreCPUAllocator.cpp:76] data. DefaultCPUAllocator: not enough memory: you tried to allocate 1105920 bytes. 今天在使用自己电脑跑YOLOV7的时候,因为自己没有GPU所以使用CPU来跑测试模型,使用CPU来进行一张独立的图像进行预测,跑一张图像完全没有问题,非常的ni

    2023年04月13日
    浏览(26)
  • 解决pytorch报错——RuntimeError: Expected to have finished reduction in the prior iteration...

    之前写代码时碰到了这样一个错误: RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. You can enable unused parameter detection by (1) passing the keyword argument find_unused_parameters=True to torch.nn.pa

    2023年04月17日
    浏览(32)
  • 报错解决ValueError: did not find a match in any of xarray‘s currently installed IO backends

    最近在服务器上配置环境遇到了xarray读取nc数据的相关问题,折腾了一下午终于解决了,记录下来,希望帮助后来人。具体报错如下 想要解决该问题只需要 两步: 【1】下载相关依赖包 ​​​​​​​ 可以发现已经明显提示了 缺少IO backends ,可到给出的网址中寻求解答。

    2024年02月02日
    浏览(82)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包