perspective 과제, 변환 여러번 가능하도록 짜기
This commit is contained in:
143
ch08/affine/affine.vcxproj
Normal file
143
ch08/affine/affine.vcxproj
Normal file
@@ -0,0 +1,143 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{e0970c66-807b-4090-83c4-c71227bd2aff}</ProjectGuid>
|
||||
<RootNamespace>affine</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\OPENCV4110_debug.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\OPENCV4110_release.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\OPENCV4110_debug.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\OPENCV4110_release.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="..\..\resources\images\lenna.bmp" />
|
||||
<Image Include="..\..\resources\images\tekapo.bmp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
30
ch08/affine/affine.vcxproj.filters
Normal file
30
ch08/affine/affine.vcxproj.filters
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="소스 파일">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="헤더 파일">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="리소스 파일">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>소스 파일</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="..\..\resources\images\tekapo.bmp">
|
||||
<Filter>리소스 파일</Filter>
|
||||
</Image>
|
||||
<Image Include="..\..\resources\images\lenna.bmp">
|
||||
<Filter>리소스 파일</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
137
ch08/affine/main.cpp
Normal file
137
ch08/affine/main.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#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<float_t, 6> 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_<double_t>({ 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_<double_t>({ 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<float_t, 6> 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<Point2f> 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;
|
||||
}
|
||||
Reference in New Issue
Block a user