// define head function
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED #include <iostream>
#include <string>
#include "cv.h"
#include "highgui.h"
#include "cxmat.hpp"
#include "cxcore.hpp"
#include "math.h" using namespace std;
using namespace cv; void Show_Image(Mat&, const string &); #endif // PS_ALGORITHM_H_INCLUDED #include "PS_Algorithm.h"
#include <time.h> using namespace std;
using namespace cv; #define pi 3.1415926 int main()
{
string Img_name("4.jpg");
Mat Img;
Img=imread(Img_name); float theta=pi/6; int width=Img.cols;
int height=Img.rows; /*
// horizontal skewing
int new_height=height;
int new_width=width+height*tan(theta)+1;
Mat Img_H=Mat::zeros(new_height,new_width, CV_8UC3); float Dis;
float new_x, new_y;
float x1, y1, p;
for (int y=0; y<new_height; y++)
{
Dis=(height-y)*tan(theta);
for (int x=0; x<new_width; x++)
{
new_y=y;
// right skew
// new_x=x-Dis;
// left skew
new_x=x+Dis-height*tan(theta); // if (new_x<0) new_x=0;
// if (new_x>width-1) new_x=width-2; if (new_x>0 && new_x<width-1)
{
x1=int(new_x);
y1=int(new_y);
p=new_x-x1; Img_H.at<Vec3b>(y,x)[0]=(1-p)*Img.at<Vec3b>(y1,x1)[0]+p*Img.at<Vec3b>(y1,x1+1)[0];
Img_H.at<Vec3b>(y,x)[1]=(1-p)*Img.at<Vec3b>(y1,x1)[1]+p*Img.at<Vec3b>(y1,x1+1)[1];
Img_H.at<Vec3b>(y,x)[2]=(1-p)*Img.at<Vec3b>(y1,x1)[2]+p*Img.at<Vec3b>(y1,x1+1)[2]; } }
}
Show_Image(Img_H, "out");
imwrite("H.jpg", Img_H);
*/ // vertical skewing
int new_height=height+width*tan(theta)+1;
int new_width=width;
Mat Img_V=Mat::zeros(new_height,new_width, CV_8UC3); float Dis;
float new_x, new_y;
float x1, y1, p;
for (int y=0; y<new_height; y++)
{ for (int x=0; x<new_width; x++)
{
Dis=x*tan(theta);
new_x=x;
// right skew
new_y=y-Dis;
// left skew
// new_y=y+Dis-width*tan(theta); if (new_y>0 && new_y<height-1)
{
x1=int(new_x);
y1=int(new_y);
p=new_y-y1; Img_V.at<Vec3b>(y,x)[0]=(1-p)*Img.at<Vec3b>(y1,x1)[0]+p*Img.at<Vec3b>(y1+1,x1)[0];
Img_V.at<Vec3b>(y,x)[1]=(1-p)*Img.at<Vec3b>(y1,x1)[1]+p*Img.at<Vec3b>(y1+1,x1)[1];
Img_V.at<Vec3b>(y,x)[2]=(1-p)*Img.at<Vec3b>(y1,x1)[2]+p*Img.at<Vec3b>(y1+1,x1)[2]; } }
}
Show_Image(Img_V, "out");
imwrite("V.jpg", Img_V); waitKey(); } // define the show image
#include "PS_Algorithm.h"
#include <iostream>
#include <string> using namespace std;
using namespace cv; void Show_Image(Mat& Image, const string& str)
{
namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE);
imshow(str.c_str(), Image); }

原图

效果图

最新文章

  1. 面试问题2:给一个5G的大文件,保存的数据为32位的整型,找到所有出现次数超过两次的数字
  2. 你眼中的async/await是什么样的?
  3. [译]在Mac上运行ASP.NET 5
  4. 初识VSTO Addin开发
  5. Liferay 6.2 改造系列之十七:当Portlet无权限时,不显示错误信息
  6. requireJS的使用_API(1)
  7. JQuery学习(表单对象属性)---checked
  8. nedb nodejs 数据库学习
  9. java集合类(二)List学习
  10. openvpn文本验证模式配置
  11. 【HDOJ】5564 Clarke and digits
  12. RedHat下GCC及G++的安装
  13. Cygwin ssh
  14. filters
  15. js原生设计模式——8单例模式之简约版属性样式方法库
  16. 在html中使用js
  17. IT术语的正确读法
  18. 身份证号码的正则表达式及验证详解(JavaScript,Regex)
  19. 基于NetMQ的TLS框架NetMQ.Security的实现分析
  20. mybatis+oracle实现简单的模糊查询

热门文章

  1. Web前端学习攻略
  2. STM32单片机和51单片机区别
  3. 为备考二级C语言做的代码练习---辅导资料《C语言经典编程282例》--(1)
  4. ui-router $transitions 用法
  5. eclipse不能添加tomcat
  6. ASP.NET页面间传值的几种方式
  7. 关于erlang的-run 的启动参数
  8. iOS文档预览功能教程
  9. 大白第一章第四节dp例题
  10. 关于System.Data.ParameterDirection四个枚举类型所起的作用(转)