Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Fonts in OpenCV

📅 2015-Mar-11 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

 
 

OpenCV can be used to render text on an image buffer using the putText function. Several simple fonts are available in OpenCV which can be used to write text.

The available fonts can be seen defined in modules/imgproc/include/opencv2/imgproc.hpp header file:

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
};

FONT_ITALIC is not a font, but is a flag that can be combined with the other fonts to get italic text.

Tried with: OpenCV 2.4.9 and Ubuntu 14.04