Hello, I want to undistord the image just using perspective transformation. Here is the image I use.
Here is the code I use:
Mat input, output;
input = cv::imread("1_1gVwxOmy8aEZr6duMTmHuA.png");
std::vector<Point2f> image_points;
image_points.push_back(Point2f(434, 291));
image_points.push_back(Point2f(476, 278));
image_points.push_back(Point2f(527, 257));
image_points.push_back(Point2f(592, 240));
image_points.push_back(Point2f(656, 225));
image_points.push_back(Point2f(730, 218));
image_points.push_back(Point2f(808, 215));
image_points.push_back(Point2f(884, 222));
image_points.push_back(Point2f(954, 229));
image_points.push_back(Point2f(421, 343));
image_points.push_back(Point2f(462, 326));
image_points.push_back(Point2f(514, 310));
image_points.push_back(Point2f(575, 291));
image_points.push_back(Point2f(647, 282));
image_points.push_back(Point2f(727, 271));
image_points.push_back(Point2f(811, 269));
image_points.push_back(Point2f(893, 278));
image_points.push_back(Point2f(965, 282));
image_points.push_back(Point2f(404, 400));
image_points.push_back(Point2f(445, 387));
image_points.push_back(Point2f(498, 373));
image_points.push_back(Point2f(565, 360));
image_points.push_back(Point2f(641, 345));
image_points.push_back(Point2f(725, 342));
image_points.push_back(Point2f(813, 337));
image_points.push_back(Point2f(900, 341));
image_points.push_back(Point2f(977, 349));
image_points.push_back(Point2f(394, 467));
image_points.push_back(Point2f(436, 454));
image_points.push_back(Point2f(490, 447));
image_points.push_back(Point2f(556, 436));
image_points.push_back(Point2f(634, 429));
image_points.push_back(Point2f(722, 423));
image_points.push_back(Point2f(817, 420));
image_points.push_back(Point2f(905, 424));
image_points.push_back(Point2f(987, 428));
image_points.push_back(Point2f(390, 533));
image_points.push_back(Point2f(432, 530));
image_points.push_back(Point2f(483, 523));
image_points.push_back(Point2f(550, 522));
image_points.push_back(Point2f(629, 516));
image_points.push_back(Point2f(721, 513));
image_points.push_back(Point2f(819, 515));
image_points.push_back(Point2f(909, 512));
image_points.push_back(Point2f(991, 513));
image_points.push_back(Point2f(394, 602));
image_points.push_back(Point2f(433, 607));
image_points.push_back(Point2f(487, 606));
image_points.push_back(Point2f(552, 609));
image_points.push_back(Point2f(633, 608));
image_points.push_back(Point2f(724, 610));
image_points.push_back(Point2f(818, 605));
image_points.push_back(Point2f(909, 604));
image_points.push_back(Point2f(992, 600));
std::vector<Point2f> output_points;
output_points.push_back(Point2f(0, 0));
output_points.push_back(Point2f(0, 10));
output_points.push_back(Point2f(0, 20));
output_points.push_back(Point2f(0, 30));
output_points.push_back(Point2f(0, 40));
output_points.push_back(Point2f(0, 50));
output_points.push_back(Point2f(0, 60));
output_points.push_back(Point2f(0, 70));
output_points.push_back(Point2f(0, 80));
output_points.push_back(Point2f(10, 0));
output_points.push_back(Point2f(10, 10));
output_points.push_back(Point2f(10, 20));
output_points.push_back(Point2f(10, 30));
output_points.push_back(Point2f(10, 40));
output_points.push_back(Point2f(10, 50));
output_points.push_back(Point2f(10, 60));
output_points.push_back(Point2f(10, 70));
output_points.push_back(Point2f(10, 80));
output_points.push_back(Point2f(20, 0));
output_points.push_back(Point2f(20, 10));
output_points.push_back(Point2f(20, 20));
output_points.push_back(Point2f(20, 30));
output_points.push_back(Point2f(20, 40));
output_points.push_back(Point2f(20, 50));
output_points.push_back(Point2f(20, 60));
output_points.push_back(Point2f(20, 70));
output_points.push_back(Point2f(20, 80));
output_points.push_back(Point2f(30, 0));
output_points.push_back(Point2f(30, 10));
output_points.push_back(Point2f(30, 20));
output_points.push_back(Point2f(30, 30));
output_points.push_back(Point2f(30, 40));
output_points.push_back(Point2f(30, 50));
output_points.push_back(Point2f(30, 60));
output_points.push_back(Point2f(30, 70));
output_points.push_back(Point2f(30, 80));
output_points.push_back(Point2f(40, 0));
output_points.push_back(Point2f(40, 10));
output_points.push_back(Point2f(40, 20));
output_points.push_back(Point2f(40, 30));
output_points.push_back(Point2f(40, 40));
output_points.push_back(Point2f(40, 50));
output_points.push_back(Point2f(40, 60));
output_points.push_back(Point2f(40, 70));
output_points.push_back(Point2f(40, 80));
output_points.push_back(Point2f(50, 0));
output_points.push_back(Point2f(50, 10));
output_points.push_back(Point2f(50, 20));
output_points.push_back(Point2f(50, 30));
output_points.push_back(Point2f(50, 40));
output_points.push_back(Point2f(50, 50));
output_points.push_back(Point2f(50, 60));
output_points.push_back(Point2f(50, 70));
output_points.push_back(Point2f(50, 80));
for (auto point : image_points) {
cv::imshow("input image ", input);
cv::circle(input, point, 5, cv::Scalar(155, 0, 0), 3);
std::cout << point << std::endl;
}
std::cout << image_points.size() << std::endl;
std::cout << output_points.size() << std::endl;
Mat lambda(3, 3, CV_32FC1);
// Get the Perspective Transform Matrix i.e. lambda
cv::perspectiveTransform( output_points, image_points, lambda);
std::cout << lambda << std::endl;
std::cout << lambda.inv() << std::endl;
// Apply the Perspective Transform just found to the src image
warpPerspective(input, output, lambda, input.size());
cv::imshow("output image ", output);
cv::waitKey(-1);
I get a perspective matrix like this:
H = [0, 0, 0; 1.875, 0, 0; 0, 0, 0]
I don't understand if the problem comes from the method ( we can use perspective method to undistord that image) or if there is a problem on my code.