Reputation: 12568
I am adding text in OpenCV like this...
import numpy as np
import cv2
font = cv2.FONT_HERSHEY_SIMPLEX
# Create a black image
img = np.zeros((512,512,3), np.uint8)
cv2.putText(img,'Hack Projects',(10,500), font, 1,(255,255,255),2)
#Display the image
cv2.imshow("img",img)
cv2.waitKey(0)
This works, but the text is not very good quality. Anybody know what I am doing wrong?
Upvotes: 11
Views: 6699
Reputation: 16791
As noted in the tutorial, text in OpenCV looks better if you add lineType = cv2.LINE_AA
to give you anti-aliased lines instead of the default cv.LINE_8
.
Changing your code to:
cv2.putText(img,'Hack Projects',(10,500), font, 1,(255,255,255),2, cv2.LINE_AA)
changes the image from this:
to this:
Upvotes: 27