Tag Archives: live video

Show current DateTime on live video using OpenCV-Python

Have you seen the security cameras output where DateTime continuously keeps updating? In this blog, we will be doing the same using OpenCV-Python i.e. we will put current DateTime on the live webcam feed. So, let’s get started.

For fetching current DateTime, we will be using Python’s DateTime module. The following code shows how to get the current DateTime

To put the DateTime on the live video, we will be using cv2.putText() on each frame as shown below

To know more about cv2.putText(), refer to this blog.

Above are the two things, that we will be needing for this task. I hope you understand these. Now, let’s get started

Steps:

  • Open the camera using cv2.VideoCapture()
  • Until the camera is open
    • Grab each frame using cap.read()
    • Put the current DateTime on each frame using cv2.putText() as discussed above
    • Display each frame using cv2.imshow()
  • On termination, release the webcam and destroy all windows using cap.release() and cv2.destroyAllWindows() respectively.

Code:

The snapshot of the output looks like this

Hope you enjoy reading.

If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.