과제 확인하기
This commit is contained in:
@@ -57,6 +57,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "affine", "ch08\affine\affin
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perspective", "Homework\perspective\perspective.vcxproj", "{F920D051-F9B5-43C2-ACF7-C5DE9B18B20C}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ch09", "ch09", "{2BBACE58-DAC1-4D1E-85FC-3A3E9F789D9B}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "edge_detection", "ch09\edge_detection\edge_detection.vcxproj", "{F7126457-CC07-433A-B762-C4DFB352653C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@@ -209,6 +213,14 @@ Global
|
||||
{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
|
||||
{F7126457-CC07-433A-B762-C4DFB352653C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{F7126457-CC07-433A-B762-C4DFB352653C}.Debug|x64.Build.0 = Debug|x64
|
||||
{F7126457-CC07-433A-B762-C4DFB352653C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{F7126457-CC07-433A-B762-C4DFB352653C}.Debug|x86.Build.0 = Debug|Win32
|
||||
{F7126457-CC07-433A-B762-C4DFB352653C}.Release|x64.ActiveCfg = Release|x64
|
||||
{F7126457-CC07-433A-B762-C4DFB352653C}.Release|x64.Build.0 = Release|x64
|
||||
{F7126457-CC07-433A-B762-C4DFB352653C}.Release|x86.ActiveCfg = Release|Win32
|
||||
{F7126457-CC07-433A-B762-C4DFB352653C}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -232,6 +244,7 @@ Global
|
||||
{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}
|
||||
{F7126457-CC07-433A-B762-C4DFB352653C} = {2BBACE58-DAC1-4D1E-85FC-3A3E9F789D9B}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E1A0C3F4-F16D-4626-86CE-D8484C0C776D}
|
||||
|
||||
144
ch09/edge_detection/edge_detection.vcxproj
Normal file
144
ch09/edge_detection/edge_detection.vcxproj
Normal file
@@ -0,0 +1,144 @@
|
||||
<?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>{f7126457-cc07-433a-b762-c4dfb352653c}</ProjectGuid>
|
||||
<RootNamespace>edgedetection</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\building.jpg" />
|
||||
<Image Include="..\..\resources\images\coins.png" />
|
||||
<Image Include="..\..\resources\images\lenna.bmp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
33
ch09/edge_detection/edge_detection.vcxproj.filters
Normal file
33
ch09/edge_detection/edge_detection.vcxproj.filters
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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\lenna.bmp">
|
||||
<Filter>리소스 파일</Filter>
|
||||
</Image>
|
||||
<Image Include="..\..\resources\images\building.jpg">
|
||||
<Filter>리소스 파일</Filter>
|
||||
</Image>
|
||||
<Image Include="..\..\resources\images\coins.png">
|
||||
<Filter>리소스 파일</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
160
ch09/edge_detection/main.cpp
Normal file
160
ch09/edge_detection/main.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
void hough_circles() {
|
||||
cv::Mat src = cv::imread("../../resources/images/coins.png", cv::IMREAD_GRAYSCALE);
|
||||
cv::Mat blurred;
|
||||
|
||||
cv::GaussianBlur(src, blurred, cv::Size(), 2.f);
|
||||
|
||||
cv::imshow("s", blurred);
|
||||
cv::waitKey();
|
||||
|
||||
std::vector<cv::Vec3f>circles;
|
||||
cv::HoughCircles(blurred, circles, cv::HOUGH_GRADIENT, 1, 50, 150, 30);
|
||||
|
||||
cv::Mat dst;
|
||||
cv::cvtColor(src, dst, cv::COLOR_GRAY2BGR);
|
||||
|
||||
for (auto c : circles) {
|
||||
cv::Point pt1(cvRound(c[0]), cvRound(c[1]));
|
||||
int radius = cvRound(c[2]);
|
||||
|
||||
cv::circle(dst, pt1, radius, cv::Scalar(0, 0, 255), 2, cv::LINE_AA);
|
||||
}
|
||||
|
||||
cv::imshow("src", src);
|
||||
cv::imshow("dst", dst);
|
||||
|
||||
cv::waitKey();
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
void hough_lines() {
|
||||
cv::Mat src = cv::imread("../../resources/images/building.jpg", cv::IMREAD_GRAYSCALE);
|
||||
cv::Mat blurred;
|
||||
|
||||
cv::GaussianBlur(src, blurred, cv::Size(), 2.f);
|
||||
|
||||
cv::Mat dx, dy, edge;
|
||||
|
||||
cv::Sobel(blurred, dx, CV_16SC1, 1, 0, cv::FILTER_SCHARR);
|
||||
cv::Sobel(blurred, dy, CV_16SC1, 0, 1, cv::FILTER_SCHARR);
|
||||
|
||||
cv::Canny(dx, dy, edge, 50, 100);
|
||||
|
||||
std::vector<cv::Vec2f>lines;
|
||||
cv::HoughLines(edge, lines, 1, CV_PI / 180, 250);
|
||||
|
||||
cv::Mat dst;
|
||||
cv::cvtColor(edge, dst, cv::COLOR_GRAY2BGR);
|
||||
|
||||
for (size_t i = 0; i < lines.size(); i++) {
|
||||
float r = lines[i][0], t = lines[i][1];
|
||||
double cos_t = std::cos(t), sin_t = std::sin(t);
|
||||
double x0 = r * cos_t, y0 = r * sin_t;
|
||||
double alpha = 1000;
|
||||
|
||||
cv::Point pt1(cvRound(x0 + alpha * (-sin_t)), cvRound(y0 + alpha * cos_t));
|
||||
cv::Point pt2(cvRound(x0 - alpha * (-sin_t)), cvRound(y0 - alpha * cos_t));
|
||||
|
||||
cv::line(dst, pt1, pt2, cv::Scalar(0, 0, 255), 2, cv::LINE_AA);
|
||||
}
|
||||
|
||||
cv::imshow("src", src);
|
||||
cv::imshow("dst", dst);
|
||||
|
||||
cv::waitKey();
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
void canny_edge() {
|
||||
cv::Mat src = cv::imread("../../resources/images/lenna.bmp", cv::IMREAD_GRAYSCALE);
|
||||
cv::Mat blurred;
|
||||
|
||||
cv::GaussianBlur(src, blurred, cv::Size(), (double)3);
|
||||
|
||||
cv::Mat dx, dy, dst1, dst2, phase;
|
||||
|
||||
cv::Sobel(blurred, dx, CV_32FC1, 1, 0, cv::FILTER_SCHARR);
|
||||
cv::Sobel(blurred, dy, CV_32FC1, 0, 1, cv::FILTER_SCHARR);
|
||||
|
||||
cv::phase(dx, dy, phase, true);
|
||||
cv::normalize(phase, phase, 0, 255, cv::NORM_MINMAX);
|
||||
phase.convertTo(phase, CV_8UC1);
|
||||
|
||||
cv::Sobel(blurred, dx, CV_16SC1, 1, 0, cv::FILTER_SCHARR);
|
||||
cv::Sobel(blurred, dy, CV_16SC1, 0, 1, cv::FILTER_SCHARR);
|
||||
|
||||
cv::Canny(dx, dy, dst1, 50, 100);
|
||||
cv::Canny(dx, dy, dst2, 50, 150);
|
||||
|
||||
cv::imshow("src", src);
|
||||
cv::imshow("dst1", dst1);
|
||||
cv::imshow("dst2", dst2);
|
||||
cv::imshow("phase", phase);
|
||||
|
||||
cv::waitKey();
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
void scharr() {
|
||||
cv::Mat src = cv::imread("../../resources/images/lenna.bmp", cv::IMREAD_GRAYSCALE);
|
||||
|
||||
cv::Mat dx, dy, fmag, mag, phase;
|
||||
|
||||
cv::Sobel(src, dx, CV_32FC1, 1, 0, cv::FILTER_SCHARR);
|
||||
cv::Sobel(src, dy, CV_32FC1, 0, 1, cv::FILTER_SCHARR);
|
||||
|
||||
cv::magnitude(dx, dy, fmag);
|
||||
fmag.convertTo(mag, CV_8UC1);
|
||||
|
||||
cv::phase(dx, dy, phase, true);
|
||||
cv::normalize(phase, phase, 0, 255, cv::NORM_MINMAX);
|
||||
phase.convertTo(phase, CV_8UC1);
|
||||
|
||||
cv::Mat edge = mag > 150;
|
||||
|
||||
cv::imshow("src", src);
|
||||
cv::imshow("mag", mag);
|
||||
cv::imshow("edge", edge);
|
||||
cv::imshow("phase", phase);
|
||||
|
||||
cv::waitKey();
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
void partial() {
|
||||
cv::Mat src = cv::imread("../../resources/images/lenna.bmp", cv::IMREAD_GRAYSCALE);
|
||||
cv::Mat edge(src.rows, src.cols, CV_8UC1);
|
||||
|
||||
std::array<std::float_t, 3> filter = {-1, 0, 1};
|
||||
|
||||
cv::Mat kernalx(1, 3, CV_32F, filter.data());
|
||||
cv::Mat kernaly(3, 1, CV_32F, filter.data());
|
||||
|
||||
cv::Mat derx, dery;
|
||||
|
||||
cv::filter2D(src, derx, -1, kernalx, cv::Point(-1, -1), 128);
|
||||
cv::filter2D(src, dery, -1, kernaly, cv::Point(-1, -1), 128);
|
||||
|
||||
for (int k = 0; k < 256; k++) {
|
||||
for (int i = 0; i < edge.rows; i++)
|
||||
for (int j = 0; j < edge.cols; j++) {
|
||||
if (std::sqrt(std::pow(derx.at<std::int8_t>(i, j), 2) + std::pow(dery.at<std::int8_t>(i, j), 2)) > k)
|
||||
edge.at<std::int8_t>(i, j) = 0;
|
||||
else
|
||||
edge.at<std::int8_t>(i, j) = 255;
|
||||
}
|
||||
std::cout << k << std::endl;
|
||||
cv::imshow("edge", edge);
|
||||
cv::waitKey();
|
||||
}
|
||||
|
||||
cv::waitKey();
|
||||
cv::destroyAllWindows();
|
||||
}
|
||||
|
||||
int main() {
|
||||
hough_circles();
|
||||
}
|
||||
Reference in New Issue
Block a user