From ecfb02b69343a895369e8798189b33b63e2db639 Mon Sep 17 00:00:00 2001 From: USW Date: Wed, 9 Apr 2025 12:02:15 +0900 Subject: [PATCH] =?UTF-8?q?perspective=20=EA=B3=BC=EC=A0=9C,=20=EB=B3=80?= =?UTF-8?q?=ED=99=98=20=EC=97=AC=EB=9F=AC=EB=B2=88=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=A7=9C=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Capstone_Design.sln | 24 +++ Homework/perspective/main.cpp | 11 ++ Homework/perspective/perspective.vcxproj | 139 +++++++++++++++++ .../perspective/perspective.vcxproj.filters | 22 +++ ch08/affine/affine.vcxproj | 143 ++++++++++++++++++ ch08/affine/affine.vcxproj.filters | 30 ++++ ch08/affine/main.cpp | 137 +++++++++++++++++ 7 files changed, 506 insertions(+) create mode 100644 Homework/perspective/main.cpp create mode 100644 Homework/perspective/perspective.vcxproj create mode 100644 Homework/perspective/perspective.vcxproj.filters create mode 100644 ch08/affine/affine.vcxproj create mode 100644 ch08/affine/affine.vcxproj.filters create mode 100644 ch08/affine/main.cpp diff --git a/Capstone_Design.sln b/Capstone_Design.sln index 619c014..38040cf 100644 --- a/Capstone_Design.sln +++ b/Capstone_Design.sln @@ -51,6 +51,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Homework", "Homework", "{E5 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "noise_denoise", "Homework\noise_denoise\noise_denoise.vcxproj", "{C91F6DA7-8B51-4630-9340-D3643FE0531E}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ch08", "ch08", "{610D1B36-71E3-4C3D-B0CE-2C563B0504A6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "affine", "ch08\affine\affine.vcxproj", "{E0970C66-807B-4090-83C4-C71227BD2AFF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perspective", "Homework\perspective\perspective.vcxproj", "{F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -187,6 +193,22 @@ Global {C91F6DA7-8B51-4630-9340-D3643FE0531E}.Release|x64.Build.0 = Release|x64 {C91F6DA7-8B51-4630-9340-D3643FE0531E}.Release|x86.ActiveCfg = Release|Win32 {C91F6DA7-8B51-4630-9340-D3643FE0531E}.Release|x86.Build.0 = Release|Win32 + {E0970C66-807B-4090-83C4-C71227BD2AFF}.Debug|x64.ActiveCfg = Debug|x64 + {E0970C66-807B-4090-83C4-C71227BD2AFF}.Debug|x64.Build.0 = Debug|x64 + {E0970C66-807B-4090-83C4-C71227BD2AFF}.Debug|x86.ActiveCfg = Debug|Win32 + {E0970C66-807B-4090-83C4-C71227BD2AFF}.Debug|x86.Build.0 = Debug|Win32 + {E0970C66-807B-4090-83C4-C71227BD2AFF}.Release|x64.ActiveCfg = Release|x64 + {E0970C66-807B-4090-83C4-C71227BD2AFF}.Release|x64.Build.0 = Release|x64 + {E0970C66-807B-4090-83C4-C71227BD2AFF}.Release|x86.ActiveCfg = Release|Win32 + {E0970C66-807B-4090-83C4-C71227BD2AFF}.Release|x86.Build.0 = Release|Win32 + {F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}.Debug|x64.ActiveCfg = Debug|x64 + {F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}.Debug|x64.Build.0 = Debug|x64 + {F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}.Debug|x86.ActiveCfg = Debug|Win32 + {F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}.Debug|x86.Build.0 = Debug|Win32 + {F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}.Release|x64.ActiveCfg = Release|x64 + {F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}.Release|x64.Build.0 = Release|x64 + {F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}.Release|x86.ActiveCfg = Release|Win32 + {F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -208,6 +230,8 @@ Global {A871F9D8-2DD0-4B01-A304-E738968313F2} = {E0A91F3E-0B54-4785-AB66-727A7EE1E15B} {380222EF-FFE1-445F-B409-1DD866DF1ED9} = {E0A91F3E-0B54-4785-AB66-727A7EE1E15B} {C91F6DA7-8B51-4630-9340-D3643FE0531E} = {E583E257-9FCE-4A4B-A554-8514F982D1BF} + {E0970C66-807B-4090-83C4-C71227BD2AFF} = {610D1B36-71E3-4C3D-B0CE-2C563B0504A6} + {F920D051-F9B5-43C2-ACF7-C5DE9B18B20C} = {E583E257-9FCE-4A4B-A554-8514F982D1BF} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E1A0C3F4-F16D-4626-86CE-D8484C0C776D} diff --git a/Homework/perspective/main.cpp b/Homework/perspective/main.cpp new file mode 100644 index 0000000..bec8593 --- /dev/null +++ b/Homework/perspective/main.cpp @@ -0,0 +1,11 @@ +#include +#include +#include +#include +#include "opencv2/opencv.hpp" + +using namespace std; +using namespace cv; + +int main() { +} \ No newline at end of file diff --git a/Homework/perspective/perspective.vcxproj b/Homework/perspective/perspective.vcxproj new file mode 100644 index 0000000..fc6254f --- /dev/null +++ b/Homework/perspective/perspective.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {f920d051-f9b5-43c2-acf7-c5de9b18b20c} + perspective + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/Homework/perspective/perspective.vcxproj.filters b/Homework/perspective/perspective.vcxproj.filters new file mode 100644 index 0000000..2c1b3dc --- /dev/null +++ b/Homework/perspective/perspective.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 소스 파일 + + + \ No newline at end of file diff --git a/ch08/affine/affine.vcxproj b/ch08/affine/affine.vcxproj new file mode 100644 index 0000000..9e78b38 --- /dev/null +++ b/ch08/affine/affine.vcxproj @@ -0,0 +1,143 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {e0970c66-807b-4090-83c4-c71227bd2aff} + affine + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/ch08/affine/affine.vcxproj.filters b/ch08/affine/affine.vcxproj.filters new file mode 100644 index 0000000..7e88d13 --- /dev/null +++ b/ch08/affine/affine.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 소스 파일 + + + + + 리소스 파일 + + + 리소스 파일 + + + \ No newline at end of file diff --git a/ch08/affine/main.cpp b/ch08/affine/main.cpp new file mode 100644 index 0000000..b758652 --- /dev/null +++ b/ch08/affine/main.cpp @@ -0,0 +1,137 @@ +#include +#include +#include +#include +#include "opencv2/opencv.hpp" + +using namespace std; +using namespace cv; + +void affine_flip() { + Mat src = imread("../../resources/images/eastsea.bmp"); + + imshow("src", src); + + Mat dst; + int flipCode[] = { 1, 0, -1 }; + for (int i = 0; i < 3; i++) { + flip(src, dst, flipCode[i]); + + String desc = format("filpcode: %d", flipCode[i]); + putText(dst, desc, Point(10, 30), FONT_HERSHEY_SIMPLEX, 1.0, Scalar(255, 0, 0), 1, LINE_AA); + + imshow("dst", dst); + waitKey(); + } + destroyAllWindows(); +} + +void affine_rotation() { + Mat src = imread("../../resources/images/tekapo.bmp"); + + Point2f cp(src.cols / 2.f, src.rows / 2.f); + + array data = { 0.f, 0.f, cos(20 * 3.141592 / 180), 0.f, 0.f, sin(20 * 3.141592 / 180) }; + Mat M(2, 3, CV_32F, data.data()); + + M += getRotationMatrix2D(cp, 20, 1); + Mat dst; + + warpAffine(src, dst, M, Size(src.cols + cos(20 * 3.141592 / 180), src.rows + sin(20 * 3.141592 / 180))); + + imshow("src", src); + imshow("dst", dst); + + waitKey(); + destroyAllWindows(); +} + +void affine_scale() { + Mat src = imread("../../resources/images/rose.bmp"); + + Mat dst1, dst2, dst3, dst4; + resize(src, dst1, Size(), 4, 4, INTER_NEAREST); + resize(src, dst2, Size(1920, 1280)); + resize(src, dst3, Size(1920, 1280), 0, 0, INTER_CUBIC); + resize(src, dst4, Size(1920 * 2, 1280 * 2), 0, 0, INTER_LANCZOS4); + + imshow("src", src); + imshow("dst1", dst1(Rect(400, 500, 400, 400))); + imshow("dst2", dst2(Rect(400, 500, 400, 400))); + imshow("dst3", dst3(Rect(400, 500, 400, 400))); + imshow("dst4", dst4(Rect(800, 1000, 400, 400))); + + waitKey(); + destroyAllWindows(); +} + +void affine_shear() { + Mat src = imread("../../resources/images/tekapo.bmp"); + + double_t mx = tan(15 * 3.141592 / 180); // x축에 대해 각도만큼 기울이는 코드 + double_t my = tan(15 * 3.141592 / 180); // y축에 대해 각도만큼 기울이는 코드 + Mat M = Mat_({ 2, 3 }, { 1, mx, 0, my, 1, 0 }), dst; + + warpAffine(src, dst, M, Size(cvRound(src.cols + src.rows * mx), cvRound(src.rows + src.cols * my))); + + imshow("src", src); + imshow("dst", dst); + + waitKey(); + destroyAllWindows(); +} + +void affine_translation() { + Mat src = imread("../../resources/images/tekapo.bmp"); + + Mat M = Mat_({ 2, 3 }, { 1, 0, 150, 0, 1, 100 }), dst; + + Size _new_size = src.size(); + _new_size.width += 150 * 2; + _new_size.height += 100 * 2; + warpAffine(src, dst, M, _new_size); + + imshow("src", src); + imshow("dst", dst); + + waitKey(); + destroyAllWindows(); +} + +void affine_transform() { + Mat src = imread("../../resources/images/tekapo.bmp"); + + /*Point2f srcPts[3] = { + Point2f(0, 0), + Point2f(src.cols - 1, 0), + Point2f(src.cols - 1, src.rows - 1) + }, dstPts[3] = { + Point2f(50, 50), + Point2f(src.cols - 100, 100), + Point2f(src.cols - 50, src.rows - 50) + };*/ + + array data = { 0.8f, 0.f, 30.f, 0.f, 0.8f, 30.f }; + Mat M(2, 3, CV_32F, data.data()); + Mat dst = imread("../../resources/images/lenna.bmp"); + + warpAffine(src, dst, M, Size(), INTER_LINEAR, BORDER_CONSTANT, Scalar(50, 50, 100)); + + vector sP = { Point2f(10, 10), Point2f(30, 70), Point2f(100, 80) }, tP; + transform(sP, tP, M); + Mat cM = getAffineTransform(sP, tP); + + cout << "Transform matrix M : " << M << endl; + cout << "Calculated matrix cM : " << cM << endl; + + imshow("src", src); + imshow("dst", dst); + + waitKey(); + destroyAllWindows(); +} + +int main() { + affine_rotation(); + return 0; +} \ No newline at end of file