The cvputtext () function in opencv adds the meaning of text:
Cvputtext (cvarr * IMG, const char * Text, cvpoint origin, constcvfont * font, cvscalar color );
The meanings of parameters in the function are as follows:
IMG--- Image pointer (it must be noted that cvarr * is equivalent to void *. Generally, an iplimage * is passed here *);
Text--- Apparently the content of the string to be printed to the image;
Origin--- The source of the string printed on the image (that is, the position of the lower-left corner of the string in the image)
Font--- A variable that describes the font attributes;
Color--- Font color;
CvfontThe initialization of type variables is implemented through the cvinitfont function. The declaration of this function is as follows:
Void cvinitfont (cvfont * font, int font_face, double h_scale, double v_scale, double shear = 0, intthickness = 1, int line_type = 8 );
The meanings of each variable in this function are as follows:
Font --- pointer to the incoming and outgoing font attribute types;
Font_face --- indicates the font type. The value can only be one of the following values:
1. cv_font_hershey_simplex
2. cv_font_hershey_plain
3. cv_font_hershey_duplex
4. cv_font_hershey_complex
5. cv_font_hershey_triplex
6. cv_font_hershey_complex_small
7. cv_font_hershey_script_simplex
8. cv_font_hershey_script_complex
H_scale --- it can only be 1 or 0.5, indicating the scaling factor of the horizontal font;
V_scale --- it can only be 1 or 0.5, indicating the zooming factor of the vertical font;
Shear --- the value ranges from 0 to 1, indicating the font skew. 0 indicates that the font is not skewed, and 1 indicates that the font is skewed to 45 degrees;
Thichness and line_type are the same as those defined in other plotting functions of opencv, indicating the width of the line and the type of the line;
The most common statements:
Iplimage * IMG = cvcreateimage (cvsize (width, height), ipl_depth_8u, 3 );
Char text [20] = "to print! ";
Cvpoint point = cvpoint (10, 10 );
Cvfont font;
Cvinitfont (& font, cv_font_hershey_duplex, 1.0f, 1.0f, 2, cv_aa );
Cvputtext (IMG, text, point, & font, cv_rgb (255, 0, 0 ));
Instance:
# Include "stdafx. H"
# Include "cv. H"
# Include "highgui. H"
# Include "cxcore. H"
# Include "iostream"
Using namespace STD;
Int _ tmain (INT argc, _ tchar * argv [])
{
Iplimage * pimg = cvloadimage ("C: \ lena.jpg ");
If (! Pimg)
{
Cout <"pimg load error..." <Endl;
System ("pause ");
Exit (-1 );
}
Cvfont font;
Cvinitfont (& font, cv_font_hershey_complex, 0.5, 0.5, 1, 2, 8 );
Cvputtext (pimg, "this is a picture named Lena! ", Cvpoint (50, 50), & font, cv_rgb (255, 0 ));
Cvsaveimage ("C: \ test1.jpg", pimg );
Cvnamedwindow ("IMG", 0 );
Cvshowimage ("IMG", pimg );
Cvwaitkey (0 );
System ("pause ");
Cvreleaseimage (& pimg );
Cvdestroyallwindows ();
Return 0;
}
Opcv Chinese network:
Http://www.opencv.org.cn/index.php/Cxcore%E7%BB%98%E5%9B%BE%E5%87%BD%E6%95%B0#InitFont