videogen_api / fonts.py
Lakpriya Seneviratna
chore: Add .gitignore and requirements.txt files
32007ab
raw
history blame contribute delete
760 Bytes
import cv2
import numpy as np
# Create a black image
image = np.zeros((480, 640, 3), dtype="uint8")
# Text to be added
text = "OpenCV Fonts"
# Coordinates
org = (50, 230)
# Font color
color = (255, 255, 255) # White
# Using different fonts
fonts = [
cv2.FONT_HERSHEY_SIMPLEX,
cv2.FONT_HERSHEY_PLAIN,
cv2.FONT_HERSHEY_DUPLEX,
cv2.FONT_HERSHEY_COMPLEX,
cv2.FONT_HERSHEY_TRIPLEX,
cv2.FONT_HERSHEY_COMPLEX_SMALL,
cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
cv2.FONT_HERSHEY_SCRIPT_COMPLEX
]
# Display text using different fonts
for i, font in enumerate(fonts):
cv2.putText(image, f"{text} {i+1}", (10, 30 + i*50), font, 1, color, 2)
# Show the image
cv2.imshow("OpenCV Fonts Example", image)
cv2.waitKey(0)
cv2.destroyAllWindows()