Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using putText() diagonally? Using OpenCV

Is it possible using the putText() method to draw text on a picture diagonally?

If not, beside using addWeighted() to blend two pictures together (where one of them is a text placed diagonally), is there any other option?

I'm trying to place a text watermark on a picture, my problem is that right now i'm using addWeighted() to blend a text drawn diagonally on a white background. Even with alpha 0.9, the white background changes the original picture.

I'm using OpenCV 2.4.9 with VC10. putText() method is part of CORE library on OpenCV.

Any ideas?

Thanks,

Alex

like image 861
user1003302 Avatar asked Sep 21 '14 07:09

user1003302


People also ask

How do you draw a polygon with OpenCV?

Step 1: Import cv2 and numpy. Step 2: Define the endpoints. Step 3: Define the image using zeros. Step 4: Draw the polygon using the fillpoly() function.


1 Answers

Have a look at this example using the idea of 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: http://opencv-code.com/quick-tips/how-to-rotate-image-in-opencv/)
 */
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);

    waitKey(0);
    return 0;
}

Result:

lenna Wattermark

like image 117
sergioFC Avatar answered Nov 08 '22 10:11

sergioFC