Skip to content
This repository has been archived by the owner on Oct 20, 2018. It is now read-only.

buaabyl/cvPutUniText

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cvPutUniText

This function depend:

  • libiconv: convert encoding
  • freetype: render bitmap from char

Interface:

CvUniLibrary* cvInitUniLibrary();
void cvCleanUniLibrary(CvUniLibrary* font_lib);

CvUniFont* cvInitUniFont(CvUniLibrary* font_lib, const char* font_face, int font_size);
void cvCleanUniFont(CvUniFont* font);

CvRect cvPutUniText(IplImage* img, const char* text,
        CvPoint org, CvUniFont* font, CvScalar color,
        const char* encoding, int calc);

Example:

int main(int argc, char* argv[])
{
    IplImage* img;
    CvUniLibrary* ft_lib;
    CvUniFont* ft_face;
    CvRect sz;
    int x = 50;
    int y = 20;
    char s[] = "这是一只小猫:cat.jpg";

    ft_lib = cvInitUniLibrary();
    ft_face = cvInitUniFont(ft_lib, "C://WINDOWS//Fonts//simsun.ttc", 32);

    img = cvLoadImage("cat.jpg", CV_LOAD_IMAGE_COLOR);
    y = img->height - 10;
    sz = cvPutUniText(img, s, cvPoint(x,y), ft_face, CV_RGB(0,0x3,0x8F), "UTF-8", 1);
    cvPutUniText(img, s, cvPoint(x,y), ft_face, CV_RGB(0,0x3,0x8F), "UTF-8", 0);
    cvSaveImage("cat-font.jpg", img, 0);
    cvWaitKey(-1);

    cvReleaseImage(&img);
    cvCleanUniFont(ft_face);
    cvCleanUniLibrary(ft_lib);

    return 0;
}

Original image:

image

Put chinese font to image:

image

  • red cross: font location
  • green line:font top
  • red line:baseline
  • blue line:font bottom

About

let opencv put unicode text to IplImage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published