2014-09-21 36 views
3

是否可以使用putText()方法在對角線上繪製圖片上的文本?使用putText()對角?使用OpenCV

如果不是,除了使用addWeighted()將兩個圖片混合在一起(其中一個是對角放置的文本),還有其他選擇嗎?

我試圖把文字水印上的圖片,我的問題是,現在我使用addWeighted()來混合文本在白色背景上繪製。即使使用alpha 0.9,白色背景也會更改原始圖片。

我在VC10中使用OpenCV 2.4.9。 putText()方法是OpenCV上CORE庫的一部分。

任何想法?

感謝,

亞歷

+0

您還沒有給出我們任何背景。這個'putText'是什麼庫? – Dai 2014-09-21 07:40:19

+0

@Dai,是opencv API的一部分。 (2.4.9中的核心模塊) – berak 2014-09-21 07:49:44

+0

您可以在空圖像中使用putText,然後對角旋轉它,最後將其添加到原始圖像中。 – sergioFC 2014-09-21 08:15:57

回答

7

在使用我的意見的想法來看看這個例子:

#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; 
} 

結果:

lenna Wattermark

+0

太棒了。看起來不錯,做我需要的。 [大拇指] – user1003302 2014-09-21 09:36:07