对角使用putText()?使用OpenCV [英] using putText() diagonally? Using OpenCV

查看:106
本文介绍了对角使用putText()?使用OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用putText()方法沿对角线在图片上绘制文本?

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

如果没有,除了使用addWeighted()将两张图片混合在一起(其中一张是对角放置的文字)之外,还有其他选择吗?

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

我正在尝试在图片上放置文本水印,我的问题是现在我正在使用addWeighted()来混合在白色背景上对角线绘制的文本.即使使用alpha 0.9,白色背景也会改变原始图片.

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.

我在VC10上使用OpenCV 2.4.9. putText()方法是OpenCV上CORE库的一部分.

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

有什么想法吗?

谢谢

亚历克斯

推荐答案

使用我的评论来看看这个示例:

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

结果:

这篇关于对角使用putText()?使用OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆