The above answer doesn't solve my problem.
I am using cv2.putText()
to put text over a video.
This works as expected, but I am attempting to use a different font (not available in OpenCV).
I understand that OpenCV is limited to the cv2.FONT_HERSHEY
fonts, so I am using PIL with OpenCV to achieve this.
I used this method with images and that experiment was successful. But I am failing when I try something similar on a video.
import cv2
from PIL import ImageFont, ImageDraw, Image
camera = cv2.VideoCapture('some_video.wmv')
while cv2.waitKey(30) < 0:
rv, frame = camera.read()
if rv:
font = ImageFont.truetype("calibrii.ttf", 80)
cv2.putText(frame, 'Hello World!', (600, 600), font, 2.8, 255)
cv2.imshow('Video', frame)
I have the "calibrii.ttf" in the same directory and as I mentioned, this approach worked with images.
Here is the error:
cv2.putText(frame, 'Hello World!', (600, 600), font, 2.8, 255)
TypeError: an integer is required (got type FreeTypeFont)