Opencv— — image offset
// 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的更多相关文章
- 利用html5、websocket和opencv实现人脸检测
最近学习人脸识别相关的东西,在MFC下使用OpenCV做了一个简单的应用.训练需要较多的数据,windows应用程序终究还是不方便,于是想着做成CS模式:检测识别都放在服务器端,视频获取和显示都放在网 ...
- Opencv CamShift+Kalman目标跟踪
#include "stdio.h" #include "string.h" #include "iostream" #include &q ...
- OpenCV图像轮廓检测
轮廓检测: 轮廓检测的原理通俗的说就是掏空内部点,比如原图中有3*3的矩形点.那么就可以将中间的那一点去掉. 一.关键函数1.1 cvFindContours函数功能:对图像进行轮廓检测,这个函数将 ...
- opencv基本的数据结构(转)
DataType : 将C++数据类型转换为对应的opencv数据类型 enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, ...
- OpenCV】透视变换 Perspective Transformation(续)
载分 [OpenCV]透视变换 Perspective Transformation(续) 分类: [图像处理] [编程语言] 2014-05-27 09:39 2776人阅读 评论(13) 收藏 举 ...
- Opencv step by step - 自适应阈值
上个博客提到的阈值化只是针对图像全局进行阈值化,opencv提供了一个更好的函数cvAdaptiveThreshold,可以做到局部特征的阈值化,这样一来, 整个图像的信息可以被更好的提取. #inc ...
- opencv学习笔记(二)寻找轮廓
opencv学习笔记(二)寻找轮廓 opencv中使用findContours函数来查找轮廓,这个函数的原型为: void findContours(InputOutputArray image, O ...
- csharp通过dll调用opencv函数,图片作为参数
[blog 项目实战派]csharp通过dll调用opencv函数,图片作为参数 一直想做着方面的研究,但是因为这个方面的知识过于小众,也是由于自己找资料的能力比较弱,知道今天才找 ...
- opencv 61篇
(一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报 分类: OpenCV ...
随机推荐
- iOS -- SKSpriteNode类
SKSpriteNode类 继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject(NSObject) ...
- C# 通过WebService方式 IIS发布网站 上传文件到服务器[转]
http://blog.sina.com.cn/s/blog_517cae3c0102v0y7.html 应用场景:要将本地的文件 上传到服务器的虚拟机上 网络环境:公司局域网(如下图中第二种) 开发 ...
- 淘宝HSF 框架使用 总结
@(JAVA开发) 淘宝HSF 框架使用 总结 随着网站访问量增加,仅仅靠增加机器已不能满足系统的要求,于是需要对应用系统进行垂直拆分和水平拆分.在拆分之后,各个被拆分的模块如何通信?如何保证性能?如 ...
- 基于ACCESS和ASP的SQL多个表查询与计算统计代码(一)
近期在写几个关于"Project - Subitem - Task"的管理系统,说是系统还是有点夸大了,基本就是一个多表查询调用和insert.update的数据库操作.仅仅是出现 ...
- ios 清理缓存(EGO)
一段清理缓存的代码例如以下: dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,) , ^{ NSSt ...
- javascript 判断字符串是否包换字符串
用"ghiahgiahgia".indexOf("hg"); 返回值>=0为包含,否则就是-1(不包含)
- 向odoo贡献中文翻译
建议通过 osc-git向odoo贡献中文翻译 osc-git 是指'开源中国'的git平台. 网址是 http://git.oschina.net/ 注册osc-git 账号省略. ...
- ZipOutputStream 用法 小计
ZipOutputStream s = new ZipOutputStream(File.Create(ZipedFile)); 构造函数之后 文件就已经创建出来了 只是 0kb s.Write(bu ...
- PHP中使用Redis
Redis是什么 Redis ( REmote DIctionary Server ) , 是一个由Salvatore Sanfilippo写的key-value存储系统. Redis是一个开源的使用 ...
- fedora delete openJDK
博客分类: linux 由于Fedora系统安装的时候会自带OpenJDK,安装完系统后 java -version 会显示 [root@localhost bin]# java -versio ...