From 37c963ee52e7838cc8d2d0e8be5485d0d33375ec Mon Sep 17 00:00:00 2001 From: USW Date: Wed, 9 Apr 2025 12:14:01 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=ED=94=BD=EC=8A=A4?= =?UTF-8?q?=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Homework/perspective/main.cpp | 44 +++++++++++++++++-- Homework/perspective/perspective.vcxproj | 3 ++ .../perspective/perspective.vcxproj.filters | 5 +++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/Homework/perspective/main.cpp b/Homework/perspective/main.cpp index bec8593..f5551ab 100644 --- a/Homework/perspective/main.cpp +++ b/Homework/perspective/main.cpp @@ -1,11 +1,49 @@ #include -#include -#include -#include #include "opencv2/opencv.hpp" using namespace std; using namespace cv; +Mat src; +Point2f srcQuad[4], dstQuad[4]; + +void on_mouse(int event, int x, int y, int flags, void* userdata); + int main() { + Mat src = imread("../../resources/images/card.bmp"); + + namedWindow("src"); + setMouseCallback("src", on_mouse); + + imshow("src", src); + waitKey(0); + + return 0; +} + +void on_mouse(int event, int x, int y, int flags, void* userdata) { + static int cnt = 0; + + if (event == EVENT_LBUTTONDOWN) { + srcQuad[cnt++ % 4] = Point2f(x, y); + + circle(src, Point(x, y), 5, Scalar(0, 0, 255), -1); + imshow("src", src); + + if (cnt % 4 == 0) { + int w = 200, h = 300; + + dstQuad[0] = Point2f(0, 0); + dstQuad[1] = Point2f(w - 1, 0); + dstQuad[2] = Point2f(w - 1, h - 1); + dstQuad[3] = Point2f(0, h - 1); + + Mat pers = getPerspectiveTransform(srcQuad, dstQuad); + + Mat dst; + warpPerspective(src, dst, pers, Size(w, h)); + + imshow("dst", dst); + } + } } \ No newline at end of file diff --git a/Homework/perspective/perspective.vcxproj b/Homework/perspective/perspective.vcxproj index fc6254f..dd31077 100644 --- a/Homework/perspective/perspective.vcxproj +++ b/Homework/perspective/perspective.vcxproj @@ -133,6 +133,9 @@ + + + diff --git a/Homework/perspective/perspective.vcxproj.filters b/Homework/perspective/perspective.vcxproj.filters index 2c1b3dc..8080f73 100644 --- a/Homework/perspective/perspective.vcxproj.filters +++ b/Homework/perspective/perspective.vcxproj.filters @@ -19,4 +19,9 @@ 소스 파일 + + + 리소스 파일 + + \ No newline at end of file