OpenCV_7漩涡

一,原图:

二,代码:

//7漩涡
template<typename T> T sqr(T x) { return x*x; }
double Pi = 3.14;
double Para = 8;

void Swirl()
{
	Mat src = imread("D:\\test\\26.png");
	int heigh = src.rows;
	int width = src.cols;
	Point center(width / 2, heigh / 2);
	Mat img;
	src.copyTo(img);
	Mat src1u[3];
	split(src, src1u);

	for (int y = 0; y<heigh; y++)
	{
		uchar* imgP = img.ptr<uchar>(y);
		uchar* srcP = src.ptr<uchar>(y);
		for (int x = 0; x<width; x++)
		{
			int R = norm(Point(x, y) - center);
			double angle = atan2((double)(y - center.y), (double)(x - center.x));
			double delta = Pi*Para / sqrtf(R + 1);
			int newX = R*cos(angle + delta) + center.x;
			int newY = R*sin(angle + delta) + center.y;

			if (newX<0) newX = 0;
			if (newX>width - 1) newX = width - 1;
			if (newY<0) newY = 0;
			if (newY>heigh - 1) newY = heigh - 1;

			imgP[3 * x] = src1u[0].at<uchar>(newY, newX);
			imgP[3 * x + 1] = src1u[1].at<uchar>(newY, newX);
			imgP[3 * x + 2] = src1u[2].at<uchar>(newY, newX);
		}
	}
	imshow("vortex", img);
	waitKey();
	imwrite("D:/img/漩涡.jpg", img);
}

//-----开始------
void COpenCVLearningDlg::OnBnClickedStartButton()
{
	Swirl();
}

三,结果:

 

欢迎扫码关注我的微信公众号

原文地址:https://blog.csdn.net/sangni007/column/info/stylizefliter

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值