环境
OpenCV2:Mat属性type,depth,step
opencv/modules/core/include/opencv2/core/hal/interface.h
- https://www.cnblogs.com/wangguchangqing/p/4016179.html
- https://blog.csdn.net/github_30605157/article/details/79872549
透视变换
- https://blog.csdn.net/xiaowei_cqu/article/details/26471527
- https://www.cnblogs.com/liekkas0626/p/5262942.html
- https://blog.csdn.net/guduruyu/article/details/72518340
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <sys/time.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <cassert>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
cv::Mat get_perspective_mat()
{
cv::Point2f src_points[] = {
cv::Point2f(165, 270),
cv::Point2f(835, 270),
cv::Point2f(360, 125),
cv::Point2f(615, 125) };
cv::Point2f dst_points[] = {
cv::Point2f(165, 270),
cv::Point2f(835, 270),
cv::Point2f(165, 30),
cv::Point2f(835, 30) };
cv::Mat M = cv::getPerspectiveTransform(src_points, dst_points);
return M;
}
int main( int argc, char** argv )
{
String imageName( "/Users/qihao/Desktop/learn/opencv/20170519102859459.png" ); // 改成你想要的图片
cv::Mat img = cv::imread(imageName);
cv::Mat res(960, 270, img.type());
cv::Mat wrap = get_perspective_mat();
struct timeval begin, end;
gettimeofday(&begin, NULL);
warpPerspective(img.clone(), res, wrap, cv::Size(960, 270), cv::INTER_LINEAR);
gettimeofday(&end, NULL);
unsigned long time = 1000000 * (end.tv_sec - begin.tv_sec) + end.tv_usec - begin.tv_usec;
printf("opencv warp time(us): %ld\n", time);
cv::imwrite("res.jpg", res);
return 0;
}
project( s )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
find_package( OpenCV REQUIRED )
add_executable( s s.cpp )
target_link_libraries( s ${OpenCV_LIBS} )