1. 程式人生 > >透視變換——鳥瞰圖

透視變換——鳥瞰圖

http://www.cnblogs.com/liekkas0626/p/5262942.html

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