• Qt-OpenCV学习笔记--透视变换--warpPerspective()


    概述

    这个函数用来对图像进行 透视变换

    函数

    1. void cv::warpPerspective
    2. (
    3. InputArray src,
    4. OutputArray dst,
    5. InputArray M,
    6. Size dsize,
    7. int flags = INTER_LINEAR,
    8. int borderMode = BORDER_CONSTANT,
    9. const Scalar & borderValue = Scalar()
    10. )
    src源图像
    dst输出图像
    M变换矩阵(3*3)
    dsize输出图像的大小
    flags插值方法
    borderMode

    边框模式

     ● BORDER_CONSTANT

     ● BORDER_REPLICATE

    borderValue恒定边框的数值(默认为0)

    测试代码

    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. #include <QDebug>
    4. #include <opencv2/core/core.hpp>
    5. #include <opencv2/highgui/highgui.hpp>
    6. #include <opencv2/imgproc/imgproc.hpp>
    7. using namespace cv;
    8. Widget::Widget(QWidget *parent)
    9. : QWidget(parent)
    10. , ui(new Ui::Widget)
    11. {
    12. ui->setupUi(this);
    13. //载入图像
    14. Mat src = imread("c:/opencv/666.jpg");
    15. //显示
    16. imshow("src",src);
    17. //定义4个点
    18. Point2f ps_src[4];
    19. Point2f ps_dst[4];
    20. ps_src[0] = Point2f(0,0);
    21. ps_src[1] = Point2f(src.size().width-1 , 0);
    22. ps_src[2] = Point2f(src.size().width-1 , src.size().height-1);
    23. ps_src[3] = Point2f(0 , src.size().height-1);
    24. ps_dst[0] = Point2f(src.size().width*0.25 , src.size().height*0.20);
    25. ps_dst[1] = Point2f(src.size().width*0.75 , src.size().height*0.20);
    26. ps_dst[2] = Point2f(src.size().width*0.85 , src.size().height*0.85);
    27. ps_dst[3] = Point2f(src.size().width*0.15 , src.size().height*0.85);
    28. //获取变换矩阵
    29. Mat M = getPerspectiveTransform(ps_src,ps_dst);
    30. //定义输出图像
    31. Mat dst;
    32. //运算
    33. warpPerspective(src,dst,M,src.size());
    34. //显示
    35. imshow("dst",dst);
    36. }
    37. Widget::~Widget()
    38. {
    39. delete ui;
    40. }

    测试结果

    参考

    Opencv学习(15)—warpPerspective()

  • 相关阅读:
    error: undefined reference to ‘vtable for …’
    【力扣每日一题】1470. 重新排列数组
    Node.js中的child_process模块的作用
    OVS-DPDK 流表查询详解
    配置yum源仓库文件通过多种方式实现
    Flutter 状态管理之Bloc
    根据二叉树创建字符串
    Day22
    LTSPICE仿真那些事
    Leetcode128. 最长连续序列
  • 原文地址:https://blog.csdn.net/ssismm/article/details/127820494