如何在OpenCV的屏幕上保持较长时间的文本?

问题描述 投票:-2回答:1

我正在制作一个物体检测应用程序,一旦它发现一个移动的物体,它就会在屏幕上显示一条消息。但我希望消息在屏幕上停留更长时间。我尝试做这样的事情

while i < 10:
    cv2.putText(current_frame, "MOVING", (100, 300),
                            cv2.FONT_HERSHEY_TRIPLEX, 4, (255, 0, 0))
    i += 1

但它没有帮助,文本只出现了一秒钟。我怎么能做到这一点?

python-3.x opencv
1个回答
-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])
© www.soinside.com 2019 - 2024. All rights reserved.