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_GRAYSCA
One nasty detail that I saw into my test code: pay attention into the import stament - it is not displayed into most examples and it needs to be the right import.
My test code used only the putText sample above and I did included the imgproc.h just as I did into some of my oldcode. The code compiled and linked fine however I was facing one weirdy behaviour with the putText (some garbage into my image).
It was a PITA until I figured out that the import was messing up with my social life ...
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;
}
}
Then I just changed the imgproc import above to
#include <opencv2/opencv.hpp> // << It does includes ALL opencv stuff
My 5 cents.