我在测试代码中看到的一个讨厌的细节:注意导入方式-大多数示例中未显示该导入方式,它需要正确导入。
我的测试代码仅使用上面的putText示例,并且确实包含了imgproc.h,就像我对某些旧代码所做的一样。代码经过编译和链接很好,但是我面临着putText的一种怪异行为(图像中有些垃圾)。
直到我发现进口商品弄乱了我的社交生活,这才是PITA ...
imageText.cpp
#include "Imaging/imageText.h"
#include "Commons/xLog.h"
#include "opencv2/imgproc.hpp" // << Seems to work right?
using namespace cv;
namespace imaging
{
inline Mat image2mat( SmartImage image ) NOEXCEPTION
{
//TODO: hard coded to work only with CV_8UC3, see the other cases ...
Mat mat(
Size( image->WIDTH, image->HEIGHT ),
CV_8UC3,
image->buffer,
Mat::AUTO_STEP
);
return mat;
}
inline void _writeText_( SmartImage image, const string TEXT )
{
Mat mat( image2mat( image ) );
string text = "Funny text inside the box";
int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
double fontScale = 2;
int thickness = 3;
Point textOrg( 10, 130 );
putText( mat, text, textOrg, fontFace, fontScale, Scalar::all( 255 ), thickness, 8 );
}
const bool writeText( SmartImage image, const string text ) NOEXCEPTION
{
try
{
_writeText_( image, text );
return true;
}
catch( cv::Exception& e )
{
LOG_ERROR( "writeText OpenCV ERROR: " << e.what() << "!" );
}
catch( ... )
{
LOG_ERROR( "writeText ERROR!" );
}
return false;
}
}
然后我将上面的imgproc导入更改为
#include <opencv2/opencv.hpp> // << It does includes ALL opencv stuff
我的5美分。
0
我正在使用opencv 2.1。在我的代码中,我存储了一些作为Mat对象存储的图像,像这样初始化:
完成矩阵运算后,可以使用imshow()正确显示它们。现在,我想在图像上添加一些文本来描述发生了什么。查看文档,看来
cvPutText()
将是我需要的功能。但是当我尝试这样的事情: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)'
显示此图像时我需要做什么才能添加一些文本?