当前位置: 首页 > article >正文

Opencv 极坐标变换

变换后图片

代码


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

using namespace cv;


inline float distanceEuclidean(int r, int c, const Point2d& point)
{
	return sqrtf(powf(point.x - c, 2) + powf(point.y - r, 2));
}

void magtitue_point(Size matSize, Point2d point)
{
	Mat mag(matSize, CV_32FC1);

	for (int r = 0; r < matSize.height; r++)
	{
		float* pRow = (float*)mag.data + r * matSize.width;
		for (int c = 0; c < matSize.width; c++)
		{
			float* pCur = pRow + c;
			*pCur = distanceEuclidean(r, c, point);
		}
	}	
}

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;
}


http://www.kler.cn/a/149554.html

相关文章:

  • RHCE的学习(16)(shell脚本编程)
  • 图论基本术语
  • 设备接入到NVR管理平台EasyNVR多品牌NVR管理工具/设备的音视频配置参考
  • WorkFlow源码剖析——Communicator之TCPServer(下)
  • 《重学Java设计模式》之 原型模式
  • 【Pikachu】越权访问实战
  • YoloV8改进策略:基于RevCol,可逆的柱状神经网络的完美迁移,YoloV8的上分利器
  • 银河麒麟V10-ARM架构-postgresql安装与部署指南
  • 133. 面试官:JSBridge是什么?
  • Java面试题(每天10题)-------连载(39)
  • 【理解ARM架构】异常处理
  • 人工智能-优化算法之梯度下降
  • RLHF:强化学习结合大预言模型的训练方式
  • 在Mysql中,什么是回表,什么是覆盖索引,索引下推?
  • Qt 软件调试(一) Log日志调试
  • MapReduce概念
  • 简化文件上传流程:学习如何封装Vue2拖拽上传组件
  • 4.ORB-SLAM3中如何实现稠密建图(二):稠密建图如何控制三大线程与稠密建图代码解析
  • 额,收到阿里云给的赔偿了!
  • OpenCV | 傅里叶变换——低通滤波器与高通滤波器
  • 西南科技大学C++程序设计实验二(类与对象一)
  • 做到这一点,运维可高枕无忧
  • 读天下杂志读天下杂志社读天下编辑部简介
  • 王者荣耀游戏制作
  • 从零构建属于自己的GPT系列2:预训练中文模型加载、中文语言模型训练、逐行代码解读
  • During handling of the above exception, another exception occurred解决方案