• Opencv 极坐标变换


    变换后图片

    代码

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

    1. #include "polar_transeforme.hpp"
    2. #include
    3. using namespace cv;
    4. void calculate_map(int rouFrom, int rouTo, Point2d center, Mat& map)
    5. {
    6. int heightDst = map.size().height;
    7. int widthDst = map.size().width;
    8. float dTheta = 2 * PAI / heightDst;
    9. for (int r = 0; r < heightDst; r++)
    10. {
    11. float* pRow = (float*)map.data + r * 2 * widthDst;
    12. float curTheta = r * dTheta;
    13. float cosTheta = cos(curTheta);
    14. float sinTheta = sin(curTheta);
    15. for (int c = 0; c < widthDst; c++)
    16. {
    17. float* pCur = pRow + c * 2;
    18. int rou = c + rouFrom;
    19. *pCur = rou * cosTheta + center.x;
    20. pCur++;
    21. *pCur = center.y - rou * sinTheta;
    22. }
    23. }
    24. }
    25. Mat polar_transeforme(Mat& oriImage, int rouFrom, int rouTo, Point2d center)
    26. {
    27. int heightDst = 2 * PAI * rouFrom;
    28. int widthDst = rouTo - rouFrom;
    29. Mat map(Size(widthDst, heightDst), CV_32FC2);
    30. calculate_map(rouFrom, rouTo, center, map);
    31. Mat dstMat;
    32. remap(oriImage, dstMat, map, Mat(), INTER_CUBIC, 0);
    33. return dstMat;
    34. }
    35. Point2d polar2Origin(Point2d p, Point2d center, int rouFrom, float dTheta)
    36. {
    37. float theta = p.y / rouFrom;
    38. float rou = p.x;
    39. float tempX = center.x + rou * sin(theta);
    40. float tempY = center.y - rou * cos(theta);
    41. return Point2d(tempX, tempY);
    42. }
    43. int main()
    44. {
    45. const std::string strImagePath = "示例图片.jpg";
    46. Mat oriImg = imread(strImagePath, IMREAD_GRAYSCALE);
    47. Point2d center(237, 237);
    48. int rouFrom = 110;
    49. int rouTo = 230;
    50. Mat polarImg = polar_transeforme(oriImg, rouFrom, rouTo, center);
    51. int test = 0;
    52. return 0;
    53. }

  • 相关阅读:
    C# Onnx Yolov8 Detect 戴安全帽检测
    【第五章】Linux 的文件权限与目录配置
    Python:为何成为当下最热门的编程语言?
    公共关系学试题与参考答案
    EasyOCR 识别模型训练
    Netlogo 简化版Scatter 分散
    Linux 时间操作及其同步
    半解析快速傅里叶变换
    RDB、AOF 阻塞操作?
    20230919后台面经整理
  • 原文地址:https://blog.csdn.net/lipeng19930407/article/details/134690200