Melaksanakan cv::warpPerspective untuk Deskewing Palsu pada Set cv::Point
Soalan: Bagaimana adakah saya mencapai kesan deskewing pada set mata menggunakan cv::warpPerspective? Mata tidak dalam susunan tertentu dan disimpan dalam vektor.
Memahami Isu:
Langkah-Langkah untuk Menyusun Palsu:
Contoh Kod:
#include <opencv2/opencv.hpp> int main() { // Input image Mat src = imread("input.jpg"); // Input points (not in particular order) vector<Point> points = { Point(408, 69), // Top-left Point(72, 2186), // Bottom-left Point(1584, 2426), // Bottom-right Point(1912, 291), // Top-right }; // Rotated rectangle (bounding box) RotatedRect boundingRect = minAreaRect(Mat(points)); // Corrected point ordering Point2f vertices[3]; vertices[0] = boundingRect.center + boundingRect.size * 0.5f; // Top-left vertices[1] = boundingRect.center + boundingRect.size * 0.5f; // Bottom-left vertices[1].y += boundingRect.size.height; vertices[2] = boundingRect.center - boundingRect.size * 0.5f; // Bottom-right // Output point ordering Point2f outputVertices[3]; outputVertices[0] = Point(0, 0); // Top-left outputVertices[1].x = outputVertices[0].x + boundingRect.size.width; // Bottom-left outputVertices[1].y = outputVertices[1].x; outputVertices[2] = outputVertices[0]; // Bottom-right // Affine transformation matrix Mat transformationMatrix = getAffineTransform(vertices, outputVertices); // Deskewed image with corrected size Mat deskewedImage; Size outputSize(boundingRect.size.width, boundingRect.size.height); warpAffine(src, deskewedImage, transformationMatrix, outputSize, INTER_LINEAR); // Save deskewed image imwrite("deskewed.jpg", deskewedImage); }
Atas ialah kandungan terperinci Bagaimana untuk Mengeluarkan Set Mata Menggunakan cv::warpPerspective?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!