From 979d5a5a099c7b5a794174fe9a7992382da0a19e Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 26 Jan 2017 00:02:56 +0100 Subject: [PATCH] Inizio trasposizione linea verticale --- geometry.cpp | 8 ++++++-- geometry.h | 1 + lines.cpp | 26 +++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/geometry.cpp b/geometry.cpp index 5373553..d429c6b 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -105,13 +105,17 @@ get_line(Point p, Point q) bool is_in_line(cv::Vec 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 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 line, Point p) +{ + return line(0)*p.x + line(1)*p.y + line(2); } cv::Point diff --git a/geometry.h b/geometry.h index 3fc079f..9227195 100644 --- a/geometry.h +++ b/geometry.h @@ -11,6 +11,7 @@ cv::Point unmap_point(double, cv::Point, cv::Point); cv::Vec get_line(cv::Point, cv::Point); bool is_in_line(cv::Vec line, cv::Point p); bool is_above_line(cv::Vec line, cv::Point p); +double line_value(cv::Vec, cv::Point); cv::Point further_point_from_line(cv::Vec, std::vector); class CoordinateSystem diff --git a/lines.cpp b/lines.cpp index a2136c4..e62c472 100644 --- a/lines.cpp +++ b/lines.cpp @@ -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 verticals[2]; + std::vector vertical_points[2]; + cv::Vec 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