最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

OpenCV圖像幾何變換之透視變換

 更新時(shí)間:2021年03月19日 15:10:17   作者:liekkas0626  
這篇文章主要為大家詳細(xì)介紹了OpenCV圖像幾何變換之透視變換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了OpenCV圖像幾何變換之透視變換的具體代碼,供大家參考,具體內(nèi)容如下

1. 基本原理

透視變換(Perspective Transformation)的本質(zhì)是將圖像投影到一個(gè)新的視平面,其通用變換公式為:

(u,v)為原始圖像像素坐標(biāo),(x=x'/w',y=y'/w')為變換之后的圖像像素坐標(biāo)。透視變換矩陣圖解如下:

仿射變換(Affine Transformation)可以理解為透視變換的特殊形式。透視變換的數(shù)學(xué)表達(dá)式為:

所以,給定透視變換對應(yīng)的四對像素點(diǎn)坐標(biāo),即可求得透視變換矩陣;反之,給定透視變換矩陣,即可對圖像或像素點(diǎn)坐標(biāo)完成透視變換,如下圖所示:

2. OpenCV透視變換函數(shù)

Mat getPerspectiveTransform(const Point2f* src, const Point2f* dst)
// Calculate a perspective transform from four pairs of the corresponding points.
// src – Coordinates of quadrangle vertices in the source image.
// dst – Coordinates of the corresponding quadrangle vertices in the destination image.
 
void warpPerspective(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())
// Apply a perspective transform to an image.
// src – Source image.
// dst – Destination image that has the size dsize and the same type as src.
// M – 3*3 transformation matrix.
// dsize – Size of the destination image.
// flags – Combination of interpolation methods and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation (dstsrc).
// borderMode – Pixel extrapolation method. When borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that corresponds to the “outliers” in the source image are not modified by the function.
// borderValue – Value used in case of a constant border. By default, it is 0.

3. 程序

#include <iostream>
 
#include "highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
 
int main()
{
 // get original image.
 cv::Mat originalImage = cv::imread("road.png");
 
 // perspective image.
 cv::Mat perspectiveImage;
 
 // perspective transform
 cv::Point2f objectivePoints[4], imagePoints[4];
 
 // original image points.
 imagePoints[0].x = 10.0; imagePoints[0].y = 457.0;
 imagePoints[1].x = 395.0; imagePoints[1].y = 291.0;
 imagePoints[2].x = 624.0; imagePoints[2].y = 291.0;
 imagePoints[3].x = 1000.0; imagePoints[3].y = 457.0;
 
 // objective points of perspective image.
 // move up the perspective image : objectivePoints.y - value .
 // move left the perspective image : objectivePoints.x - value.
 double moveValueX = 0.0;
 double moveValueY = 0.0;
 
 objectivePoints[0].x = 46.0 + moveValueX; objectivePoints[0].y = 920.0 + moveValueY;
 objectivePoints[1].x = 46.0 + moveValueX; objectivePoints[1].y = 100.0 + moveValueY;
 objectivePoints[2].x = 600.0 + moveValueX; objectivePoints[2].y = 100.0 + moveValueY;
 objectivePoints[3].x = 600.0 + moveValueX; objectivePoints[3].y = 920.0 + moveValueY;
 
 cv::Mat transform = cv::getPerspectiveTransform(objectivePoints, imagePoints);
 
 // perspective.
 cv::warpPerspective(originalImage,
   perspectiveImage,
   transform,
   cv::Size(originalImage.rows, originalImage.cols),
   cv::INTER_LINEAR | cv::WARP_INVERSE_MAP);
 
 // cv::imshow("perspective image", perspectiveImage);
 // cvWaitKey(0);
 
 cv::imwrite("perspectiveImage.png", perspectiveImage);
 
 return 0;
}

原始圖像及其透視變換結(jié)果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C語言動(dòng)態(tài)內(nèi)存管理分析總結(jié)

    C語言動(dòng)態(tài)內(nèi)存管理分析總結(jié)

    C語言中開辟內(nèi)存有很多種方式,目前我們最常用的也就是數(shù)組,但數(shù)組是在我們用到他之前就得設(shè)定好它的長度,有時(shí)很不方便。隨意我們來探究動(dòng)態(tài)內(nèi)存管理
    2021-11-11
  • 淺談C++反向迭代器的設(shè)計(jì)

    淺談C++反向迭代器的設(shè)計(jì)

    本文主要介紹了淺談C++反向迭代器的設(shè)計(jì),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • C++實(shí)現(xiàn)LeetCode165.版本比較)

    C++實(shí)現(xiàn)LeetCode165.版本比較)

    這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode165.版本比較),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • C++連接mysql數(shù)據(jù)庫(改進(jìn)版)

    C++連接mysql數(shù)據(jù)庫(改進(jìn)版)

    C++是大家都非常熟悉的,也是大家平時(shí)辦公中經(jīng)常會(huì)用到的,下面這篇文章主要給大家介紹了關(guān)于C++連接mysql數(shù)據(jù)庫的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-12-12
  • C/C++左旋字符串實(shí)現(xiàn)代碼舉例

    C/C++左旋字符串實(shí)現(xiàn)代碼舉例

    在C/C++語言中沒有專門的字符串變量,通常用字符數(shù)組來存放字符串,下面這篇文章主要給大家介紹了關(guān)于C/C++左旋字符串實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下
    2023-12-12
  • 基于C語言實(shí)現(xiàn)簡單的掃雷游戲

    基于C語言實(shí)現(xiàn)簡單的掃雷游戲

    這篇文章主要為大家詳細(xì)介紹了基于C語言實(shí)現(xiàn)簡單的掃雷游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • VisualStudio2022下配置 OpenMP多線程編程環(huán)境與運(yùn)行

    VisualStudio2022下配置 OpenMP多線程編程環(huán)境與運(yùn)行

    本文主要介紹了VisualStudio2022下配置 OpenMP多線程編程環(huán)境與運(yùn)行,文中通過圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-06-06
  • QT基于TCP實(shí)現(xiàn)網(wǎng)絡(luò)聊天室程序

    QT基于TCP實(shí)現(xiàn)網(wǎng)絡(luò)聊天室程序

    這篇文章主要為大家詳細(xì)介紹了QT基于TCP實(shí)現(xiàn)網(wǎng)絡(luò)聊天室程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • C語言輸入一個(gè)數(shù)判斷是否為素?cái)?shù)的多種方法

    C語言輸入一個(gè)數(shù)判斷是否為素?cái)?shù)的多種方法

    素?cái)?shù)是只能被1和它自己本身整除,不能被其他自然數(shù)整除的大于1的正整數(shù),下面這篇文章主要給大家介紹了關(guān)于C語言輸入一個(gè)數(shù)判斷是否為素?cái)?shù)的多種方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-04-04
  • Seesion在C++服務(wù)端的使用方法

    Seesion在C++服務(wù)端的使用方法

    這篇文章主要介紹了Seesion在C++服務(wù)端是怎么使用的?本文給出了解決方案和實(shí)例代碼供大家參考,需要的朋友可以參考下
    2020-02-02

最新評(píng)論

黑龙江省| 南部县| 余庆县| 定南县| 涿州市| 芦山县| 寿宁县| 民权县| 武冈市| 柳江县| 堆龙德庆县| 南阳市| 年辖:市辖区| 渝中区| 凌海市| 北宁市| 庆城县| 拉孜县| 深圳市| 宁津县| 宜兴市| 乌鲁木齐县| 如皋市| 灯塔市| 浮梁县| 航空| 林周县| 延津县| 西昌市| 龙井市| 乐昌市| 波密县| 沙湾县| 安溪县| 南部县| 芦山县| 县级市| 永善县| 九寨沟县| 玛曲县| 千阳县|