opencv

环境

OpenCV2:Mat属性type,depth,step

opencv/modules/core/include/opencv2/core/hal/interface.h

透视变换

#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} )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值