Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Try this:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

void PutRotateText(cv::Mat& src, double angle, cv::Mat& dst)
{
    int _len = std::max(src.cols, src.rows);
    cv::Point2f pt(_len/2., _len/2.);
    cv::Mat r = cv::getRotationMatrix2D(pt, angle, 1.0);
    cv::warpAffine(src, dst, r, cv::Size(_len, _len));
}

int main() {
    Mat _img = imread("messi.jpg", CV_LOAD_IMAGE_COLOR);

    // Create and rotate the red text
    Mat messi_Imgage = Mat::zeros(_img.rows, _img.cols, _img.type());
    putText(messi_Imgage, "lionel messi", Point(0, _img.cols/2), FONT_HERSHEY_SIMPLEX, 2.0,Scalar(255,0,0),2);
    PutRotateText(messi_Imgage, -30, messi_Imgage);

    img+= messi_Imgage;

    namedWindow("Rotate Text", CV_WINDOW_AUTOSIZE);
    imshow("Rotate Text", _img);

    waitKey(0);
    return 0;
}