Search code examples
pythonwebcamopencv

How to show a variable value on the webcam video stream? (python OpenCV)


I coded to open webcam video on a new window using OpenCV cv2.VideoCapture(0).

You can display text on webcam video using cv2.putText() command. But it displays string values only.

How to put varying values in the webcam video that is being displayed on a new window?

For example, if value of variable p is changing all the time, you can easily display it on the command window by writing print(p). But how can we display values of p over the webcam video?


Solution

  • You can also show changing variables using cv2.putText() method. Just need to convert the variable into string using str() method. Suppose you want to show variable x that is for example an integer and it is always changing. You can use cv2.putText(frame, str(x), org, font, fontScale, color, thickness, cv2.LINE_AA) to do it (You should fill org,font, etc.).