dewarp prospective

This commit is contained in:
boyska 2017-01-15 01:07:03 +01:00
parent af800e3870
commit f44bc3bae9

View file

@ -121,9 +121,27 @@ int main(int argc, char *argv[])
}
}
#ifdef _DEBUG
cv::Point middle1 = further_point_from_line(get_line(corn_1, corn_2), points2);
cv::Point middle2 = further_point_from_line(get_line(corn_3, corn_4), points1);
// we now have all the points of the two trapezoid (middle1 and middle2 are shared)
cv::Mat trasf[2]; //transformation matrix
double xsize = dist(corn_1, middle1), ysize=dist(middle1, middle2);
cv::Point2f trapezoid[2][4] = {
{corn_1, middle1, middle2, corn_4},
{corn_2, corn_3, middle2, middle1}};
cv::Point2f outsizes[4] = {cv::Point2f(0, 0), cv::Point(xsize, 0),
cv::Point(xsize, ysize), cv::Point(0, ysize)};
cv::Mat rect[2]; //final pages, transformed in a nice rectangle
//we are rereading in full color to get colored output
img = cv::imread(args.input,CV_LOAD_IMAGE_COLOR);
for(int i=0; i < 2; i++) {
trasf[i] = cv::getPerspectiveTransform(trapezoid[i], outsizes);
cv::warpPerspective(img, rect[i], trasf[i], cv::Size(xsize, ysize));
}
#ifdef _DEBUG
cv::line(img, corn_1, middle1, MAGENTA, dotwidth>>3);
cv::line(img, corn_2, middle1, MAGENTA, dotwidth>>3);
cv::line(img, middle1, middle2, BLACK, dotwidth>>4);