OpenCV-Python is a library of Python bindings designed to solve computer vision problems. It can process images and videos to identify objects, faces, or even the handwriting of a human
Note: For more information, refer to Introduction to OpenCV
Display date and time in videos
It sometimes becomes necessary to display date and time on videos when we are processing videos of live feed or videos which are of a large duration. Time and date will be helpful to know and analyze any anomaly detected in the video with reference to its time and date. To display date and time on videos we do the following.
Code
# Import libraries import numpy import cv2 import datetime # open the video vid = cv2.VideoCapture('sample.mp4') # Process untill end. while(vid.isOpened()): ret, frame = vid.read() if ret: # describe the type of # font you want to display font = cv2.FONT_HERSHEY_SCRIPT_COMPLEX # Get date and time and # save it inside a variable dt = str(datetime.datetime.now()) # put the dt variable over the # video frame frame = cv2.putText(frame, dt, (10, 100), font, 1, (210, 155, 155), 4, cv2.LINE_8) # show the video cv2.imshow('frame', frame) key = cv2.waitKey(1) # define the key to # close the window if key == 'q' or key == 27: break else: break # release the vid object vid.release() # close all the opened windows. cv2.destroyAllWindows() |
Output

Recommended Posts:
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Python | Download YouTube videos using youtube_dl module
- Transition from OpenCV 2 to OpenCV 3.x
- Pytube | Python library to download youtube videos
- Program to display Astrological sign or Zodiac sign for given date of birth
- Youtube Data API for handling videos | Set-1
- Youtube Data API for handling videos | Set-2
- Youtube Data API for handling videos | Set-3
- Youtube Data API for handling videos | Set-4
- Youtube Data API for handling videos | Set-5
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Multiple Color Detection in Real-Time using Python-OpenCV
- Detect Cat Faces in Real-Time using Python-OpenCV
- Python - Displaying real time FPS at which webcam/video file is processed using OpenCV
- How to print date starting from the given date for n number of days using Pandas?
- Python | Working with date and time using Pandas
- Get Current Date and Time using Python
- OpenCV | Real Time Road Lane Detection
- Python | Create video using multiple images using OpenCV
- Image resizing using Seam carving using OpenCV in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

