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