Python 如何使用open cv在视频中绘制虚线
我试着用这个代码在视频上画一个动画点Python 如何使用open cv在视频中绘制虚线,python,opencv,video-processing,Python,Opencv,Video Processing,我试着用这个代码在视频上画一个动画点 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 whi
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()
但整个动画发生在单个帧上,而不是连续发生在连续帧上。我还想给红色的球/圆添加一个抖动/随机性的元素。
如何实现这两个目标?啊哈通过调整睡眠计时器和跳过帧解决了这个问题
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()
你能更具体地说明问题是什么吗?请看,.@AMC只是想在视频上画一条曲线。从左侧进入,从右侧退出。请尝试改进您的问题。不太清楚你想做什么,人们不喜欢浪费时间猜测。你提到运动和视频,但你的代码显示的是静止图像?你提到像蛇一样的波浪线,但你的代码画了一条直线?我不相信任何人能明智地帮助你,除非你改进你的问题。@MarkSetchell改进了代码further@AMC根据我刚才的尝试,进一步改进了代码