OpenCV基本功能实现2

总结1

创建空白图像,并在此基础上画圆、矩形、直线、椭圆、文本。利用这些工具画简单的图形。
参数的具体使用

代码

#include <iostream>
#include <string>
#include <sstream>
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

using namespace std;
using namespace cv;

int main()
{
        //create blank image
        Mat img(512, 512, CV_8UC3, Scalar(255, 255, 255));
        circle(img, Point(256, 256), 190, Scalar(255, 0, 255), FILLED);
        ellipse(img, Point(175,195), Size(40,20), 0, 0, 360, Scalar(0, 0, 0), FILLED);
        ellipse(img, Point(335,195), Size(40,20), 0, 0, 360, Scalar(0, 0, 0), FILLED);
        line(img, Point(175,215), Point(175, 245), Scalar(0, 0, 255), 2);
        line(img, Point(335,215), Point(335, 245), Scalar(0, 0, 255), 2);
        circle(img, Point(256,306), 20, Scalar(0, 255, 255), FILLED);
        rectangle(img, Point(235,375), Point(275, 380), Scalar(0, 0, 255),FILLED);
        putText(img, String("OUCH!"), Point(215,40), FONT_HERSHEY_TRIPLEX, 1, Scalar(0, 255, 0), 3);
        imshow("Img", img);
        waitKey(0);
}

结果

在这里插入图片描述

总结2

利用透射变换将一个矩形区域提取出来

代码

#include <iostream>
#include <string>
#include <sstream>
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

using namespace std;
using namespace cv;

float w = 92, h = 103;
Mat matrix, imgWarp;

int main()
{
        Mat img;
        img = imread("me.jpg");
        resize(img, img, Size(), 0.4, 0.4);
        //the coordinates of source points
        Point2f src[4] = {{95,264}, {187,264}, {95,367}, {187,367}};
        //the coordinates of destination points
        Point2f dst[4] = {{0.0f,0.0f}, {w,0.0f}, {0.0f,h}, {w,h}};
        //perspective transformation
        matrix = getPerspectiveTransform(src, dst);
        warpPerspective(img, imgWarp, matrix, Size(w,h));
        //sign source points
        for(int i = 0; i < 4; i++)
        {
                circle(img, src[i], 5, Scalar(0, 0, 255), FILLED);
        }
        //show image
        imshow("Image", img);
        imshow("Image Wrap", imgWarp);
        waitKey(0);
}

结果

在这里插入图片描述 原图
在这里插入图片描述处理后的图片

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值