我尝试使用此代码在视频上绘制动画点
require(microbenchmark)
pmax_new <- function(a, b) {
elsb <- which(a > b)
b[elsb] <- a[elsb]
b
}
a <- c(3,3,5,NA,1)
b <- c(2,4,6,0,NA)
s <- 20
microbenchmark( pmax(rep(a, s), rep(b, s)), times = 1E6 )
microbenchmark( pmax_new(rep(a, s), rep(b, s)), times = 1E6)
但是整个动画发生在单个帧上,而不是连续帧上连续。另外,我想在红色球/圆圈中添加一定程度的抖动/随机性。 如何实现两者?
答案 0 :(得分:1)
Ahh通过调整睡眠计时器并跳过帧来解决了
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()