我正在创建一个对象检测应用程序,一旦它发现一个移动的对象,它就会在屏幕上显示一条消息。但我希望消息在屏幕上停留更长时间。我尝试过这样的事情
while i < 10:
cv2.putText(current_frame, "MOVING", (100, 300),
cv2.FONT_HERSHEY_TRIPLEX, 4, (255, 0, 0))
i += 1
但它没有帮助,文字只出现了一秒钟。我怎么能做到这一点?
答案 0 :(得分:-1)
## the variable that store detected obj's positions and counters
locs = {}
## the loop
while True:
ret, frame = cap.read()
## your detection processing
detectd, pos = detect(frame)
## Assume tag the obj on 5 frames
if detectd:
locs[pos] = 5
for pos in locs:
cv2.putText(current_frame, str(pos), loc, cv2.FONT_HERSHEY_TRIPLEX, 4, (255, 0, 0))
## update the variable
locs = dict([(k,v-1) for (k,v) in locs.items() if v>0])