opencv之WarpPerspective透视变化

// opencv2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"  
#include "cv.h"
#include "highgui.h"
#include <cxcore.h>
using namespace cv;
using namespace std;




int main(int argc, char **argv)
{
	CvPoint2D32f srcTri[4], dstTri[4];
	CvMat*       warp_mat = cvCreateMat(3, 3, CV_32FC1);
	IplImage*    src = NULL;
	IplImage*    dst = NULL;

	src = cvLoadImage("test.jpg", 1);
	dst = cvCloneImage(src);
	dst->origin = src->origin;
	cvZero(dst);

	srcTri[0].x = 0;
	srcTri[0].y = 0;
	srcTri[1].x = src->width - 1;
	srcTri[1].y = 0;
	srcTri[2].x = 0;
	srcTri[2].y = src->height - 1;
	srcTri[3].x = src->width - 1;
	srcTri[3].y = src->height - 1;

	dstTri[0].x = src->width * 0.05;
	dstTri[0].y = src->height * 0.33;
	dstTri[1].x = src->width * 0.9;
	dstTri[1].y = src->height * 0.25;
	dstTri[2].x = src->width * 0.2;
	dstTri[2].y = src->height * 0.7;
	dstTri[3].x = src->width * 0.8;
	dstTri[3].y = src->height * 0.9;

	cvGetPerspectiveTransform(srcTri, dstTri, warp_mat);
	cvWarpPerspective(src, dst, warp_mat);

	cvNamedWindow("src", 1);
	cvShowImage("src", src);
	cvNamedWindow("Affine_Transform", 1);
	cvShowImage("Affine_Transform", dst);

	cvWaitKey(0);

	cvReleaseImage(&src);
	cvReleaseImage(&dst);
	cvReleaseMat(&warp_mat);



	return 0;
}

你可能感兴趣的:(opencv之WarpPerspective透视变化)