From 63525bab64d46d94f2223437da55bad5701363fa Mon Sep 17 00:00:00 2001 From: USW Date: Wed, 30 Apr 2025 12:11:45 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=BC=EB=8B=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Capstone_Design.sln | 35 +++++ ch11/adaptive/adaptive.vcxproj | 139 ++++++++++++++++++++ ch11/adaptive/adaptive.vcxproj.filters | 22 ++++ ch11/adaptive/main.cpp | 43 ++++++ ch11/morphology/main.cpp | 72 ++++++++++ ch11/morphology/morphology.vcxproj | 145 +++++++++++++++++++++ ch11/morphology/morphology.vcxproj.filters | 32 +++++ ch11/thershhold/main.cpp | 54 ++++++++ ch11/thershhold/thershhold.vcxproj | 144 ++++++++++++++++++++ ch11/thershhold/thershhold.vcxproj.filters | 33 +++++ resources/images/document.bmp | 3 + 11 files changed, 722 insertions(+) create mode 100644 ch11/adaptive/adaptive.vcxproj create mode 100644 ch11/adaptive/adaptive.vcxproj.filters create mode 100644 ch11/adaptive/main.cpp create mode 100644 ch11/morphology/main.cpp create mode 100644 ch11/morphology/morphology.vcxproj create mode 100644 ch11/morphology/morphology.vcxproj.filters create mode 100644 ch11/thershhold/main.cpp create mode 100644 ch11/thershhold/thershhold.vcxproj create mode 100644 ch11/thershhold/thershhold.vcxproj.filters create mode 100644 resources/images/document.bmp diff --git a/Capstone_Design.sln b/Capstone_Design.sln index c5869b5..c88a62c 100644 --- a/Capstone_Design.sln +++ b/Capstone_Design.sln @@ -61,6 +61,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ch09", "ch09", "{2BBACE58-D EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "edge_detection", "ch09\edge_detection\edge_detection.vcxproj", "{F7126457-CC07-433A-B762-C4DFB352653C}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ch11", "ch11", "{94FE4669-77AC-4D41-8E24-F5DEDEAC930F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "thershhold", "ch11\thershhold\thershhold.vcxproj", "{12A25565-0007-412B-9490-9AA28305272D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "adaptive", "ch11\adaptive\adaptive.vcxproj", "{8F873187-A5F8-4D02-ABE9-BF652FE53BC3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "morphology", "ch11\morphology\morphology.vcxproj", "{9BD9A147-29ED-4F6C-8BFD-71F03E56332C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -221,6 +229,30 @@ Global {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 + {12A25565-0007-412B-9490-9AA28305272D}.Debug|x64.ActiveCfg = Debug|x64 + {12A25565-0007-412B-9490-9AA28305272D}.Debug|x64.Build.0 = Debug|x64 + {12A25565-0007-412B-9490-9AA28305272D}.Debug|x86.ActiveCfg = Debug|Win32 + {12A25565-0007-412B-9490-9AA28305272D}.Debug|x86.Build.0 = Debug|Win32 + {12A25565-0007-412B-9490-9AA28305272D}.Release|x64.ActiveCfg = Release|x64 + {12A25565-0007-412B-9490-9AA28305272D}.Release|x64.Build.0 = Release|x64 + {12A25565-0007-412B-9490-9AA28305272D}.Release|x86.ActiveCfg = Release|Win32 + {12A25565-0007-412B-9490-9AA28305272D}.Release|x86.Build.0 = Release|Win32 + {8F873187-A5F8-4D02-ABE9-BF652FE53BC3}.Debug|x64.ActiveCfg = Debug|x64 + {8F873187-A5F8-4D02-ABE9-BF652FE53BC3}.Debug|x64.Build.0 = Debug|x64 + {8F873187-A5F8-4D02-ABE9-BF652FE53BC3}.Debug|x86.ActiveCfg = Debug|Win32 + {8F873187-A5F8-4D02-ABE9-BF652FE53BC3}.Debug|x86.Build.0 = Debug|Win32 + {8F873187-A5F8-4D02-ABE9-BF652FE53BC3}.Release|x64.ActiveCfg = Release|x64 + {8F873187-A5F8-4D02-ABE9-BF652FE53BC3}.Release|x64.Build.0 = Release|x64 + {8F873187-A5F8-4D02-ABE9-BF652FE53BC3}.Release|x86.ActiveCfg = Release|Win32 + {8F873187-A5F8-4D02-ABE9-BF652FE53BC3}.Release|x86.Build.0 = Release|Win32 + {9BD9A147-29ED-4F6C-8BFD-71F03E56332C}.Debug|x64.ActiveCfg = Debug|x64 + {9BD9A147-29ED-4F6C-8BFD-71F03E56332C}.Debug|x64.Build.0 = Debug|x64 + {9BD9A147-29ED-4F6C-8BFD-71F03E56332C}.Debug|x86.ActiveCfg = Debug|Win32 + {9BD9A147-29ED-4F6C-8BFD-71F03E56332C}.Debug|x86.Build.0 = Debug|Win32 + {9BD9A147-29ED-4F6C-8BFD-71F03E56332C}.Release|x64.ActiveCfg = Release|x64 + {9BD9A147-29ED-4F6C-8BFD-71F03E56332C}.Release|x64.Build.0 = Release|x64 + {9BD9A147-29ED-4F6C-8BFD-71F03E56332C}.Release|x86.ActiveCfg = Release|Win32 + {9BD9A147-29ED-4F6C-8BFD-71F03E56332C}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -245,6 +277,9 @@ Global {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} + {12A25565-0007-412B-9490-9AA28305272D} = {94FE4669-77AC-4D41-8E24-F5DEDEAC930F} + {8F873187-A5F8-4D02-ABE9-BF652FE53BC3} = {94FE4669-77AC-4D41-8E24-F5DEDEAC930F} + {9BD9A147-29ED-4F6C-8BFD-71F03E56332C} = {94FE4669-77AC-4D41-8E24-F5DEDEAC930F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E1A0C3F4-F16D-4626-86CE-D8484C0C776D} diff --git a/ch11/adaptive/adaptive.vcxproj b/ch11/adaptive/adaptive.vcxproj new file mode 100644 index 0000000..7f139fd --- /dev/null +++ b/ch11/adaptive/adaptive.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {8f873187-a5f8-4d02-abe9-bf652fe53bc3} + adaptive + 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/ch11/adaptive/adaptive.vcxproj.filters b/ch11/adaptive/adaptive.vcxproj.filters new file mode 100644 index 0000000..2c1b3dc --- /dev/null +++ b/ch11/adaptive/adaptive.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/ch11/adaptive/main.cpp b/ch11/adaptive/main.cpp new file mode 100644 index 0000000..b33a6ac --- /dev/null +++ b/ch11/adaptive/main.cpp @@ -0,0 +1,43 @@ +#include +#include "opencv2/opencv.hpp" + +using namespace cv; +using namespace std; + +void on_trackbar(int pos, void* userdata); + +int main(int argc, char* argv[]) { + Mat src; + + if (argc < 2) + src = imread("../../resources/images/sudoku.jpg", IMREAD_GRAYSCALE); + else + src = imread(argv[1], IMREAD_GRAYSCALE); + + if (src.empty()) { + cerr << "Image load failed!" << endl; + return -1; + } + + imshow("src", src); + + namedWindow("dst"); + createTrackbar("Block size", "dst", 0, 200, on_trackbar, (void*)&src); + setTrackbarPos("Block size", "dst", 11); + + cv::waitKey(); + cv::destroyAllWindows(); +} + +void on_trackbar(int pos, void* userdata) { + Mat src = *(Mat*)userdata; + + int bsize = pos; + if (bsize % 2 == 0) bsize--; + if (bsize < 3) bsize = 3; + + Mat dst; + adaptiveThreshold(src, dst, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, bsize, 5); + + imshow("dst", dst); +} \ No newline at end of file diff --git a/ch11/morphology/main.cpp b/ch11/morphology/main.cpp new file mode 100644 index 0000000..5e7bdf8 --- /dev/null +++ b/ch11/morphology/main.cpp @@ -0,0 +1,72 @@ +#include +#include "opencv2/opencv.hpp" + +using namespace cv; +using namespace std; + +void erode_dilate() { + Mat src = imread("../../resources/images/milkdrop.bmp", IMREAD_GRAYSCALE); + Mat bin; + threshold(src, bin, 0, 255, THRESH_BINARY | THRESH_OTSU); + + Mat dst1, dst2; + erode(bin, dst1, getStructuringElement(MorphShapes::MORPH_CROSS, Size(7, 7))); + dilate(bin, dst2, getStructuringElement(MorphShapes::MORPH_ELLIPSE, Size(3, 5))); + + imshow("src", src); + imshow("bin", bin); + imshow("erode", dst1); + imshow("dilate", dst2); + + cv::waitKey(); + cv::destroyAllWindows(); +} + +void open_close() { + cv::VideoCapture video("../../resources/images/vtest.avi"); + if (!video.isOpened()) { + std::cerr << "camera.isopened()" << std::endl; + return; + } + cv::Mat src; + cv::Mat prevSrc; + double fps = 1000 / video.get(cv::VideoCaptureProperties::CAP_PROP_FPS); + std::cout << "\n\n" << fps << "\n\n"; + while (true) { + prevSrc = src; + video >> src; + if (src.empty()) { + std::cerr << "img.empty()" << std::endl; + return; + } + cv::imshow("src", src); + if (cv::waitKey(fps) == 27) + break; + } + cv::cvtColor(src, src, cv::COLOR_BGR2GRAY); + src.convertTo(src, CV_8U); + + Mat bin; + threshold(src, bin, 0, 255, THRESH_BINARY | THRESH_OTSU); + + Mat dst1, dst2, dst3, dst4, dst5; + morphologyEx(bin, dst1, MORPH_OPEN, Mat()); + morphologyEx(bin, dst2, MORPH_CLOSE, Mat()); + morphologyEx(bin, dst3, MORPH_GRADIENT, Mat()); + Canny(bin, dst4, 30, 127); + dst5 = std::abs(src - prevSrc); + + imshow("src", src); + imshow("bin", bin); + imshow("erode", dst1); + imshow("dilate", dst2); + imshow("gradient", dst3); + imshow("Canny", dst4); + + cv::waitKey(); + cv::destroyAllWindows(); +} + +int main(int argc, char* argv[]) { + open_close(); +} \ No newline at end of file diff --git a/ch11/morphology/morphology.vcxproj b/ch11/morphology/morphology.vcxproj new file mode 100644 index 0000000..16233c7 --- /dev/null +++ b/ch11/morphology/morphology.vcxproj @@ -0,0 +1,145 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {9bd9a147-29ed-4f6c-8bfd-71f03e56332c} + morphology + 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/ch11/morphology/morphology.vcxproj.filters b/ch11/morphology/morphology.vcxproj.filters new file mode 100644 index 0000000..f0f8d4f --- /dev/null +++ b/ch11/morphology/morphology.vcxproj.filters @@ -0,0 +1,32 @@ + + + + + {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/ch11/thershhold/main.cpp b/ch11/thershhold/main.cpp new file mode 100644 index 0000000..b436cf4 --- /dev/null +++ b/ch11/thershhold/main.cpp @@ -0,0 +1,54 @@ +#include +#include "opencv2/opencv.hpp" + +using namespace cv; +using namespace std; + +void on_trackbar(int pos, void* userdata); + +int main(int argc, char* argv[]) { + Mat src; + + if (argc < 2) + src = imread("../../resources/images/neutrophils.png", IMREAD_GRAYSCALE); + else + src = imread(argv[1], IMREAD_GRAYSCALE); + + if (src.empty()) { + cerr << "Image load failed!" << endl; + return -1; + } + + namedWindow("dst"); + createTrackbar("Threshold", "dst", 0, 255, on_trackbar, (void*)&src); + setTrackbarPos("Threshold", "dst", 128); + + cv::waitKey(); + cv::destroyAllWindows(); +} + +void on_trackbar(int pos, void* userdata) { + Mat src = *(Mat*)userdata; + + Mat hist; + int channels[] = { 0 }; + int dims = 1; + const int histSize[] = { 256 }; + float graylevel[] = { 0, 256 }; + const float* ranges[] = { graylevel }; + + calcHist(&src, 1, channels, noArray(), hist, dims, histSize, ranges); + double histMax; + minMaxLoc(hist, 0, &histMax); + Mat imgHist(100, 256, CV_8UC1, Scalar(255)); + for (int i = 0; i < 256; i++) { + line(imgHist, Point(i, 100), Point(i, 100 - cvRound(hist.at(i, 0) * 100 / histMax)), Scalar(0)); + } + line(imgHist, Point(pos, 0), Point(pos, 100), 0, 1, LINE_AA); + + Mat dst; + threshold(src, dst, pos, 255, THRESH_BINARY); + + imshow("dst", dst); + imshow("hist", imgHist); +} \ No newline at end of file diff --git a/ch11/thershhold/thershhold.vcxproj b/ch11/thershhold/thershhold.vcxproj new file mode 100644 index 0000000..902a65b --- /dev/null +++ b/ch11/thershhold/thershhold.vcxproj @@ -0,0 +1,144 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {12a25565-0007-412b-9490-9aa28305272d} + thershhold + 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/ch11/thershhold/thershhold.vcxproj.filters b/ch11/thershhold/thershhold.vcxproj.filters new file mode 100644 index 0000000..813d112 --- /dev/null +++ b/ch11/thershhold/thershhold.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {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/resources/images/document.bmp b/resources/images/document.bmp new file mode 100644 index 0000000..553629c --- /dev/null +++ b/resources/images/document.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:543e2b7228821792610d3cbe86077668f4de9934f588a1802e11aac70b737c77 +size 2250054