ready to change coordinates
This commit is contained in:
parent
1ac56e85eb
commit
2f5f45fcad
1 changed files with 42 additions and 8 deletions
50
lines.cpp
50
lines.cpp
|
@ -164,6 +164,29 @@ find_longest_line(std::vector<cv::Point> hull, unsigned begin, unsigned end) //t
|
|||
return bestline;
|
||||
}
|
||||
|
||||
cv::Point
|
||||
map_point(double theta, cv::Point origin, cv::Point tomap)
|
||||
{
|
||||
//that's the algorithm: res = Rt*(tomap - origin)
|
||||
cv::Vec<double,2> p_as_vector;
|
||||
cv::Point p;
|
||||
cv::Point res;
|
||||
cv::Matx<double,2,2> Rt;
|
||||
|
||||
p = tomap - origin;
|
||||
p_as_vector[0] = p.x;
|
||||
p_as_vector[1] = p.y;
|
||||
//TODO: fai matrice
|
||||
Rt(0,0) = cos(theta);
|
||||
Rt(0,1) = sin(theta);
|
||||
Rt(1,1) = Rt(0,0);
|
||||
Rt(1,0) = -Rt(0,1);
|
||||
cv::Vec<double,2> res_as_vector = Rt*p_as_vector;
|
||||
res.x = res_as_vector[0];
|
||||
res.y = res_as_vector[1];
|
||||
return res;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char const *fname = "files/masckera.png";
|
||||
|
@ -208,15 +231,20 @@ int main(int argc, char *argv[])
|
|||
|
||||
//these are the "horizontal" lines
|
||||
int *maxdistances = max2_distance(hull);
|
||||
cv::Point corn_1, corn_2, corn_3, corn_4;
|
||||
corn_1 = hull[maxdistances[0]];
|
||||
corn_2 = hull[(maxdistances[0]+1)%hull.size()];
|
||||
corn_3 = hull[maxdistances[1]];
|
||||
corn_4 = hull[(maxdistances[1]+1)%hull.size()];
|
||||
|
||||
#ifdef _DEBUG
|
||||
//img = cv::imread(fname,CV_LOAD_IMAGE_COLOR); // uncomment to this to display image with colors
|
||||
std::cout << "Maxdist1:" << maxdistances[0] << " " << hull[maxdistances[0]] << hull[(maxdistances[0]+1)%hull.size()] << std::endl;
|
||||
std::cout << "Maxdist2:" << maxdistances[1] << " " << hull[maxdistances[1]] << hull[(maxdistances[1]+1)%hull.size()] << std::endl;
|
||||
cv::circle(img,hull[maxdistances[0]],dotwidth>>2,BROWN,2);
|
||||
cv::circle(img,hull[(maxdistances[0]+1)%hull.size()],dotwidth>>2,BROWN,2);
|
||||
cv::circle(img,hull[maxdistances[1]],dotwidth>>2,BROWN,2);
|
||||
cv::circle(img,hull[(maxdistances[1]+1)%hull.size()],dotwidth>>2,BROWN,2);
|
||||
img = cv::imread(fname,CV_LOAD_IMAGE_COLOR); // uncomment to this to display image with colors
|
||||
std::cout << "Maxdist1:" << maxdistances[0] << " " << corn_1 << corn_2 << std::endl;
|
||||
std::cout << "Maxdist2:" << maxdistances[1] << " " << corn_3 << corn_4 << std::endl;
|
||||
cv::circle(img,corn_1,dotwidth>>1,MAGENTA,2);
|
||||
cv::circle(img,corn_2,dotwidth>>2,MAGENTA,2);
|
||||
cv::circle(img,corn_3,dotwidth>>2,BROWN,2);
|
||||
cv::circle(img,corn_4,dotwidth>>2,BROWN,2);
|
||||
cv::namedWindow("win", CV_GUI_NORMAL);
|
||||
// cv::imshow("4 corners",img);
|
||||
// cv::waitKey(0);
|
||||
|
@ -249,7 +277,13 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
// theta is the angle of the line connecting point 1 and 2; it will be the
|
||||
// rotation of our new coordinate system
|
||||
double theta = atan(((double)corn_1.y - corn_2.y)/(corn_1.x - corn_2.x));
|
||||
std::cout << "Theta = " << theta << std::endl;
|
||||
assert(map_point(theta, corn_1, corn_1).x == 0);
|
||||
assert(map_point(theta, corn_1, corn_1).y == 0);
|
||||
assert(map_point(theta, corn_1, corn_2).y == 0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue