cartToPolar
#include<opencv2/opencv.hpp>
#include<iostream>
#include <vector>
int main(int argc, char** argv) {
std::vector<cv::Point2f> sides;//建立容器存坐标
sides.push_back(cv::Point2f(3, 4));
sides.push_back(cv::Point2f(6, 8));
sides.push_back(cv::Point2f(1, 1));
cv::Mat xpts(sides.size(), 1, CV_32FC1);
xpts.at<float>(0, 0) = sides[0].x;
xpts.at<float>(1, 0) = sides[1].x;
xpts.at<float>(2, 0) = sides[2].x;
cv::Mat ypts(sides.size(), 1, CV_32F);
ypts.at<float>(0, 0) = sides[0].y;
ypts.at<float>(1, 0) = sides[1].y;
ypts.at<float>(2, 0) = sides[2].y;
std::cerr << xpts << std::endl;
std::cerr << ypts << std::endl;
cv::Mat magnitude, angle;
cartToPolar(xpts, ypts, magnitude, angle);//笛卡尔坐标转极坐标
/*
参数1:x坐标矩阵 n行1列
参数2:y坐标矩阵 n行1列
参数3:极径矩阵
参数4:极角矩阵 根据atan2(y, x) 算出来的 单位:弧度
*/
std::cerr << magnitude << std::endl;
std::cerr << angle << std::endl;
std::cerr << atan2(1, 1)<<std::endl;;
cv::waitKey(0);
return 0;
}