cv2.rectangle--TypeError: an integer is required (got type tuple)
在图片上框出人脸,出现了下面的错误:
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)相关推荐
- 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 提 ...
- pyinstaller打包任何py文件TypeError: an integer is required (got type bytes)
pyinstaller打包任何py文件TypeError: an integer is required (got type bytes) 目录 pyinstaller打包任何py文件TypeErro ...
- 读取文件:TypeError: an integer is required (got type str)
读取文件的时候报错: Traceback (most recent call last): File "D:\Python35\test\csdn.py", line 46, in ...
- python:使用PyInstaller打包成exe文件,以及TypeError: an integer is required (got type bytes)异常解决
本文主要介绍安装pyinstaller教程与pyinstaller打包出现 TypeError: an integer is required (got type bytes)异常问题解决办法: 1. ...
- Python 使用pyinstaller打包exe文件报错: TypeError: an integer is required (got type bytes) 的解决方法
python打包成exe文件首先需要安装pyinstaller库,再进入到目标文件目录,输入命令行打包py文件,但出现报错:TypeError: an integer is required (got ...
- TypeError: an integer is required (got type bytes)
win10下spark2.4不能与python3.8及以上版本兼容,替换3.8为3.7完美解决
- an integer is required (got type tuple) 报错解决
今天在调用Opencv的一个函数的时候出现如下报错: 原代码为: blur2 = cv2.boxFilter(img1, (3, 3), normalize=True) 这是在调用一个opencv 图 ...
- python报错 TypeError: an integer is required
问题描述: 在本地使用socket向NetAssist传送数据的时候,执行python文件后发现报出python 报错TypeError: an integer is required错误 代码: 1 ...
- python opencv cv2.rectangle 参数含义
因为做程序图像剪切一直不太明白是怎么切片的,这里就用 cv2.rectangle 这个函数来看一下 opencv 是怎么计量图像的坐标轴的. cv2.rectangle 这个函数的作用是在图像上绘制一 ...
- cv2.rectangle()画出矩形的用法
cv2.rectangle(img, (x,y), (x+w,y+h), (0,255,0), 2) 功能:画出矩行框 参数:img:原图 (x,y):矩阵的左上点坐标 (x+w,y+h):矩阵的右下 ...
最新文章
- 小样本学习 few-shot learning
- phpstudy一直自动停止启动_发动机自动启停,到底是省油还是毁车?
- 11988 - Broken Keyboard (a.k.a. Beiju Text)
- 查询雇佣的所有员工_想要最好的员工? 让他们自己雇用
- 用汇编的眼光看C++(之循环流程)
- htc328d屏幕排线怎么换_HTC T328D解锁详细图文教程
- android 水晶报表,水晶报表分组,统计,求和,sum()函数使用
- UESTC - 59 数据大搜索
- 第 7 章 —— 代理模式
- Android之按钮点击事件——显示图片隐藏图片
- 长白县积极建设精准扶贫云平台
- 谈谈养老保险的那点猫腻 我愤怒了!
- html的国际标准智商测试,国际标准智商测试30题(含答案)
- 【转】关于“手动重新生成注册表性能计数器”的问题
- JavaWeb JavaBean,MVC三层架构
- 视频剪裁尺寸和裁剪时间
- 仿真4. 仿真平台架构设计
- 使用Cisco Packet Tracer练习无线还真不错!
- 设计模式之备忘录模式详解
- matlab 数组显示图片,20.1.4 显示图像数据