Opencv— — image offset
2016-02-24 11:24
337 查看
// 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
/* Image offset. */ #include "PS_Algorithm.h" int main() { string Image_name("4.jpg"); Mat Img=imread(Image_name.c_str()); Mat Img_out(Img.size(), CV_8UC3); int warp, xOffset, yOffset; xOffset=150; yOffset=100; warp=1; int width=Img.cols; int height=Img.rows; if (warp) { while(xOffset<0) xOffset=xOffset+width; while(yOffset<0) yOffset=yOffset+height; xOffset=xOffset%width; yOffset=yOffset%height; } int new_x, new_y; for (int y=0; y<height; y++) { for (int x=0; x<width; x++) { if(warp) { new_x=(x+width-xOffset)%width; new_y=(y+height-yOffset)%height; } else { new_x=x-xOffset; new_y=y-yOffset; } if(new_x<0) new_x=0; if(new_x>=width-1) new_x=width-2; if(new_y<0) new_y=0; if(new_y>=height-1) new_y=height-2; for (int k=0; k<3; k++) { Img_out.at<Vec3b>(y, x)[k]=Img.at<Vec3b>(new_y, new_x)[k]; } } } Show_Image(Img_out, "New_img"); // cout<<"All is well."<<endl; // cout<<xOffset<<endl; // cout<<yOffset<<endl; 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); }
图像效果可以参考:
http://blog.csdn.net/matrix_space/article/details/46790011
相关文章推荐
- Nginx用作反向代理服务器使用
- 反向代理及Nginx示例
- Nginx查看并发数的两种方法及详解
- nginx环境wordpress 固定链接实现…
- SOA架构设计(转发)
- Opencv— — mix channels
- NGINX 配置404错误页面转向
- 【转载】运维小技巧:使用ss命令代替 netstat
- 国内几个重要的B2C网站
- docker swarm
- tomcat7-maven-plugin部署项目到远程tomcat报错
- CentOS6.4 LVS+keepalived高可用负载均衡服务配置
- nginx php5 整合
- 修改linux主机名导致mysql启动失败
- 在Windows和Linux上安装paramiko模块以及easy_install的安装方法
- [转] Linux中文件查找技术(名称、…
- discuz centos linux 部署标准
- nginx安装及配置
- Xcode6中如何修改文件中自动创建的Created by和Copyright 文件模板
- linux history 删除