源码:
void wave_sine(cv::Mat& src,cv::Mat& dst,double amplitude,double wavelength)
{
dst.create(src.rows, src.cols, CV_8UC3);
dst.setTo(0);
double xAmplitude = amplitude;
double yAmplitude = amplitude;
double xWavelength = wavelength;
double yWavelength = wavelength;
for (int h = 0; h < dst.rows; h ++) {
double fh = h / yWavelength;
fh = sin(fh);
fh = h + yAmplitude * fh;
int nh = floor(fh);
if (nh < 0 || nh > dst.rows - 1)
nh = h;
for (int w = 0; w < dst.cols; w ++) {
double fw = w / xWavelength;
//sine
fw = sin(fw);
fw = w + xAmplitude * fw;
int nw = floor(fw);
if (nw < 0 || nw > dst.cols - 1)
nw = w;
dst.at<Vec3b>(h, w)[0] = src.at<Vec3b>(nh, nw)[0];
dst.at<Vec3b>(h, w)[1] = src.at<Vec3b>(nh, nw)[1];
dst.at<Vec3b>(h, w)[2] = src.at<Vec3b>(nh, nw)[2];
}
}
}
原图:
当amplitude = 22,wavelength=30时的效果: