opencv 如何在图像输入字幕

来源:互联网 发布:软件项目开发进度计划 编辑:程序博客网 时间:2024/05/20 01:10

          昨晚在床上看 opencv  看到了如何在图像输入字幕,其实前段时间我已经学过了,只是没认真琢磨,昨晚看了,尽早赶紧写了一下。哼~~~不错!

         代码如下:

   

IplImage *img=cvCreateImage(cvSize(640,480),8,1);CvFont font;double hScale=1.0;double vScale=1.0;int lineWidth=1;cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC, hScale, vScale, 0, lineWidth );cvPutText(img, "hellow world",cvPoint(100,100),&font, cvScalar(255,0,0) );cvShowImage("qq", img);cvWaitKey(0);return 0;


 

效果图:

 

参数:

cvInitFont(CvFont*font, intfontFace, double hscale, doublevscale, doubleshear=0, int thickness=1, intlineType=8)

 

Parameters:
  • font – Pointer to the font structure initialized by the function
  • fontFace

    Font name identifier. Only a subset of Hershey fonts  http://sources.isc.org/utils/misc/hershey-font.txt  are supported now:

    • CV_FONT_HERSHEY_SIMPLEX normal size sans-serif font
    • CV_FONT_HERSHEY_PLAIN small size sans-serif font
    • CV_FONT_HERSHEY_DUPLEX normal size sans-serif font (more complex than   CV_FONT_HERSHEY_SIMPLEX )
    • CV_FONT_HERSHEY_COMPLEX normal size serif font
    • CV_FONT_HERSHEY_TRIPLEX normal size serif font (more complex than CV_FONT_HERSHEY_COMPLEX )
    • CV_FONT_HERSHEY_COMPLEX_SMALL smaller version of  CV_FONT_HERSHEY_COMPLEX
    • CV_FONT_HERSHEY_SCRIPT_SIMPLEX hand-writing style font
    • CV_FONT_HERSHEY_SCRIPT_COMPLEX more complex variant of  CV_FONT_HERSHEY_SCRIPT_SIMPLEX

    The parameter can be composited from one of the values above and an optional  CV_FONT_ITALIC  flag, which indicates italic or oblique font.

  • hscale – Horizontal scale.  If equal to  1.0f , the characters have the original width depending on the font type. If equal to 0.5f , the characters are of half the original width.
  • vscale – Vertical scale. If equal to  1.0f , the characters have the original height depending on the font type. If equal to0.5f , the characters are of half the original height.
  • shear – Approximate tangent of the character slope relative to the vertical line.  A zero value means a non-italic font, 1.0f  means about a 45 degree slope, etc.
  • thickness – Thickness of the text strokes
  • lineType – Type of the strokes, see  line()  description

 

 

cvPutText(CvArr*img, const char*text, CvPoint org, const CvFont*font, CvScalarcolor)

 

Parameters:
  • img – Image.
  • text – Text string to be drawn.
  • org – Bottom-left corner of the text string in the image.
  • fontCvFont structure initialized usingInitFont().
  • fontFace – Font type. One of  FONT_HERSHEY_SIMPLEXFONT_HERSHEY_PLAIN,FONT_HERSHEY_DUPLEXFONT_HERSHEY_COMPLEXFONT_HERSHEY_TRIPLEX, FONT_HERSHEY_COMPLEX_SMALLFONT_HERSHEY_SCRIPT_SIMPLEX, or  FONT_HERSHEY_SCRIPT_COMPLEX, where each of the font ID’s can be combined with FONT_HERSHEY_ITALIC  to get the slanted letters.
  • fontScale – Font scale factor that is multiplied by the font-specific base size.
  • color – Text color.
  • thickness – Thickness of the lines used to draw a text.
  • lineType – Line type. See the  line  for details.
  • bottomLeftOrigin – When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.

 

 

 

好了,到此啦。详见opencv manual~~~

 

 

 

原创粉丝点击