opencv为图像画框并显示文字
2015-10-14 13:47
1036 查看
代码示例:
#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;
}
代码结果:
重要的两个函数的原型:
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 );
#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;
}
代码结果:
重要的两个函数的原型:
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 );
相关文章推荐
- opennms启动
- 浅谈Linux Kernel 中循环链表的实现
- Ubuntu apache配置虚拟路由
- 《架构之美》这本书的翻译版就是彻头彻尾的垃圾
- centos6.5下安装redmine或迁移
- Linux下PCIe驱动以及DMA机制
- centos7安装jdk1.7(rpm)
- OpenCV的智能指针: Ptr
- Stop Words
- shell三剑客之grep
- OpenWRT开发之——研究包的Makefile
- linux date timezone
- ansible 连接 windows (通过powershell)
- 图解FFMPEG打开媒体的函数avformat_open_input
- cross-compiling FFmpeg through Ubuntu Linux
- shell 中date 的用法
- Linux System Account SSH Weak Password Detection Automatic By System API
- java web项目打成war包放到linux下中文显示乱码
- NginxSSL
- CentOS6.7 安装Codeblocks