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

OPENCV 基于旋转矩阵 旋转Point2f

测试效果

创建两个点,让第二个点绕第一个点转45度

代码解析

Mat a; a = imread("D:\\0.bmp", -1);

读取一张图片当作背景板

Point2f p1(350, 150); Point2f p2(550.0f, 150.0f);

创建两个点

cv::Mat mat = getRotationMatrix2D(p1, 45, 1.0);

生成旋转矩阵,中心点为p1

std::vector<cv::Point2f> points = { p2 }; cv::Mat srcPoint(points);

将p2的数据放进一个mat对象中

cv::Mat dstPoint; // 应用变换 cv::transform(srcPoint, dstPoint, mat);

创建结果Mat 执行矩阵变换

float x = dstPoint.at<float>(0, 0); float y = dstPoint.at<float>(0, 1); cv::Point2f rotatedPoint(x, y);

输出结果也是一个Mat对象 从这个Mat对象中取出仿射变换之后的点坐标数据

std::cout << "Rotated Point: " << rotatedPoint << std::endl; circle(mergedImage, p1, 3, Scalar(0, 255, 0), 3, LINE_AA); circle(mergedImage, p2, 3, Scalar(0, 255, 0), 3, LINE_AA); circle(mergedImage, rotatedPoint, 3, Scalar(0, 0, 255), 3, LINE_AA); line(mergedImage,p1,p2, Scalar(0, 255, 255),2,LINE_AA); line(mergedImage, p1, rotatedPoint, Scalar(0, 0, 255), 2, LINE_AA);

三个点坐标数据,绘制到图像上,以便确认执行正确。

原始代码

    Mat a;a = imread("D:\\0.bmp", -1);cv::Mat mergedImage;std::vector<cv::Mat> channels = { a, a, a };cv::merge(channels, mergedImage);Point2f p1(350, 150);Point2f p2(550.0f, 150.0f);cv::Mat mat = getRotationMatrix2D(p1, 45, 1.0);std::vector<cv::Point2f> points = { p2 };cv::Mat srcPoint(points);cv::Mat dstPoint;// 应用变换cv::transform(srcPoint, dstPoint, mat);// 提取结果float x = dstPoint.at<float>(0, 0);float y = dstPoint.at<float>(0, 1);cv::Point2f rotatedPoint(x, y);std::cout << "Rotated Point: " << rotatedPoint << std::endl;circle(mergedImage, p1, 3, Scalar(0, 255, 0), 3, LINE_AA);circle(mergedImage, p2, 3, Scalar(0, 255, 0), 3, LINE_AA);circle(mergedImage, rotatedPoint, 3, Scalar(0, 0, 255), 3, LINE_AA);line(mergedImage,p1,p2, Scalar(0, 255, 255),2,LINE_AA);line(mergedImage, p1, rotatedPoint, Scalar(0, 0, 255), 2, LINE_AA);imshow("1", mergedImage);waitKey();

http://www.xdnf.cn/news/1420939.html

相关文章:

  • Python核心技术开发指南(030)——函数入门
  • PAT乙级_1093 字符串A+B_Python_AC解法_含疑难点
  • 基于 C 语言的网络单词查询系统设计与实现(客户端 + 服务器端)
  • Python OpenCV图像处理与深度学习:Python OpenCV特征检测入门
  • AI时代SEO关键词实战解析
  • Python3环境搭建教程 - 使用Conda工具
  • CGroup 资源控制组 + Docker 网络模式
  • 【并发场景问题】超卖、一人一单业务问题的解决方案
  • 大型语言模型监督微调(SFT)
  • openharmony之sandbox沙箱机制详解
  • K8S网络组件Calico深度解析
  • Python OpenCV图像处理与深度学习:Python OpenCV图像几何变换入门
  • 深入解析 Go 程序逆向风险与防护策略
  • 如何对嵌入式软件进行单元测试
  • 无重复字符的最长子串,leetCode热题100,C++实现
  • Vue3响应式陷阱:如何避免ref解构导致的响应式丢失
  • 电动自行车车架前叉振动、组合件冲击、把立管弯曲强度试验机等机械强度性能测试项目解析
  • 【趣味阅读】Python 文件头的秘密:从编码声明到 Shebang
  • Spring事务管理策略对比与性能优化实践指南
  • AI辅助论文写作,在《人工智能生成合成内容标识办法》出台后的新规则
  • HarmonyOS 应用开发深度实践:深入 Stage 模型与 ArkTS 声明式 UI
  • Linux - JDK安装
  • 刷题之链表oj题目
  • 突破超强回归模型,高斯过程回归!
  • 大语言模型对齐
  • VMware pro16(许可证)+centos 7超详细安装教程
  • MQ使用场景分析
  • 【RK3576】【Android14】PMIC电源管理
  • DVWA靶场通关笔记-SQL Injection Blind(SQL盲注 Impossible级别)
  • kubectl-etcd