【发布时间】:2018-05-18 12:59:45
【问题描述】:
您好,我正在尝试运行涉及绘制框但不断返回错误的代码
TypeError: integer argument expected, got float
出现的代码中的第一个问题是
def draw_box(Image, x, y, w, h):
cv2.line(Image, (x, y), (x + (w/5) ,y), WHITE, 2)
cv2.line(Image, (x+((w/5)*4), y), (x+w, y), WHITE, 2)
cv2.line(Image, (x, y), (x, y+(h/5)), WHITE, 2)
cv2.line(Image, (x+w, y), (x+w, y+(h/5)), WHITE, 2)
cv2.line(Image, (x, (y+(h/5*4))), (x, y+h), WHITE, 2)
cv2.line(Image, (x, (y+h)), (x + (w/5) ,y+h), WHITE, 2)
cv2.line(Image, (x+((w/5)*4), y+h), (x + w, y + h), WHITE, 2)
cv2.line(Image, (x+w, (y+(h/5*4))), (x+w, y+h), WHITE, 2)
我通过用 python 地板分割替换分割符号来解决这个问题,但接下来的方框图区域返回相同的类型错误
cv2.rectangle(Image, (Name_X_pos-10, Name_y_pos-25), (Name_X_pos +10 + (len(NAME) * 7), Name_y_pos-1), (0,0,0), -2)
我试过把 cv2.rectangle(int(Image, (Name_.. 只是为了接收回来
TypeError: int() takes at most 2 arguments (5 given)
关于如何解决这个问题的任何想法?
【问题讨论】:
-
你不想要
int(Image, (Name)..)- 你想将单个数字转换为整数,例如(int(Name_X_pos+10+len(NAME)*7), ...) -
我这样做了,它现在返回错误“ValueError: int() base must be >= 2 and
-
您在
int()中包含多个参数。一次只做一个数字(仔细查看我刚刚发送的代码)。 -
例如
cv2.rectangle(Image, (int(Name_X_pos-10), int(Name_y_pos-25)), (int(Name_X_pos +10 + (len(NAME) * 7)), int(Name_y_pos-1)), (0,0,0), -2) -
修复了它。感谢您的帮助