Inizio trasposizione linea verticale

This commit is contained in:
boyska 2017-01-26 00:02:56 +01:00 committed by avana
parent 4505d17871
commit 979d5a5a09
3 changed files with 30 additions and 5 deletions

View file

@ -105,13 +105,17 @@ get_line(Point p, Point q)
bool
is_in_line(cv::Vec<double,3> line, Point p)
{
return line(0)*p.x + line(1)*p.y + line(2) == 0;
return line_value(line, p) == 0;
}
bool
is_above_line(cv::Vec<double,3> line, Point p)
{
return line(0)*p.x + line(1)*p.y + line(2) > 0;
return line_value(line, p) > 0;
}
double line_value(cv::Vec<double,3> line, Point p)
{
return line(0)*p.x + line(1)*p.y + line(2);
}
cv::Point

View file

@ -11,6 +11,7 @@ cv::Point unmap_point(double, cv::Point, cv::Point);
cv::Vec<double,3> get_line(cv::Point, cv::Point);
bool is_in_line(cv::Vec<double,3> line, cv::Point p);
bool is_above_line(cv::Vec<double,3> line, cv::Point p);
double line_value(cv::Vec<double,3>, cv::Point);
cv::Point further_point_from_line(cv::Vec<double,3>, std::vector<cv::Point>);
class CoordinateSystem

View file

@ -119,6 +119,8 @@ class BookShape {
double ysize();
cv::Mat* getTrasfs();
};
//topleft topmiddle topright
//botleft botmiddle botright
BookShape::BookShape(cv::Point tl, cv::Point tm, cv::Point tr, cv::Point bl, cv::Point bm, cv::Point br)
{
trapezoids[0][0] = tl;
@ -195,14 +197,32 @@ BookShape get_book_shape(cv::Mat img)
corn_3 = hull[maxdistances[1]];
corn_4 = hull[(maxdistances[1]+1)%hull.size()];
std::vector<cv::Point> verticals[2];
std::vector<cv::Point> vertical_points[2];
cv::Vec<double,3> verticals[2];
// Between the two corners on the same side, the longest line is the vertical border of the book
verticals[0] = find_longest_line(hull, (maxdistances[0]+1)%hull.size(), maxdistances[1]);
vertical_points[0] = find_longest_line(hull, (maxdistances[0]+1)%hull.size(), maxdistances[1]);
std::cout << maxdistances[1] << std::endl;
std::cout << maxdistances[1]+1 << std::endl;
std::cout << (maxdistances[1]+1)%hull.size() << std::endl;
verticals[1] = find_longest_line(hull, (maxdistances[1]+1)%hull.size(), maxdistances[0]);
vertical_points[1] = find_longest_line(hull, (maxdistances[1]+1)%hull.size(), maxdistances[0]);
free(maxdistances);
#ifdef _DEBUG
img = cv::imread("files/masckera.png", CV_LOAD_IMAGE_COLOR);
cv::circle(img, vertical_points[0][0], img.cols>>7, cv::Scalar(200, 0, 0), -1);
cv::circle(img, vertical_points[0][vertical_points[0].size()-1], img.cols>>7, cv::Scalar(200, 0, 0), -1);
cv::circle(img, vertical_points[1][0], img.cols>>7, cv::Scalar(200, 200, 0), -1);
cv::circle(img, vertical_points[1][vertical_points[1].size()-1], img.cols>>7, cv::Scalar(200, 0, 0), -1);
cv::circle(img, corn_1, img.cols>>7, cv::Scalar(200, 0, 200), -1);
cv::namedWindow("aaa", CV_GUI_NORMAL);
cv::imshow("aaa", img);
cv::waitKey(0);
#endif
verticals[0] = get_line(vertical_points[0][0], vertical_points[0][vertical_points[0].size()-1]);
std::cout << verticals[0] << std::endl;
std::cout << line_value(verticals[0], corn_1) << std::endl;
verticals[0][2] -= line_value(verticals[0], corn_1);
std::cout << line_value(verticals[0], corn_1) << "=0?" << std::endl;
verticals[1] = get_line(vertical_points[1][0], vertical_points[1][vertical_points[1].size()-1]);
// theta is the angle of the line connecting point 1 and 2; it will be the
// rotation of our new coordinate system