在图片上框出人脸,出现了下面的错误:

cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
TypeError: an integer is required (got type tuple)

以前没有遇到过,在stackoverflow上找到了解释,是PIL.Image读出来的图像不能使用cv2的原因。
在此留下翻译的解释:
cv2模块用来处理numpy arrays的图像,而不是PIL.Image的实例。因为cv2.rectangle和Image类型都是完全用编译代码实现的,所以回溯对于理解出了什么问题并没有那么大帮助。在引擎盖下,本机cv2.rectangle()代码试图访问图像对象上需要整数,但cv2.rectangle()传入元组的内容,因为它希望与numpy arrays交互。
解决方法:
1)img = cv2.imread(imgpath)
2)转换PIL.Image为numpy.arrays
nparray = np.array(img)
另附:numpy array 转化为PIL.Image
img = Image.fromarray(nparray)

cv2.rectangle--TypeError: an integer is required (got type tuple)相关推荐

  1. python an integer is required_Python TypeError: an integer is required (got type tuple)

    Python TypeError: an integer is required (got type tuple) 关注:256  答案:2  mip版 解决时间 2021-01-12 12:36 提 ...

  2. pyinstaller打包任何py文件TypeError: an integer is required (got type bytes)

    pyinstaller打包任何py文件TypeError: an integer is required (got type bytes) 目录 pyinstaller打包任何py文件TypeErro ...

  3. 读取文件:TypeError: an integer is required (got type str)

    读取文件的时候报错: Traceback (most recent call last): File "D:\Python35\test\csdn.py", line 46, in ...

  4. python:使用PyInstaller打包成exe文件,以及TypeError: an integer is required (got type bytes)异常解决

    本文主要介绍安装pyinstaller教程与pyinstaller打包出现 TypeError: an integer is required (got type bytes)异常问题解决办法: 1. ...

  5. Python 使用pyinstaller打包exe文件报错: TypeError: an integer is required (got type bytes) 的解决方法

    python打包成exe文件首先需要安装pyinstaller库,再进入到目标文件目录,输入命令行打包py文件,但出现报错:TypeError: an integer is required (got ...

  6. TypeError: an integer is required (got type bytes)

    win10下spark2.4不能与python3.8及以上版本兼容,替换3.8为3.7完美解决

  7. an integer is required (got type tuple) 报错解决

    今天在调用Opencv的一个函数的时候出现如下报错: 原代码为: blur2 = cv2.boxFilter(img1, (3, 3), normalize=True) 这是在调用一个opencv 图 ...

  8. python报错 TypeError: an integer is required

    问题描述: 在本地使用socket向NetAssist传送数据的时候,执行python文件后发现报出python 报错TypeError: an integer is required错误 代码: 1 ...

  9. python opencv cv2.rectangle 参数含义

    因为做程序图像剪切一直不太明白是怎么切片的,这里就用 cv2.rectangle 这个函数来看一下 opencv 是怎么计量图像的坐标轴的. cv2.rectangle 这个函数的作用是在图像上绘制一 ...

  10. cv2.rectangle()画出矩形的用法

    cv2.rectangle(img, (x,y), (x+w,y+h), (0,255,0), 2) 功能:画出矩行框 参数:img:原图 (x,y):矩阵的左上点坐标 (x+w,y+h):矩阵的右下 ...

最新文章

  1. 小样本学习 few-shot learning
  2. phpstudy一直自动停止启动_发动机自动启停,到底是省油还是毁车?
  3. 11988 - Broken Keyboard (a.k.a. Beiju Text)
  4. 查询雇佣的所有员工_想要最好的员工? 让他们自己雇用
  5. 用汇编的眼光看C++(之循环流程)
  6. htc328d屏幕排线怎么换_HTC T328D解锁详细图文教程
  7. android 水晶报表,水晶报表分组,统计,求和,sum()函数使用
  8. UESTC - 59 数据大搜索
  9. 第 7 章 —— 代理模式
  10. Android之按钮点击事件——显示图片隐藏图片
  11. 长白县积极建设精准扶贫云平台
  12. 谈谈养老保险的那点猫腻 我愤怒了!
  13. html的国际标准智商测试,国际标准智商测试30题(含答案)
  14. 【转】关于“手动重新生成注册表性能计数器”的问题
  15. JavaWeb JavaBean,MVC三层架构
  16. 视频剪裁尺寸和裁剪时间
  17. 仿真4. 仿真平台架构设计
  18. 使用Cisco Packet Tracer练习无线还真不错!
  19. 设计模式之备忘录模式详解
  20. matlab 数组显示图片,20.1.4 显示图像数据

热门文章

  1. 遗传算法调参 参数设置
  2. 年轻人不再去菜市场,互联网如何拯救菜场摊贩?
  3. 前端---HTML制作百度首页
  4. 华为鸿蒙系统平板电脑,华为5G鸿蒙系统平板电脑正式入网,搭载八核处理器麒麟9000芯片...
  5. 苹果cms新手入门安装配置教程
  6. Alfred Workflow教程与实例
  7. Pythonic写法
  8. python学什么内容_老男孩Python都需要学什么内容?老男孩教育
  9. 京东话费充值,点击出现的css样式
  10. java中多个if语句如何简化_8种if else语句简化方法