【发布时间】:2019-12-04 19:43:09
【问题描述】:
是否可以在录制视频并同时在这些图像上写入当前时间时获取帧?我一直在寻找这个,但我找不到任何东西。我想在每一帧上写下时间和/或用那个时间戳保存这些帧。我无法从视频中获取每一帧的时间信息,所以我想出了这个解决方案。我愿意接受任何想法。提前致谢。
【问题讨论】:
-
请显示您已经完成的方面的代码。
标签: python opencv camera frame video-recording
是否可以在录制视频并同时在这些图像上写入当前时间时获取帧?我一直在寻找这个,但我找不到任何东西。我想在每一帧上写下时间和/或用那个时间戳保存这些帧。我无法从视频中获取每一帧的时间信息,所以我想出了这个解决方案。我愿意接受任何想法。提前致谢。
【问题讨论】:
标签: python opencv camera frame video-recording
是的,这是可能的。 cap.get(0) 标志(其中 cap 是 cv2.VideoCapture 对象)为您提供以毫秒为单位的帧时间戳。你可以这样做:
import cv2
# If you want to write system time instead of frame timestamp then import datetime
# import datetime
filepath = '.../video.mp4'
cap = cv2.VideoCapture(filepath)
# If capturing from webcam then as follows:
# cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
if(ret== False):
break
current_time = cap.get(0)
# If you want system time then replace above line with the following:
# current_time = datetime.datetime.now()
cv2.putText(frame,'Current time:'+str(current_time),
(10, 100),
cv2.FONT_HERSHEY_SIMPLEX,
1,
(255,255,255),
2)
# Display the resulting frame
cv2.namedWindow('Frame with timestamp')
cv2.imshow('Frame with timestamp',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
希望这会有所帮助:)
【讨论】: