Opencv 极坐标变换

变换后图片

代码

// 以Center为极坐标原点,将RowFrom到RowTo的圆环,仅仅变换该范围内的点,忽略掉其他部分。


#include "polar_transeforme.hpp"
#include <string>

using namespace cv;



void calculate_map(int rouFrom, int rouTo, Point2d center, Mat& map)
{
	int heightDst = map.size().height;
	int widthDst = map.size().width;

	float dTheta = 2 * PAI / heightDst;

	for (int r = 0; r < heightDst; r++)
	{
		float* pRow = (float*)map.data + r * 2 * widthDst;
		float curTheta = r * dTheta;
		float cosTheta = cos(curTheta);
		float sinTheta = sin(curTheta);
		for (int c = 0; c < widthDst; c++)
		{
			float* pCur = pRow + c * 2;
			int rou = c + rouFrom;
			*pCur = rou * cosTheta + center.x;
			pCur++;
			*pCur = center.y - rou * sinTheta;
		}
	}
}


Mat polar_transeforme(Mat& oriImage, int rouFrom, int rouTo, Point2d center)
{
	int heightDst = 2 * PAI * rouFrom;
	int widthDst = rouTo - rouFrom;
	Mat map(Size(widthDst, heightDst), CV_32FC2);
	calculate_map(rouFrom, rouTo, center, map);

	Mat dstMat;
	remap(oriImage, dstMat, map, Mat(), INTER_CUBIC, 0);
	return dstMat;
}

Point2d polar2Origin(Point2d p, Point2d center, int rouFrom, float dTheta)
{
	float theta = p.y / rouFrom;
	float rou = p.x;
	float tempX = center.x + rou * sin(theta);
	float tempY = center.y - rou * cos(theta);
	return Point2d(tempX, tempY);
}


int main()
{
	const std::string strImagePath = "示例图片.jpg";
	Mat oriImg = imread(strImagePath, IMREAD_GRAYSCALE);
	Point2d center(237, 237);
	int rouFrom = 110;
	int rouTo = 230;
	
	Mat polarImg = polar_transeforme(oriImg, rouFrom, rouTo, center);

	int test = 0;
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值