Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when printing on an image using OpenCV putText

Tags:

c++

opencv

I am trying to print text on an image (cv::Mat) using cv::putText

string text = "Funny text inside the box";
int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
double fontScale = 2;
int thickness = 3;  
cv::Point textOrg(10, 130);
cv::putText(img, text, textOrg, fontFace, fontScale, Scalar::all(255), thickness,8);

But this results in an access violation error at runtime. While

cv::putText(img, "text", textOrg, fontFace, fontScale, Scalar::all(255), thickness,8);

results in "???text" being printed on the image. Any idea what could be going wrong?

like image 298
bsidd Avatar asked Feb 09 '12 03:02

bsidd


Video Answer


1 Answers

I am not sure what the correct protocol for this is, but I had the exact same problem as @arbguy and my fix was because of @Vlad's comment. From @Vlad's comment I checked to see if I was using the correct (debug) libraries for my Debug build. I was not. Setting the libraries to the debug version of of libraries fixed my error and I was able to use cv::putText correctly. Here's what I did (using visual studio 2012):

  1. Set all of my openCV .lib references to the "d.lib" versions. Your references will be different based on which libraries you are using but here are my references:

    opencv_imgproc242d.lib
    opencv_core242d.lib
    opencv_highgui242d.lib
    
  2. I then had to copy over the correct .dll libraries to my executable directory. I actually have a post-build step that copies the necessary .dll files into the binary directory. I also had to copy "tbb_debug.dll" as well. This is located in %OPENCVDIR%\build\common\tbb\ia32\vc10 (for my 32-bit build). the final list of .dll files I had to copy over was: opencv_imgproc242d.dll opencv_core242d.dll opencv_highgui242d.dll

After doing this everything worked! NOTE: I am not a C++ expert so if anybody has a better suggestion for doing this I'm happy. Also, I am not sure how to properly credit @Vlad for actually solving this problem since he is the one that suggested the correct solution.

like image 165
Julia Schwarz Avatar answered Nov 02 '22 20:11

Julia Schwarz