Created
February 7, 2012 00:54
-
-
Save fukata/1756286 to your computer and use it in GitHub Desktop.
put_text_sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv/cv.h> | |
#include <opencv/highgui.h> | |
#include <time.h> | |
// http://opencv.jp/sample/text.html | |
// gcc put_text_sample.c -o put_text_sample `pkg-config --libs --cflags opencv` && ./put_text_sample | |
int | |
main (int argc, char **argv) | |
{ | |
int i; | |
IplImage *img; | |
CvRNG rng = cvRNG (time (NULL)); | |
CvScalar rcolor; | |
int irandom; | |
int font_face[] = { | |
CV_FONT_HERSHEY_SIMPLEX, | |
CV_FONT_HERSHEY_PLAIN, | |
CV_FONT_HERSHEY_DUPLEX, | |
CV_FONT_HERSHEY_COMPLEX, | |
CV_FONT_HERSHEY_TRIPLEX, | |
CV_FONT_HERSHEY_COMPLEX_SMALL, | |
CV_FONT_HERSHEY_SCRIPT_SIMPLEX, | |
CV_FONT_HERSHEY_SCRIPT_COMPLEX | |
}; | |
CvFont font[16]; | |
float italicscale = 0.0f; | |
int thickness = 3; | |
// (1)画像を確保し初期化する | |
img = cvCreateImage (cvSize (400, 500), IPL_DEPTH_8U, 3); | |
cvZero (img); | |
// (2)フォント構造体を初期化する | |
for (i = 0; i < 16; i += 2) { | |
cvInitFont (&font[i], font_face[i / 2], 1.0, 1.0, italicscale, thickness, CV_AA); | |
cvInitFont (&font[i + 1], font_face[i / 2] | CV_FONT_ITALIC, 1.0, 1.0, italicscale, thickness, CV_AA); | |
} | |
// (3)フォントを指定して,テキストを描画する | |
for (i = 0; i < 16; i++) { | |
irandom = cvRandInt (&rng); | |
rcolor = CV_RGB (irandom & 255, (irandom >> 8) & 255, (irandom >> 16) & 255); | |
cvPutText (img, "OpenCV sample code", cvPoint (15, (i + 1) * 30), &font[i], rcolor); | |
} | |
// (4)画像の表示,キーが押されたときに終了 | |
cvNamedWindow ("Text", CV_WINDOW_AUTOSIZE); | |
cvShowImage ("Text", img); | |
cvWaitKey (0); | |
cvDestroyWindow ("Text"); | |
cvReleaseImage (&img); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment