源码:
void wave_sawtooth(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;
int xWavelength = wavelength;
int yWavelength = wavelength;
for (int h = 0; h < dst.rows; h ++) {
double fh = 1.0 * (h % yWavelength) / yWavelength;
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 = 1.0 * (w % xWavelength) / xWavelength;
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=50,wavelength = 50时的效果: