|
@@ -0,0 +1,126 @@
|
|
1
|
+#include "WaferRebuild.h"
|
|
2
|
+#include <fstream>
|
|
3
|
+#include <iostream>
|
|
4
|
+#include <regex>
|
|
5
|
+#include <opencv2/opencv.hpp>
|
|
6
|
+#include <dirent.h>
|
|
7
|
+#include <thread>
|
|
8
|
+
|
|
9
|
+// 自定义比较函数
|
|
10
|
+bool numeric_string_compare(const std::string& s1, const std::string& s2) {
|
|
11
|
+ // 正则表达式匹配所有数字
|
|
12
|
+ std::regex re("(\\d+)");
|
|
13
|
+ std::sregex_iterator it1(s1.begin(), s1.end(), re), it2(s2.begin(), s2.end(), re);
|
|
14
|
+ std::sregex_iterator reg_end;
|
|
15
|
+
|
|
16
|
+ while (it1 != reg_end && it2 != reg_end) {
|
|
17
|
+ int num1 = std::stoi(it1->str());
|
|
18
|
+ int num2 = std::stoi(it2->str());
|
|
19
|
+ if (num1 != num2)
|
|
20
|
+ return num1 < num2;
|
|
21
|
+ ++it1;
|
|
22
|
+ ++it2;
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ // 如果所有数字相等,按字典顺序排序
|
|
26
|
+ return s1 < s2;
|
|
27
|
+}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+int read_files_in_dir(const char* p_dir_name, std::vector<std::string>& file_names) {
|
|
31
|
+ DIR* p_dir = opendir(p_dir_name);
|
|
32
|
+ if (p_dir == nullptr) {
|
|
33
|
+ return -1;
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ struct dirent* p_file = nullptr;
|
|
37
|
+ while ((p_file = readdir(p_dir)) != nullptr) {
|
|
38
|
+ if (strcmp(p_file->d_name, ".") != 0 &&
|
|
39
|
+ strcmp(p_file->d_name, "..") != 0) {
|
|
40
|
+ //std::string cur_file_name(p_dir_name);
|
|
41
|
+ //cur_file_name += "/";
|
|
42
|
+ //cur_file_name += p_file->d_name;
|
|
43
|
+ std::string cur_file_name(p_file->d_name);
|
|
44
|
+ file_names.push_back(cur_file_name);
|
|
45
|
+ }
|
|
46
|
+ }
|
|
47
|
+ std::sort(file_names.begin(), file_names.end(), numeric_string_compare);
|
|
48
|
+ closedir(p_dir);
|
|
49
|
+ return 0;
|
|
50
|
+}
|
|
51
|
+
|
|
52
|
+int main()
|
|
53
|
+{
|
|
54
|
+ WaferRebuild wr;
|
|
55
|
+ nlohmann::json cfg;
|
|
56
|
+ // A:/code/win_pratice/PmdPratice/cpp/WaferRebuild/x64/WaferRebuilddll/resource
|
|
57
|
+ std::ifstream is("A:/code/win_pratice/PmdPratice/cpp/WaferRebuilddll_bak/WaferRebuilddll/resource/cfg.json");
|
|
58
|
+ is >> cfg;
|
|
59
|
+ auto a = wr.initParam(cfg);
|
|
60
|
+
|
|
61
|
+ std::vector<std::string> file_names;
|
|
62
|
+ const char* image_path = "A:/code/win_pratice/PmdPratice/cpp/WaferRebuilddll_bak/WaferRebuilddll/resource/img_pats/";
|
|
63
|
+ if (read_files_in_dir(image_path, file_names) < 0) {
|
|
64
|
+ std::cout << "read_files_in_dir failed." << std::endl;
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+ std::vector< std::shared_ptr<infra::Image>> image_list;
|
|
69
|
+ for (int f = 0; f < (int)file_names.size(); f++) {
|
|
70
|
+
|
|
71
|
+ std::shared_ptr<infra::Image> frame = std::make_shared<infra::Image>(2048 * 2448);
|
|
72
|
+ cv::Mat colorImage;
|
|
73
|
+ cv::Mat img = cv::imread(std::string(image_path) + "/" + file_names[f],0);
|
|
74
|
+ if (img.empty()) continue;
|
|
75
|
+
|
|
76
|
+ // cv::cvtColor(img, colorImage, cv::COLOR_GRAY2BGR);
|
|
77
|
+ // memcpy(frame->data(), colorImage.data, colorImage.rows * colorImage.cols * colorImage.channels());
|
|
78
|
+ memcpy(frame->data(), img.data, img.rows * img.cols * img.channels());
|
|
79
|
+ image_list.push_back(frame);
|
|
80
|
+ }
|
|
81
|
+ std::shared_ptr<infra::CloudPoint<double>> cloud_points0 = std::make_shared<infra::CloudPoint<double>>();
|
|
82
|
+ auto result = wr.calcCloud(image_list, cloud_points0, 0);
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+ /*
|
|
86
|
+ const int numThreads = 4;
|
|
87
|
+ std::vector<std::thread> threads;
|
|
88
|
+ // 创建多个 cloud_points 对象
|
|
89
|
+ std::shared_ptr<infra::CloudPoint<double>> cloud_points0 = std::make_shared<infra::CloudPoint<double>>();
|
|
90
|
+ std::shared_ptr<infra::CloudPoint<double>> cloud_points1 = std::make_shared<infra::CloudPoint<double>>();
|
|
91
|
+ std::shared_ptr<infra::CloudPoint<double>> cloud_points2 = std::make_shared<infra::CloudPoint<double>>();
|
|
92
|
+ std::shared_ptr<infra::CloudPoint<double>> cloud_points3 = std::make_shared<infra::CloudPoint<double>>();
|
|
93
|
+
|
|
94
|
+ // 将 cloud_points 放入 vector
|
|
95
|
+ std::vector<std::shared_ptr<infra::CloudPoint<double>>> cloud_points = { cloud_points0, cloud_points1, cloud_points2, cloud_points3 };
|
|
96
|
+
|
|
97
|
+ // 创建多个线程并运行 calcCloud 函数,每个线程传递不同的参数组合
|
|
98
|
+ for (int i = 0; i < numThreads; ++i) {
|
|
99
|
+ threads.push_back(std::thread([&wr, &image_list, &cloud_points, i]() {
|
|
100
|
+ auto result = wr.calcCloud(image_list, cloud_points[i], i);
|
|
101
|
+ // 可以在这里处理函数返回的结果,如输出或其他逻辑
|
|
102
|
+ std::cout << "Thread " << i << " finished with result: " << std::get<0>(result) << ", " << std::get<1>(result) << "\n";
|
|
103
|
+ }));
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ // 等待所有线程完成
|
|
107
|
+ for (auto& thread : threads) {
|
|
108
|
+ thread.join();
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ std::map<int32_t, std::shared_ptr<infra::CloudPoint<double>>> cloud_points_list = {
|
|
112
|
+ {0, cloud_points0},
|
|
113
|
+ {1, cloud_points1},
|
|
114
|
+ {2, cloud_points2},
|
|
115
|
+ {3, cloud_points3}
|
|
116
|
+ };;
|
|
117
|
+ std::shared_ptr<infra::CloudPoint<double>> cloud_out = std::make_shared<infra::CloudPoint<double>>();
|
|
118
|
+
|
|
119
|
+ auto m_ret = wr.mergeCloud(cloud_points_list, cloud_out);
|
|
120
|
+ std::cout << "Merge sucess!" << std::endl;
|
|
121
|
+ std::cout << std::get<0>(m_ret) << ", " << std::get<1>(m_ret) << "\n";
|
|
122
|
+ */
|
|
123
|
+ std::cout << "Success!" << std::endl;
|
|
124
|
+ system("pause");
|
|
125
|
+ return 0;
|
|
126
|
+}
|