Opencv— — image offset
// define head function
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED
#include
#include
#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=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(y, x)[k]=Img.at(new_y, new_x)[k];
}
}
}
Show_Image(Img_out, "New_img");
// cout<<"All is well."<
// define the show image
#include "PS_Algorithm.h"
#include
#include
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);
}