Opencv step by step - 绘图

有时候我们需要在图像上写一些字或者画一些简单的几何图案。

祭上代码:

#include <cv.h>
#include <highgui.h> int main(int argc,char **argv)
{ cvNamedWindow("image output");
IplImage *src = cvCreateImage(cvSize(800,600),IPL_DEPTH_8U,3); //draw line
cvLine(src, cvPoint(10,10), cvPoint(400,300), CV_RGB(255,166,177));
//draw rectangle
cvRectangle(src, cvPoint(100,20), cvPoint(300,500), CV_RGB(0,0,255));
//draw ellipse
cvEllipse(src, cvPoint(400,300), cvSize(200,100), 50, 0, 200, CV_RGB(0,255,0));
//draw font
char *text = "This is freaking fantastic!";
CvFont my_font;
cvInitFont(&my_font, CV_FONT_HERSHEY_SCRIPT_COMPLEX, 1, 1);
cvPutText(src, text, cvPoint(300, 400), &my_font, CV_RGB(100,255,0)); cvShowImage("image output", src);
cvWaitKey(); cvReleaseImage(&src);
cvDestroyWindow("image output");
}

注释里面写的比较清楚,这里画了直线,长方体,椭圆和文字。

效果图:

Opencv step by step - 绘图

上一篇:BNUOJ 52308 We don't wanna work! set模拟


下一篇:cmake简易教程