Friday, 13 May 2011

Add text to image

The code is:

#include "cv.h" 
#include "highgui.h" 
#include <iostream>
using namespace std;
 
int main() 
{ 
  IplImage *img = cvLoadImage("C:/Users/amit/Desktop/BACKUP1.jpg"); 
 
  /* initialize font and add text */ 
  CvFont font; 
  cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0, 1, CV_AA); 
 
cvPutText(img, "Hello ^_^", cvPoint(40, 40), &font, cvScalar(255, 0, 0, 0)); 
  /* display the image */ 
  cvNamedWindow("image", CV_WINDOW_AUTOSIZE); 
  cvShowImage("image", img); 
  cvWaitKey(0); 
  cvDestroyWindow("image");
  cvReleaseImage( &img );
  return 0;
}


The output is:


The command used initiating font ,size ,thickness is of format: 
cvInitFont(CvFont* font, int fontFace, double hscale, double vscale, double shear=0, int thickness=1, int lineType=8)

The command cvPutText() is used to wite the text on the image at required coordinates.
cvPutText(CvArr* img, const char* text, CvPoint org, const CvFont* font, CvScalar color)

 

Draws a text string.
Parameters:
  • img – Input image
  • text – String to print
  • org – Coordinates of the bottom-left corner of the first letter
  • font – Pointer to the font structure
  • color – Text color

No comments:

Post a Comment