opencv displaying variable on video

2019-06-07 13:23发布

问题:

is it possible to overlay %d on the screen using opencv?

CvPutText()

was tried but that cant be done

回答1:

Let's pretend I didn't explained to you in a comment before.

int number  = 5;
char text[255]; 
sprintf(text, "Score %d", (int)number);

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, text, cvPoint(200,400), &font, cvScalar(255,255,0));


回答2:

cvPutText() draws on an image, but it doesn't do formatting - you need to format the string to be printed using sprintf or similar