python - CV2.rectangle 在 Windows 上需要整数,但在 Ubuntu 上使用浮点数
问题描述
我在 ubuntu 上编写了一些代码,并试图在 Windows 上运行它。
我在 Windows 上收到此错误:TypeError: integer argument expected, got float
self.rect1 = [(self.width / 2) - 10, (self.height / 2) - 10]
self.rect2 = [(self.width / 2) + 10, (self.height / 2) + 10]
cv2.rectangle(self.image, tuple(self.rect1), tuple(self.rect2), (255,0,0), -1)
我知道我可以通过使用来解决这个问题,int()
但我想像在 Ubuntu 上那样使用浮动值。
这是操作系统特定的原因吗?
更新
我相信@mesutpiskin 的回答是正确的。如果我手动将变量定义为浮点数:
self.rect1 = [200.5, 200.5]
self.rect2 = [210.5, 210.5]
我在 Ubuntu 上遇到同样的错误。我猜 Ubuntu 在除法期间返回 int 而不是 float。打印类型证实了这一点。
rect3 = [(width / 2) - 10, (height / 2) - 10]
rect4 = [(width / 2) + 10, (height / 2) + 10]
print(type(rect3[0]))
输出:<type 'int'>
解决方案
推荐阅读
- python - 将 json 字段解析为变量
- r - 如何将数字向量放入函数而不是R中的字符?
- python - 为什么draw的递归使用n-1时,打印输出中的N值会增加到2和3?
- node.js - 致命错误:接近堆限制的无效标记压缩分配失败 - JavaScript 堆内存不足 | 反应式
- android - 我收到此异常:对象不存在于该位置
- protobuf-net - 使用 protobuf-net.Grpc 生成通用服务的 .proto 文件
- list - 将列表存储在另一个列表中的列表中
- python - Pyplot 散点图名称未定义
- ruby-on-rails - 由于 Windows 上的 sqlite gem 版本不匹配,Rails 无法使用
- python - Odoo 备份错误:FileNotFoundError: [Errno 2] No such file or directory