我正在编写我的第一个代码之一,我想在图像上显示变量。从文本文件中读取变量。这是我的代码的一部分:
font=cv2.FONT_HERSHEY_SIMPLEX
fontScale=2
fontColor=(255,255,255)
lineType=2;
def line11():
cv2.ellipse(img, (443,350), (35,35), 0, 0, -180, (0,0,255), 4);
cv2.putText(img, x,(443,320),fontScale, (255,255,255),lineType)
从 tex 文件中读取值 x:
with open('US1.txt') as f1, open('US2.txt') as f2:
for x, y in zip(f1,f2):
x = x.strip()
y = y.strip()
print("{0} {1}".format(x, y))
不幸的是,我得到了错误:
TypeError
Traceback (most recent call last)
<ipython-input-2-bc1d3b9f83c2> in <module>
130
131 if (float(x) <=0.5):
--> 132 line11();
133
134 elif (0.5< float(x)<=1):
<ipython-input-2-bc1d3b9f83c2> in line11()
16 cv2.ellipse(img, (443,350), (35,35), 0, 0, -180, (0,0,255), 4);
17
---> 18 cv2.putText(img, x, (443,350),fontScale, (255,255,255),lineType)
19
20 def line12():
TypeError: must be real number, not tuple
我找不到解决方案。我尝试了很多选择(即x的清型),现在我很无助。有人可以向我解释吗?谢谢!
qq_遁去的一_1
繁星点点滴滴
相关分类