I am am trying to use OpenCV to create an image from text. The image may or may not have an overlay that needs to be merged with it. The font of the Text needs to be needs to be different than the HERSHEY text that comes with the C++ interface of OpenCV. I saw in this post and others that it can be done using the cvFontQt and cvAddText.
I am using OpenCV 2.4.13 and Qt 5.6. In the sample code below I can output the first and third lines using cvPutText with cvFont and HERSHEY however the second line using cvAddText with cvFontQt does not display.
#include "stdafx.h"
#include "opencv2\core\core_c.h"
#include "opencv2\highgui\highgui_c.h"
int main()
{
// Create a window for a container to hold the image
cvNamedWindow("cvtest", CV_WINDOW_AUTOSIZE);
IplImage *img = cvCreateImage(cvSize(600, 300), IPL_DEPTH_64F, 4);
// Set the image background to white
cvSet(img, cvScalar(255, 255, 255));
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5);
cvPutText(img, "cvInitFont; cvPutText: First line.", cvPoint(4, 30), &font, cvScalar(255));
CvFont fontqt = cvFontQt("Courier New", -1, cvScalar(0,0,255), CV_FONT_NORMAL, CV_STYLE_NORMAL, 0);
cvAddText(img, "cvFontQV; cvAddText: Second line.", cvPoint(4, 60), &fontqt);
cvPutText(img, "cvInitFont; cvPutText: Third line.", cvPoint(4, 90), &font, cvScalar(255));
cvShowImage("cvtest", img);
cvWaitKey(0);
cvSaveImage("C:\\OpenCvTest64F.jpg", img);
// Cleanup
cvDestroyAllWindows();
cvReleaseImage(&img);
return 0;
}
The resulting image ("C:\OpenCvTest64F.jpg"):
Am I using cvFontQt or cvAddText incorrectly? Any thoughts on why it does not show up in the image?