Opencv 极坐标变换

变换后图片

代码

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

cpp 复制代码
#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;
}
相关推荐
冬奇Lab5 小时前
Workflow 系列(04):Multi-Agent 协调——编排器边界、并发控制与上下文隔离
人工智能·工作流引擎
冬奇Lab5 小时前
每日一个开源项目(第147篇):HyperGraphRAG - 用超图表示 N 元关系,RAG 的第三代范式
人工智能·开源·graphql
甲维斯5 小时前
Github + 阿里云oss实现类似codex的自动更新!
人工智能
阿里云大数据AI技术7 小时前
光轮智能 × 阿里云:共建 Physical AI 云上数据、评测与持续学习基础设施
人工智能·机器学习
机器之心7 小时前
实锤了:Claude Code偷查用户,时区、中国AI实验室全是关键词
人工智能·openai
网易云信7 小时前
Cursor点燃个人开发者,企业级AI为何频频受挫?Agent工厂从提效工具到AI员工的跃迁
人工智能·开源
网易云信7 小时前
解锁触手可及的温暖:网易智企 x Wander Puffs AI 云游泡芙
人工智能
转转技术团队7 小时前
从 PRD 到可验证代码:AI 需求开发闭环实践
人工智能