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 ...
随机推荐
- Android动画系列 - PropertyAnim 详解
前言:上一篇文章传统View动画与Property动画基础及比较简单对Android动画系统的基础做了介绍,本篇文章将对PropertyAnimation进行全面深入的探讨,本篇文章可以分为两大块,从 ...
- clipRect 介绍
clipRect 介绍 博客分类: android android的clip有以下两点疑问: Clip(剪切)的时机 Clip中的Op的参数的意思. 通常咱们理解的clip(剪切),是对已经存 ...
- 为什么硬盘明明还有空间,linux却说硬盘空间不足?inode;mkdir: 无法创建目录"shen1": 设备上没有空间
现象:df -h显示硬盘还有14G空间,但是touch file/mkdir directory都失败,提示硬盘没有空间 原因:df -ia查看下inode的使用情况,发现已经爆了,(下图显示使用88 ...
- XmlNode与XmlElement的区别总结
原文链接:http://www.cnblogs.com/oilsun/archive/2012/07/07/2580427.html 今 天在做ASP.NET操作XML文档的过程中,发现了两个类:Xm ...
- ItelliJ IDEA开发工具使用—创建一个web项目
转 http://blog.csdn.net/wangyang1354/article/details/50452806 最近想用IDEA编辑器开发,但是平时都用MyEclipse和eclipse ...
- (二)MVVMLight 关联View和ViewModel
在我们按照(一)中的步骤,安装好MMVLight的环境后, 会多出一个文件夹ViewModel,里面有两个.cs文件MainViewModel.cs和ViewModelLocator.cs MainV ...
- Django-Rest-Framework部分源码流程分析
class TestView(APIView): ''' 调用这个函数的时候,会自动触发authentication_classes的运行,所以会先执行上边的类 ''' authentication_ ...
- caffe搭建--caffe- win10 vs2015 编译(支持GPU)--注意在cmake的时候需要根据情况仔细修改配置
--http://blog.csdn.net/longji/article/details/60964998 注意: 在cmake的时候需要根据情况仔细修改配置,比如,如果gpu的能力不足3.0的话, ...
- SharePoint ULS Log Viewer 日志查看器
SharePoint ULS Log Viewer 日志查看器 项目描写叙述 这是一个Windows应用程序,更加轻松方便查看SharePoint ULS日志文件.支持筛选和简单的视图. 信息 这是一 ...
- 有趣的Ruby-学习笔记3
Ruby方法 方法名要以小写字母开头.假设用大写字母开头会被作为常量 (这点非常奇怪) 定义一个无參的方法 def method_name expr.. end 定义一个有參的方法 def metho ...