opencv为图像画框并显示文字

转自:https://blog.csdn.net/a200800170331/article/details/49124107
参考代码示例:

#include "opencv2/opencv.hpp"
int main()
{
	CvFont font;
	cvInitFont(&font, CV_FONT_HERSHEY_PLAIN, 1.5f, 1.5f, 0, 2, CV_AA);//设置显示的字体
	IplImage *pImg=cvLoadImage("1.jpg");
	CvPoint P1,P2;
	P1.x=50;
	P1.y=50;
	P2.x=200;
	P2.y=200;
	char *strID;
	strID="MyObject";
	cvRectangle(pImg,P1 ,P2, CV_RGB(0, 255, 0), 2);	//绿色画框
	cvPutText(pImg,strID, cvPoint(P1.x, P1.y-10), &font, CV_RGB(255, 0, 0));//红色字体注释
	cvNamedWindow("MyImg");
	cvShowImage("MyImg",pImg);
	cvWaitKey(0);
	cvReleaseImage(&pImg);
	return 1;
}

opencv为图像画框并显示文字_第1张图片
重要的两个函数的原型:

1./* Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2),
if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn /
CVAPI(void) cvRectangle( CvArr
img, CvPoint pt1, CvPoint pt2,
CvScalar color, int thickness CV_DEFAULT(1),
int line_type CV_DEFAULT(8),
int shift CV_DEFAULT(0));

2./* Renders text stroke with specified font and color at specified location.
CvFont should be initialized with cvInitFont /
CVAPI(void) cvPutText( CvArr
img, const char* text, CvPoint org,
const CvFont* font, CvScalar color );

你可能感兴趣的:(OpenCV)