How to overlay text on image when working with cv::Mat type(使用 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, "区分两个图像.", 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)'
我需要做什么才能在显示此图像时添加一些文本?
What do I need to do to be able to add some text when displaying this image?
推荐答案
我看错地方了.我在较新的 OpenCV 文档 cpp 中找到了答案.有一个名为 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);
希望这对某人有所帮助.
Hope this helps someone.
这篇关于使用 cv::Mat 类型时如何在图像上覆盖文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 cv::Mat 类型时如何在图像上覆盖文本


基础教程推荐
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01