// 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

Opencv— — image offset的更多相关文章

  1. 利用html5、websocket和opencv实现人脸检测

    最近学习人脸识别相关的东西,在MFC下使用OpenCV做了一个简单的应用.训练需要较多的数据,windows应用程序终究还是不方便,于是想着做成CS模式:检测识别都放在服务器端,视频获取和显示都放在网 ...

  2. Opencv CamShift+Kalman目标跟踪

    #include "stdio.h" #include "string.h" #include "iostream" #include &q ...

  3. OpenCV图像轮廓检测

    轮廓检测: 轮廓检测的原理通俗的说就是掏空内部点,比如原图中有3*3的矩形点.那么就可以将中间的那一点去掉. 一.关键函数1.1  cvFindContours函数功能:对图像进行轮廓检测,这个函数将 ...

  4. opencv基本的数据结构(转)

    DataType : 将C++数据类型转换为对应的opencv数据类型 enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, ...

  5. OpenCV】透视变换 Perspective Transformation(续)

    载分 [OpenCV]透视变换 Perspective Transformation(续) 分类: [图像处理] [编程语言] 2014-05-27 09:39 2776人阅读 评论(13) 收藏 举 ...

  6. Opencv step by step - 自适应阈值

    上个博客提到的阈值化只是针对图像全局进行阈值化,opencv提供了一个更好的函数cvAdaptiveThreshold,可以做到局部特征的阈值化,这样一来, 整个图像的信息可以被更好的提取. #inc ...

  7. opencv学习笔记(二)寻找轮廓

    opencv学习笔记(二)寻找轮廓 opencv中使用findContours函数来查找轮廓,这个函数的原型为: void findContours(InputOutputArray image, O ...

  8. csharp通过dll调用opencv函数,图片作为参数

    [blog 项目实战派]csharp通过dll调用opencv函数,图片作为参数          ​一直想做着方面的研究,但是因为这个方面的知识过于小众,也是由于自己找资料的能力比较弱,知道今天才找 ...

  9. opencv 61篇

    (一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报  分类: OpenCV ...

随机推荐

  1. Android 测试自定义纯数字软键盘

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  2. SilverLight-DataControls:四、The PagedCollectionView(分页的集合视图) 对象

    ylbtech-SilverLight-DataControls-PagedCollectionView:The PagedCollectionView(分页的集合视图) 对象 1.A, Buildi ...

  3. 初涉IPC,了解AIDL的工作原理及用法

    初涉IPC,了解AIDL的工作原理及用法 今天来讲讲AIDL.这个神奇的AIDL,也是近期在学习的,看了某课大神的解说写下的blog,希望结合自己的看法给各位同价通俗易懂的解说 官方文档:http:/ ...

  4. 关于JavaScript禁止点击事件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 怎样隐藏Windows7 系统保留分区

    安装Windows7操作系统时须要预留出100MB左右的系统保留盘分区.在Windows7激活是必须给它分配盘符,否则无法将其成功激活,但是激活后该盘符永久地显示了出来,怎样将其隐藏掉呢? 1.隐藏前 ...

  6. Azure Mobile App - Custom Authentication

    Custom Authentication: 1. For OLD Mobile Service - https://azure.microsoft.com/en-us/documentation/a ...

  7. idea常用的快捷命令

    main方法: psvm System.out.println(): sout

  8. caffe2--ubuntu16.04--14.04--install

    Install Welcome to Caffe2! Get started with deep learning today by following the step by step guide ...

  9. cvpr2014

    http://www.cvpapers.com/cvpr2014.html 吴佳俊 楼天城

  10. 在Mac OS中配置CMake的详细图文教程http://blog.csdn.net/baimafujinji/article/details/78588488

    CMake是一个比make更高级的跨平台的安装.编译.配置工具,可以用简单的语句来描述所有平台的安装(编译过程).并根据不同平台.不同的编译器,生成相应的Makefile或者project文件.本文主 ...