使用cv :: Mat类型时如何在图像上覆盖文本 [英] How to overlay text on image when working with cv::Mat type

查看:119
本文介绍了使用cv :: Mat类型时如何在图像上覆盖文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opencv 2.1.在我的代码中,我存储了一些图像作为Mat对象存储,初始化如下:

I am using opencv 2.1. In my code I have a few images stored as Mat objects initialized like this:

Mat img1 = imread("img/stuff.pgm", CV_LOAD_IMAGE_GRAYSCALE);

完成矩阵运算后,可以使用imshow()正确显示它们.现在,我想在图像上添加一些文本来描述发生了什么.查看文档,看来cvPutText()将是我需要的功能.但是当我尝试这样的事情时:

I can display them properly using imshow() after my matrix operations are done. Now I want to add some text on the image to describe what has happened. Looking at the documentation it seems like cvPutText() would be the function I need. But when I try something like this:

cvPutText(result, "Differencing the two images.", cvPoint(30,30), &font, GREEN);

我收到以下编译错误: error: cannot convert ‘cv::Mat’ to ‘CvArr*’ for argument ‘1’ to ‘void cvPutText(CvArr*, const char*, CvPoint, const CvFont*, CvScalar)’

I get the following compile error: error: cannot convert ‘cv::Mat’ to ‘CvArr*’ for argument ‘1’ to ‘void cvPutText(CvArr*, const char*, CvPoint, const CvFont*, CvScalar)’

显示此图像时,我需要做些什么才能添加一些文本?

What do I need to do to be able to add some text when displaying this image?

推荐答案

我在看错地方.我在较新的 cpp的OpenCV文档中找到了答案.有一个名为putText()的新函数,该函数接受cv :: Mat对象.所以我尝试了这一行,它行得通:

I was looking at the wrong place. I found the answer in the newer OpenCV documentation for cpp. There is a new function called putText() that accepts cv::Mat objects. So I tried this line and it works:

putText(result, "Differencing the two images.", cvPoint(30,30), 
    FONT_HERSHEY_COMPLEX_SMALL, 0.8, cvScalar(200,200,250), 1, CV_AA);

希望这对某人有帮助.

这篇关于使用cv :: Mat类型时如何在图像上覆盖文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆