引入二维空间(以下简称2D) 的射影变换

这些变换发生在用透视摄像机对平面摄像的时候.

该章偏重于入门介绍并为三维空间(以下简称3D) 几何铺路.

大多数的概念在2D 中比3D 中更容易理解和可视化.

本章介绍射影变换,包括它的特殊悄况:仿射和相似变换;

并把注意力主要集中在从透视图像中恢复仿射性质(例如平行钱)和度量性质(例如线之间的角度) .

[cpp] view plaincopy
  1. // mapcyl.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <opencv/cv.h>
  5. #include <opencv/highgui.h>
  6. cv::Point2f convert_pt(cv::Point2f point,int w,int h)
  7. {
  8. //center the point at 0,0
  9. cv::Point2f pc(point.x-w/2,point.y-h/2);
  10. //these are your free parameters
  11. //negative focal length since we are rear projecting
  12. float f = -w/2;
  13. float r = w;
  14. float omega = w/2;
  15. float z0 = f - sqrt(r*r-omega*omega);
  16. float zc = (2*z0+sqrt(4*z0*z0-4*(pc.x*pc.x/(f*f)+1)*(z0*z0-r*r)))/(2* (pc.x*pc.x/(f*f)+1));
  17. cv::Point2f final_point(pc.x*zc/f,pc.y*zc/f);
  18. final_point.x += w/2;
  19. final_point.y += h/2;
  20. return final_point;
  21. }
  22. int _tmain(int argc, _TCHAR* argv[])
  23. {
  24. cv::Mat imgMat = cv::imread("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE);
  25. cv::copyMakeBorder(imgMat, imgMat, 175, 175, 175, 175, cv::BORDER_CONSTANT);
  26. cv::namedWindow("Original",CV_WINDOW_AUTOSIZE);
  27. cv::imshow("Original", imgMat);
  28. cv::waitKey(0);
  29. cv::Mat destImgMat(imgMat.size(), CV_8U);
  30. for(int y = 0; y < imgMat.rows; y++)
  31. {
  32. for(int x = 0; x < imgMat.cols; x++)
  33. {
  34. cv::Point2f current_pos(x,y);
  35. current_pos = convert_pt(current_pos, imgMat.cols, imgMat.rows);
  36. cv::Point2i top_left((int)current_pos.x,(int)current_pos.y); //top left because of integer rounding
  37. //make sure the point is actually inside the original image
  38. if(top_left.x < 0 || top_left.x > imgMat.cols-2 || top_left.y < 0 || top_left.y > imgMat.rows-2)
  39. {
  40. continue;
  41. }
  42. //bilinear interpolation
  43. float dx = current_pos.x-top_left.x;
  44. float dy = current_pos.y-top_left.y;
  45. float weight_tl = (1.0 - dx) * (1.0 - dy);
  46. float weight_tr = (dx)       * (1.0 - dy);
  47. float weight_bl = (1.0 - dx) * (dy);
  48. float weight_br = (dx)       * (dy);
  49. uchar value = weight_tl * imgMat.at<uchar>(top_left) +
  50. weight_tr * imgMat.at<uchar>(top_left.y,top_left.x+1) +
  51. weight_bl * imgMat.at<uchar>(top_left.y+1,top_left.x) +
  52. weight_br * imgMat.at<uchar>(top_left.y+1,top_left.x+1);
  53. destImgMat.at<uchar>(y,x) = value;
  54. }
  55. }
  56. cv::namedWindow("Cylindrical",CV_WINDOW_AUTOSIZE);
  57. cv::imshow("Cylindrical",destImgMat);
  58. cv::waitKey(0);
  59. cv::imwrite( "cyl_lena.jpg", destImgMat );
  60. return 0;
  61. }

结果:

参考文献:

https://stackoverflow.com/questions/12017790/warp-image-to-appear-in-cylindrical-projection?lq=1

【Opencv】2D射影儿何和变换——柱面投影,图像拼接柱面投影相关推荐

  1. 2D射影儿何和变换——柱面投影,图像拼接柱面投影

    引入二维空间(以下简称2D) 的射影变换 这些变换发生在用透视摄像机对平面摄像的时候. 该章偏重于入门介绍并为三维空间(以下简称3D) 几何铺路. 大多数的概念在2D 中比3D 中更容易理解和可视化. ...

  2. matlab 柱面投影,图像拼接(不投影到柱面)(渐入渐出融合) matlab程序

    1,先拍摄一组图片,比如两幅图:A.B 我直接用网上的两幅图: 2,分别投影到柱面坐标系 就用自己写的柱面投影程序 matlab里 结果: 3,开始配准第一步:SIFT得到匹配对(直接用OpenCV里 ...

  3. OpenCV系列之霍夫线变换 | 三十二

    目标 在这一章当中, 我们将了解霍夫变换的概念. 我们将看到如何使用它来检测图像中的线条. 我们将看到以下函数:cv.HoughLines(),cv.HoughLinesP() 理论 如果可以用数学形 ...

  4. OpenCV中的霍夫线变换、概率霍夫线变换

    OpenCV中的霍夫线变换.概率霍夫线变换 1. 效果图 2. 原理 2.1 什么是霍夫变换? 2.2 什么是概率霍夫变换? 3. 源码 3.1 霍夫变换 3.2 概率霍夫变换 参考 这篇博客将介绍P ...

  5. OpenCV中的尺度不变特征变换(SIFT Scale-Invariant Feature Transform)

    OpenCV中的尺度不变特征变换(SIFT Scale-Invariant Feature Transform) 1. 效果图 2. 原理 2.1 步骤 2.2 opencv实现方法 2.3 SIFT ...

  6. opencv 2d人脸姿态计算

    opencv 2d人脸姿态计算 可以的: # -*- coding: utf-8 -*- # 测试使用opencv中的函数solvepnp import cv2 import numpy as np ...

  7. OpenCV霍夫变换:霍夫线变换,霍夫圆变换合辑

    本篇文章中,我们一起探讨了OpenCV中霍夫变换相关的知识点,以及了解了OpenCV中实现霍夫线变换的HoughLines.HoughLinesP函数的使用方法,实现霍夫圆变换的HoughCircle ...

  8. Python+opencv 机器视觉 - 基于霍夫圈变换算法检测图像中的圆形实例演示

    Python+opencv 机器视觉 - 基于霍夫圈变换算法检测图像中的圆形实例演示 第一章:霍夫变换检测圆 ① 实例演示1 ② 实例演示2 ③ 霍夫变换函数解析 第二章:Python + openc ...

  9. OpenCV使用Laplacian filtering和距离变换以及Laplacian滤波对重叠对象进行分段的实例(附完整代码)

    OpenCV使用Laplacian filtering和距离变换以及Laplacian滤波对重叠对象进行分段的实例 OpenCV使用Laplacian filtering和距离变换以及Laplacia ...

最新文章

  1. 2022-2028年中国蛋白石行业发展现状分析及投资前景趋势报告
  2. 网页中插入VLC播放器播放rtsp视频流步骤
  3. __cplusplus的用处
  4. 交通安全与智能控制专业学计算机吗,交通安全与智能控制专业就业方向及就业前景分析...
  5. spring的aop的动态代理机制都有哪些_Spring学习(4):Spring AOP
  6. php订单系统 帝国cms,帝国CMS商城系统在线支付后,订单邮件提醒
  7. struts2的select标签的用法
  8. Java多线程4:synchronized锁机制
  9. MongoDB 权限认证
  10. 数据库零碎---mysql编码设置,与乱码分析
  11. 2021-02-28 配置Jetty+GeoServer-2.18.2允许CORS跨域访问 - 草稿
  12. 涉嫌抄袭!致歉,抖音Semi Design承认参考阿里Ant Design
  13. Mybatis3全面详解
  14. paddlehub 使用体验-视频抠图_乘风破浪的姐姐_人美路子野 2020-08-13
  15. ubuntu16.04安装google拼音输入法
  16. 基于MTCNN+arcface的人脸检测和人脸识别
  17. unity3d射击类demo
  18. Python--变量
  19. Ping不通的原因分析
  20. nginx作为web服务应用

热门文章

  1. 数值分析多种算法C语言代码-推荐
  2. Linux CentOS 中安装 Redis(五)
  3. 计算机速成课 第二十四集 冷战和消费主义
  4. 【Python】利用tkinter开发测手速小游戏
  5. DNS域名解析服务详解
  6. crtsiii型无砟轨道板_北京雄安城际全线轨道贯通:全程设5座车站,1小时通勤,“刷脸”进站...
  7. 地球同步轨道、太阳同步轨道知识
  8. 1.MySQL 常用语句
  9. H2.64和H2.65编码区别
  10. 腾讯云(云镜)主机入侵检测漏洞检测