首页 技术 正文
技术 2022年11月12日
0 收藏 353 点赞 4,648 浏览 1104 个字

在图像定位和模式识别时,经常需要把结果标注到图片上,标注内容可以是数字字母、矩形框等(opencv支持的)或者是中文汉字(借助freetype)。

1、显示数字/矩形框

#include <opencv/highgui.h>
using namespace cv;//绘画
Mat image = imread(image_root + filename);
Point p1(x,y), p2(x+w,y+h), p0(x+w/2, y+h/2);
string label = 123456789; //数字rectangle(image, p1, p2, Scalar(255, 0, 0));
putText(image, label.c_str(), p0, CV_FONT_HERSHEY_COMPLEX, 0.5, Scalar(0, 255, 0));imwrite( image_root2 + filename, image );

2、显示汉字

首先,下载freetype-2.6,在build/windows/vc2010中编译项目(我使用的是vs2012),在/objs/vc2010/Win32/下生成静态链接库freetype26.lib。

然后,新建项目,将freetype的include文件夹添加到项目的包含路径中,将freetype26.lib添加到链接文件中。添加汉字绘制类CvxText,编写例子:

#include <opencv/highgui.h>
#include <assert.h>
#include "CvxText.h"
using namespace cv;int main()
{
IplImage *image = cvLoadImage("lena.jpg", CV_LOAD_IMAGE_COLOR);
assert(image); // 输出汉字
{
// C:\\Windows\\Fonts为windows系统自带的字体,选择中文的
CvxText text("C:\\Windows\\Fonts\\FZSTK.TTF"); const char *msg = "在OpenCV中输出汉字!";
float p = 0.5;
text.setFont(NULL, NULL, NULL, &p); // 透明处理
text.putText(image, msg, cvPoint(100, 150), CV_RGB(0,0,255)); Mat mat(image);
imwrite( "pro.jpg", mat );
}
cvReleaseImage(&image);
return 0;
}

 

项目下载。

参考:http://blog.csdn.net/fengbingchun/article/details/8029337

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,909
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,434
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,249
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,060
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,692
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,730