diff --git a/.gitignore b/.gitignore index 203d776..1000e8d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ ################################################################################ /.vs/07_Feature_Matching/v16 +/07_Feature_Matching/x64/Debug diff --git a/07_Feature_Matching.sln b/07_Feature_Matching.sln new file mode 100644 index 0000000..89befa6 --- /dev/null +++ b/07_Feature_Matching.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33423.256 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "07_Feature_Matching", "07_Feature_Matching\07_Feature_Matching.vcxproj", "{A2446EAA-BC66-4031-9B30-02B0F7130CF7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A2446EAA-BC66-4031-9B30-02B0F7130CF7}.Debug|x64.ActiveCfg = Debug|x64 + {A2446EAA-BC66-4031-9B30-02B0F7130CF7}.Debug|x64.Build.0 = Debug|x64 + {A2446EAA-BC66-4031-9B30-02B0F7130CF7}.Debug|x86.ActiveCfg = Debug|Win32 + {A2446EAA-BC66-4031-9B30-02B0F7130CF7}.Debug|x86.Build.0 = Debug|Win32 + {A2446EAA-BC66-4031-9B30-02B0F7130CF7}.Release|x64.ActiveCfg = Release|x64 + {A2446EAA-BC66-4031-9B30-02B0F7130CF7}.Release|x64.Build.0 = Release|x64 + {A2446EAA-BC66-4031-9B30-02B0F7130CF7}.Release|x86.ActiveCfg = Release|Win32 + {A2446EAA-BC66-4031-9B30-02B0F7130CF7}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6F30637E-EDAF-47ED-9952-D8D2A4947D6A} + EndGlobalSection +EndGlobal diff --git a/07_Feature_Matching/07_Feature_Matching.vcxproj b/07_Feature_Matching/07_Feature_Matching.vcxproj new file mode 100644 index 0000000..8fe4193 --- /dev/null +++ b/07_Feature_Matching/07_Feature_Matching.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {a2446eaa-bc66-4031-9b30-02b0f7130cf7} + My07FeatureMatching + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + C:\opencv-4.6.0_X64\build\include + + + false + + + + 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 + C:\opencv-4.6.0_X64\build\include + + + Console + true + C:\opencv-4.6.0_X64\build\x64\vc15\lib + opencv_world460d.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/07_Feature_Matching/07_Feature_Matching.vcxproj.filters b/07_Feature_Matching/07_Feature_Matching.vcxproj.filters new file mode 100644 index 0000000..44ccbe8 --- /dev/null +++ b/07_Feature_Matching/07_Feature_Matching.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/07_Feature_Matching/07_Feature_Matching.vcxproj.user b/07_Feature_Matching/07_Feature_Matching.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/07_Feature_Matching/07_Feature_Matching.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/07_Feature_Matching/box.png b/07_Feature_Matching/box.png new file mode 100644 index 0000000..6f01082 Binary files /dev/null and b/07_Feature_Matching/box.png differ diff --git a/07_Feature_Matching/box_in_scene.png b/07_Feature_Matching/box_in_scene.png new file mode 100644 index 0000000..cff246a Binary files /dev/null and b/07_Feature_Matching/box_in_scene.png differ diff --git a/07_Feature_Matching/building.jpg b/07_Feature_Matching/building.jpg new file mode 100644 index 0000000..6056492 Binary files /dev/null and b/07_Feature_Matching/building.jpg differ diff --git a/07_Feature_Matching/dst1.png b/07_Feature_Matching/dst1.png new file mode 100644 index 0000000..b99a12a Binary files /dev/null and b/07_Feature_Matching/dst1.png differ diff --git a/07_Feature_Matching/dst2.png b/07_Feature_Matching/dst2.png new file mode 100644 index 0000000..980be43 Binary files /dev/null and b/07_Feature_Matching/dst2.png differ diff --git a/07_Feature_Matching/dst3.png b/07_Feature_Matching/dst3.png new file mode 100644 index 0000000..413e09b Binary files /dev/null and b/07_Feature_Matching/dst3.png differ diff --git a/07_Feature_Matching/feature-matching.cpp b/07_Feature_Matching/feature-matching.cpp new file mode 100644 index 0000000..ddda231 --- /dev/null +++ b/07_Feature_Matching/feature-matching.cpp @@ -0,0 +1,113 @@ +#include +using namespace std; + +#include +#include +using namespace cv; + +void corner_fast() +{ + Mat src = imread("building.jpg", IMREAD_GRAYSCALE); + + if (src.empty()) + { + cerr << "Image load failed !" << endl; + return; + } + + vector keypoints; + FAST(src, keypoints, 60, true); + + Mat dst; + cvtColor(src, dst, COLOR_GRAY2BGR); + + for (KeyPoint kp : keypoints) + { + Point pt(cvRound(kp.pt.x), cvRound(kp.pt.y)); + circle(dst, pt, 5, Scalar(0, 0, 255), 2); + } + + imshow("src", src); + imshow("dst", dst); + imwrite("dst1.png", dst); + + waitKey(0); + destroyAllWindows(); +} + +void detect_keypoints() +{ + Mat src = imread("box_in_scene.png", IMREAD_GRAYSCALE); + + if (src.empty()) + { + cerr << "Image load failed !" << endl; + return; + } + + Ptr feature = ORB::create(); + + vector keypoints; + feature->detect(src, keypoints); + + Mat desc; + feature->compute(src, keypoints, desc); + + cout << "keypoints.size(): " << keypoints.size() << endl; + cout << "desc.size(): " << desc.size() << endl; + + Mat dst; + drawKeypoints(src, keypoints, dst, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS); + + imshow("src", src); + imshow("dst", dst); + imwrite("dst2.png", dst); + + waitKey(); + destroyAllWindows(); +} + +void keypoint_matching() +{ + Mat src1 = imread("box.png", IMREAD_GRAYSCALE); + Mat src2 = imread("box_in_scene.png", IMREAD_GRAYSCALE); + + if (src1.empty() || src2.empty()) + { + cerr << "Image load failed !" << endl; + return; + } + + Ptr feature = ORB::create(); + + vector keypoints1, keypoints2; + Mat desc1, desc2; + feature->detectAndCompute(src1, Mat(), keypoints1, desc1); + feature->detectAndCompute(src2, Mat(), keypoints2, desc2); + + Ptr matcher = BFMatcher::create(NORM_HAMMING); + + vector matches; + matcher->match(desc1, desc2, matches); + + Mat dst; + drawMatches(src1, keypoints1, src2, keypoints2, matches, dst); + + imshow("dst", dst); + imwrite("dst3.png", dst); + + waitKey(); + destroyAllWindows(); +} + +int main() +{ + // ex 14-2) FAST + corner_fast(); + + // ex 14-4) ORB, Keypoints + detect_keypoints(); + + // ex 14-6) ORB, Keypoint Matching + keypoint_matching(); +} \ No newline at end of file diff --git a/x64/Debug/07_Feature_Matching.exe b/x64/Debug/07_Feature_Matching.exe new file mode 100644 index 0000000..11c7ed1 Binary files /dev/null and b/x64/Debug/07_Feature_Matching.exe differ diff --git a/x64/Debug/07_Feature_Matching.pdb b/x64/Debug/07_Feature_Matching.pdb new file mode 100644 index 0000000..8e571fd Binary files /dev/null and b/x64/Debug/07_Feature_Matching.pdb differ diff --git a/x64/Debug/opencv_world460d.dll b/x64/Debug/opencv_world460d.dll new file mode 100644 index 0000000..6921313 Binary files /dev/null and b/x64/Debug/opencv_world460d.dll differ