Inizio trasposizione linea verticale
This commit is contained in:
parent
4505d17871
commit
979d5a5a09
3 changed files with 30 additions and 5 deletions
|
@ -105,13 +105,17 @@ get_line(Point p, Point q)
|
||||||
bool
|
bool
|
||||||
is_in_line(cv::Vec<double,3> line, Point p)
|
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
|
bool
|
||||||
is_above_line(cv::Vec<double,3> line, Point p)
|
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
|
cv::Point
|
||||||
|
|
|
@ -11,6 +11,7 @@ cv::Point unmap_point(double, cv::Point, cv::Point);
|
||||||
cv::Vec<double,3> get_line(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_in_line(cv::Vec<double,3> line, cv::Point p);
|
||||||
bool is_above_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>);
|
cv::Point further_point_from_line(cv::Vec<double,3>, std::vector<cv::Point>);
|
||||||
|
|
||||||
class CoordinateSystem
|
class CoordinateSystem
|
||||||
|
|
26
lines.cpp
26
lines.cpp
|
@ -119,6 +119,8 @@ class BookShape {
|
||||||
double ysize();
|
double ysize();
|
||||||
cv::Mat* getTrasfs();
|
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)
|
BookShape::BookShape(cv::Point tl, cv::Point tm, cv::Point tr, cv::Point bl, cv::Point bm, cv::Point br)
|
||||||
{
|
{
|
||||||
trapezoids[0][0] = tl;
|
trapezoids[0][0] = tl;
|
||||||
|
@ -195,14 +197,32 @@ BookShape get_book_shape(cv::Mat img)
|
||||||
corn_3 = hull[maxdistances[1]];
|
corn_3 = hull[maxdistances[1]];
|
||||||
corn_4 = hull[(maxdistances[1]+1)%hull.size()];
|
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
|
// 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] << std::endl;
|
||||||
std::cout << maxdistances[1]+1 << std::endl;
|
std::cout << maxdistances[1]+1 << std::endl;
|
||||||
std::cout << (maxdistances[1]+1)%hull.size() << 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);
|
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
|
// theta is the angle of the line connecting point 1 and 2; it will be the
|
||||||
// rotation of our new coordinate system
|
// rotation of our new coordinate system
|
||||||
|
|
Loading…
Reference in a new issue