Как нарисовать пунктирную линию в видео с помощью открытого резюме - PullRequest
0 голосов
/ 01 мая 2020

Я попытался с помощью этого кода нарисовать анимированную точку на видео

from collections import deque
from imutils.video import VideoStream
import numpy as np
import cv2
import imutils
import time

vs = cv2.VideoCapture('/media/intercept.mp4')    
pts = deque(maxlen=64) #buffer size

# keep looping
while True:
    ret,frame = vs.read()

    if frame is None:
        break
    # resize the frame, blur it, and convert it to the HSV
    # color space
    frame = imutils.resize(frame, width=600)
    blurred = cv2.GaussianBlur(frame, (11, 11), 0)
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    for i in range(10,260,20):
        time.sleep(0.5)     #To visualise dots one by one
        cv2.circle(frame,(i, i),10, (0,0,255), -1) #draw circle
        cv2.imshow('frame',frame)     #show output image
        if cv2.waitKey(1) == ord('q'):
            break

    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF
    # if the 'q' key is pressed, stop the loop
    if key == ord("q"):
        break

cv2.destroyAllWindows()
vs.release()    

Но вся анимация выполняется в одном кадре, а не непрерывно в последовательных кадрах. Также я хочу добавить определенный элемент джиттера / случайности в красный шар / круг. Как я могу достичь обоих?

1 Ответ

1 голос
/ 01 мая 2020

Ааа решил эту проблему, настроив таймер сна и пропустив кадры

from collections import deque
from imutils.video import VideoStream
import numpy as np
import cv2
import imutils
import time

vs = cv2.VideoCapture('/media/intercept.mp4')
pts = deque(maxlen=64) #buffer size

i=0
ct=0
# keep looping
while True:
    ret,frame = vs.read()
    # resize the frame, blur it, and convert it to the HSV
    # color space
    frame = imutils.resize(frame, width=600)
    blurred = cv2.GaussianBlur(frame, (11, 11), 0)
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    i+=2
    ct+=10
    #for i in range(10,260,20):
        #time.sleep(0.5)     #To visualise dots one by one
    if ct%10==0:
        cv2.circle(frame,(i, i),10, (0,0,255), -1) #draw circle
        #cv2.imshow('frame',frame)     #show output image
        if cv2.waitKey(1) == ord('q'):
            break

    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF
    # if the 'q' key is pressed, stop the loop
    if key == ord("q"):
        break

cv2.destroyAllWindows()
vs.release()   
...