|
@@ -3,7 +3,10 @@
|
|
|
#include <iostream>
|
|
|
#include <fstream>
|
|
|
#include <vector>
|
|
|
+#include <map>
|
|
|
#include <filesystem>
|
|
|
+#include <opencv2/imgproc/imgproc.hpp>
|
|
|
+#include <opencv2/highgui/highgui.hpp>
|
|
|
|
|
|
using namespace cv;
|
|
|
using namespace cv::xfeatures2d;
|
|
@@ -14,6 +17,8 @@ typedef void process(const path& input, const path& output);
|
|
|
|
|
|
const auto detector1 = SIFT::create();
|
|
|
const auto detector2 = SURF::create();
|
|
|
+
|
|
|
+const auto matcher = FlannBasedMatcher::create();
|
|
|
/// <summary>
|
|
|
/// 提取图片特征描述符
|
|
|
/// </summary>
|
|
@@ -114,6 +119,7 @@ void process_image3(const path& image, const path& output) {
|
|
|
// cout << element << endl;
|
|
|
// }
|
|
|
//}
|
|
|
+
|
|
|
cout << "after: " << descriptor_cat.type() << " - " << descriptor_cat.channels() << endl;
|
|
|
|
|
|
FileStorage file_storage(output.string(), FileStorage::WRITE);
|
|
@@ -191,18 +197,61 @@ void process_mat(string input_dir, string output_dir, const string& suffix, proc
|
|
|
deep_copy(input_dir_path, output_dir_path, suffix, process);
|
|
|
}
|
|
|
|
|
|
+void test(string img, string temp) {
|
|
|
+ Mat mat = imread(img);
|
|
|
+
|
|
|
+ vector<KeyPoint> keypoints_cat;
|
|
|
+ Mat descriptor_cat;
|
|
|
+ detector1->detectAndCompute(mat, Mat(), keypoints_cat, descriptor_cat);
|
|
|
+
|
|
|
+ map<string, Mat> temps;
|
|
|
+ for (auto& it : directory_iterator(path(temp))) {
|
|
|
+ Mat t = imread(it.path().string());
|
|
|
+ vector<KeyPoint> kp;
|
|
|
+ Mat des;
|
|
|
+ detector1->detectAndCompute(t, Mat(), kp, des);
|
|
|
+ temps.emplace(it.path().string().c_str(), des);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (auto it2 = temps.begin(); it2 != temps.end(); ++it2) {
|
|
|
+ auto name = it2->first;
|
|
|
+ auto value = it2->second;
|
|
|
+
|
|
|
+ vector<vector<DMatch>> result;
|
|
|
+ matcher->knnMatch(value, descriptor_cat, result, 2);
|
|
|
+
|
|
|
+ int count = 0;
|
|
|
+
|
|
|
+ for (auto match : result) {
|
|
|
+ if (match.at(0).distance < 0.7f * match.at(1).distance) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ cout << name << " ----- " << count << endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
int main(int argc, char** argv) {
|
|
|
- string input_dir = "D:\\Work\\Cards";
|
|
|
+ //string img = "C:\\Users\\zhaoyadi\\Desktop\\undefined.png";
|
|
|
+ //string temp = "D:\\process\\origin\\A-1-3";
|
|
|
+ //test(img, temp);
|
|
|
+
|
|
|
+ string input_dir = "D:\\process\\origin";
|
|
|
//string output_dir = "D:\\Work\\Outputs";
|
|
|
- string output_dir1 = "D:\\Work\\SIFT";
|
|
|
- string output_dir2 = "D:\\Work\\SURF";
|
|
|
- string output_dir3 = "D:\\Work\\SIFT-XML";
|
|
|
- string output_dir4 = "D:\\Work\\SURF-XML";
|
|
|
+ string output_dir1 = "D:\\process\\SIFT";
|
|
|
+ //string output_dir2 = "D:\\process\\SURF";
|
|
|
+ //string output_dir3 = "D:\\process\\SIFT-XML";
|
|
|
+ //string output_dir4 = "D:\\process\\SURF-XML";
|
|
|
+ //string output_dir5 = "D:\\process\\SIFT-JSON";
|
|
|
+ //string output_dir6 = "D:\\process\\SURF-JSON";
|
|
|
|
|
|
process_mat(input_dir, output_dir1, "png", process_image1);
|
|
|
- process_mat(input_dir, output_dir2, "png", process_image2);
|
|
|
- process_mat(input_dir, output_dir3, "xml", process_image3);
|
|
|
- process_mat(input_dir, output_dir4, "xml", process_image4);
|
|
|
+ //process_mat(input_dir, output_dir2, "png", process_image2);
|
|
|
+ //process_mat(input_dir, output_dir3, "xml", process_image3);
|
|
|
+ //process_mat(input_dir, output_dir4, "xml", process_image4);
|
|
|
+ //process_mat(input_dir, output_dir5, "json", process_image3);
|
|
|
+ //process_mat(input_dir, output_dir6, "json", process_image4);
|
|
|
|
|
|
return 0;
|
|
|
}
|