-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopolar.cpp
64 lines (43 loc) · 1.42 KB
/
topolar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <cv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <cmath>
using namespace std;
using namespace cv;
#define pai 3.14159
int main()
{
Mat src = imread("/home/user/june/test/woman.png");
imshow("original",src);
int rows = src.rows;//行
int cols =src.cols;//列
cout<<"输入极坐标原点,用分数表示:"<<endl;
Point2f center(rows,cols);
cin>>center.x >>center.y;
center.x *= rows;
center.y *=cols;
float max1_cols = std::max(sqrt(center.x*center.x+center.y*center.y ), sqrt(center.x*center.x+(center.y-cols)*(center.y-cols) ) );
float max2_cols =std::max(sqrt((center.x-rows)*(center.x-rows)+center.y*center.y ) ,sqrt((center.x-rows)*(center.x-rows) +(center.y-cols)*(center.y-cols)));
float dest_cols = std::max(max1_cols+1,max2_cols+1 );
cout<<dest_cols<<endl;
//float max1_rows =
//float max2_rows =
Mat dest(360,dest_cols,CV_8UC3,Scalar(0,0,0));
for(int i=0;i<rows;i++)
for(int j=0;j<cols;j++)
{
int y = sqrt((i-center.x)*(i-center.x)+(j-center.y)*(j-center.y));
int x =(pai+atan2(j-center.y,i-center.x))/2.0/pai*360.0;//(arctan(static_cast<double>(j)/static_cast<double>(i)));
//cout<<"zuobiao"<<x<<" "<<y<<endl;
for(int k=0;k<3;k++)
dest.at<Vec3b>(x,y)[k] = src.at<Vec3b>(i,j)[k];
}
cout<<"wode"<<endl;
imshow("original",src);
imshow("topolar",dest);
waitKey(100000);
return 0;
}