<p>参数<code>org</code>用于选择文本在图像中的位置,文本的左下角放在点<code>org</code>处。如果希望文本更靠右,则增加x值;如果希望文本更低,则增加y值。所以每一行都会更低,因为您正在使用<code>offset*idx</code>增加y值。</p>
<p>正如您所拥有的,第二个参数<code>str(lbls)</code>将打印出整个数组,该数组应更改为单个元素的变量,您将其作为<code>list</code>。(但是,最好不要使用<code>list</code>作为变量,因为它将替换内置函数<code>list()</code>。我将使用<code>lbl</code>。)</p>
<p>下面是打印列表中单词的示例:</p>
<pre><code>import cv2
import numpy as np
import matplotlib.pyplot as plt
frame = np.ones([400,400,3])*255
lbls = ['standUp', 'front', 'lookU', 'lookF', 'lookDF', 'HandOnHipR']
offset = 35
x,y = 50,50
for idx,lbl in enumerate(lbls):
cv2.putText(frame, str(lbl), (x,y+offset*idx), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,0), 2)
plt.imshow(frame)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/V5mRO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V5mRO.jpg" alt="enter image description here"/></a></p>
<p>如果您希望使用上面显示的括号和标点符号,则可以手动打印它们。第一个和最后一个元素需要单独打印:</p>
<pre><code>cv2.putText(frame, '[\''+str(lbls[0])+'\',', (x,y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,0), 2)
for idx,lbl in enumerate(lbls[1:-1]):
cv2.putText(frame, '\''+str(lbl)+'\',', (x,y+offset*(idx+1)), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,0), 2)
cv2.putText(frame, '\''+str(lbls[0])+'\']', (x,y+offset*(idx+2)), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,0), 2)
</code></pre>
<p><a href="https://i.stack.imgur.com/P6zJ4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P6zJ4.jpg" alt="enter image description here"/></a></p>
<p>否则,可以将元素更改为实际包含标点符号。</p>