Using putText () diagonally? Using OpenCV

Can the putText () method be used to draw text diagonally?

If not, besides using addWeighted () to blend two images (where one of them is diagonally aligned text), is there any other option?

I am trying to place a text watermark on an image, my problem is that I am currently using addWeighted () to blend text drawn diagonally on a white background. Even with alpha 0.9, the white background changes the original image.

I am using OpenCV 2.4.9 with VC10. The putText () method is part of the OpenCV CORE library.

Any ideas?




source to share

1 answer

Take a look at this example using the idea from my comment:

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

using namespace std;
using namespace cv;

 * Rotate an image (source:
void rotate(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("lenna.png", CV_LOAD_IMAGE_COLOR);

    // Create and rotate the text
    Mat textImg = Mat::zeros(img.rows, img.cols, img.type());
    putText(textImg, "stackoverflow", Point(0, img.cols/2), FONT_HERSHEY_SIMPLEX, 2.0,Scalar(20,20,20),2);
    rotate(textImg, -45, textImg);

    // Sum the images (add the text to the original img)
    img= img+textImg;

    namedWindow("WaterMark", CV_WINDOW_AUTOSIZE);
    imshow("WaterMark", img);

    return 0;



lenna Wattermark



All Articles