我正在使用opencv-python进行人脸检测实验。我还想使用cv.drawRect函数。我尝试使用cv.putText,但它在Python中不受支持。除了cv.putText之外,是否有其他函数可以将文本写入图像帧?
font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 3, 8) #Creates a font
x = 10 #position of text
y = 20 #position of text
cv.PutText(image,"Hello World!!!", (x,y),font, 255) #Draw the text
如果有人对新版本的opencv-python感兴趣:
import cv2
font = cv2.FONT_HERSHEY_DUPLEX
color = (255, 0, 0) # red
fontsize = 255
text = "test"
position = (10, 10)
cv2.putText(image, text, position, font, fontsize, color=color)
enum HersheyFonts {
FONT_HERSHEY_SIMPLEX = 0, //!< normal size sans-serif font
FONT_HERSHEY_PLAIN = 1, //!< small size sans-serif font
FONT_HERSHEY_DUPLEX = 2, //!< normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX)
FONT_HERSHEY_COMPLEX = 3, //!< normal size serif font
FONT_HERSHEY_TRIPLEX = 4, //!< normal size serif font (more complex than FONT_HERSHEY_COMPLEX)
FONT_HERSHEY_COMPLEX_SMALL = 5, //!< smaller version of FONT_HERSHEY_COMPLEX
FONT_HERSHEY_SCRIPT_SIMPLEX = 6, //!< hand-writing style font
FONT_HERSHEY_SCRIPT_COMPLEX = 7, //!< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX
FONT_ITALIC = 16 //!< flag for italic font
};
(图片来源:Code Yarns)