/**
* @file SURF_Homography
* @brief SURF detector + descriptor + FLANN Matcher + FindHomography
* @author A. Huaman
*/
#include <stdio.h>
#include <iostream>
#include <cv.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
#define KCV_ImageRow(ptr, step, row)\
((ptr)+(step)* (row))
static void icvCircShiftUD_(const uchar* sptr_, int sstep, uchar* dptr_, int dstep, int w, int h, int yShift)
{
yShift = (h + yShift % h) % h;
if (yShift == 0) return;
sstep /= sizeof(sptr_[0]);
dstep /= sizeof(dptr_[0]);
const uchar* sptr = KCV_ImageRow(sptr_, sstep, h - yShift);
uchar* dptr = dptr_;
w *= sizeof(sptr[0]);
for (int i = 0; i < yShift; ++i, sptr += sstep, dptr += dstep)
{
memcpy(dptr, sptr, 3*w);//3*w,移位的是3通道图像;w,移位的是单通道图像
}
sptr = sptr_;
for (int i = yShift; i < h; ++i, sptr += sstep, dptr += dstep)
{
memcpy(dptr, sptr, 3*w);
}
}
int main()
{
IplImage* src = cvLoadImage("images\\lena.jpg",1);//1 代表导入彩色3通道图像,0代表导入黑白单通道图像
cvShowImage("src", src);
const uchar* sptr = (uchar*)(src->imageData);
int w = src->width;
int h = src->height;
int sstep = src->widthStep;
IplImage *dst = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 3);//3代表3通道图像,1代表单通道图像
uchar* dptr = (uchar*)(dst->imageData);
int dstep = dst->widthStep;
int yShift = 0;
CvRNG rng;
rng = cvRNG(cvGetTickCount());
for (int i = 0; i < 1000; i++)//产生1000幅循环移位图像
{
printf("%d\n", cvRandInt(&rng) % h);//出来的是0~h的正整数
yShift = cvRandInt(&rng) % h;
icvCircShiftUD_(sptr, sstep, dptr, dstep, w, h, yShift);
char filename[255];
sprintf_s(filename, "images\\dst\\dst%d.jpg", i);
cvSaveImage(filename, dst);
}
cvReleaseImage(&src);
cvReleaseImage(&dst);
cvWaitKey(-1);
return 0;
}