{"id":140,"date":"2025-09-19T15:28:47","date_gmt":"2025-09-19T07:28:47","guid":{"rendered":"https:\/\/caoxunyi.cn\/?p=140"},"modified":"2025-10-01T02:19:57","modified_gmt":"2025-09-30T18:19:57","slug":"%e5%9c%a8arch%e4%b8%8a%e4%bb%8e%e9%9b%b6%e6%9e%84%e5%bb%ba-c-%e4%ba%ba%e8%84%b8%e8%af%86%e5%88%ab%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/caoxunyi.cn\/index.php\/140\/","title":{"rendered":"\u5728Arch\u4e0a\u4ece\u96f6\u6784\u5efa C++ \u4eba\u8138\u8bc6\u522b\u5e94\u7528"},"content":{"rendered":"<p>\u672c\u6559\u7a0b\u5c06\u57fa\u4e8e\u5e26\u60a8\u5b8c\u6210\u4ece\u73af\u5883\u914d\u7f6e\u5230\u6700\u7ec8\u8fd0\u884c\u7a0b\u5e8f\u7684\u5168\u90e8\u6d41\u7a0b\u3002<\/p>\n<h4><strong>\u7b2c 0 \u6b65\uff1a\u51c6\u5907\u60a8\u7684\u7cfb\u7edf<\/strong><\/h4>\n<p>\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u7684 Arch Linux \u7cfb\u7edf\u662f\u6700\u65b0\u7684\u3002\u8fd9\u662f\u4e00\u4e2a\u597d\u4e60\u60ef\uff0c\u53ef\u4ee5\u907f\u514d\u5f88\u591a\u6f5c\u5728\u7684\u8f6f\u4ef6\u7248\u672c\u51b2\u7a81\u95ee\u9898\u3002<\/p>\n<p>\u6253\u5f00\u60a8\u7684\u7ec8\u7aef (Konsole)\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u6309\u56de\u8f66\u3002<\/p>\n<p>Bash<\/p>\n<pre><code>sudo pacman -Syu<\/code><\/pre>\n<ul>\n<li><code>sudo<\/code>: \u4ee5\u7ba1\u7406\u5458\u6743\u9650\u8fd0\u884c\u547d\u4ee4\uff0c\u56e0\u4e3a\u5b89\u88c5\u8f6f\u4ef6\u9700\u8981\u8fd9\u4e2a\u6743\u9650\u3002<\/li>\n<li><code>pacman<\/code>: Arch Linux \u7684\u5305\u7ba1\u7406\u5668\uff0c\u76f8\u5f53\u4e8e\u60a8\u7cfb\u7edf\u7684\u201c\u5e94\u7528\u5546\u5e97\u201d\u3002<\/li>\n<li><code>-Syu<\/code>: <code>-S<\/code> \u4ee3\u8868\u540c\u6b65 (Sync)\uff0c<code>-y<\/code> \u4ee3\u8868\u5237\u65b0\u8f6f\u4ef6\u5305\u5217\u8868\uff0c<code>-u<\/code> \u4ee3\u8868\u5347\u7ea7 (Update) \u6240\u6709\u5df2\u5b89\u88c5\u7684\u5305\u3002<\/li>\n<\/ul>\n<p>\u7cfb\u7edf\u4f1a\u63d0\u793a\u60a8\u8f93\u5165\u5bc6\u7801\uff0c\u8f93\u5165\u540e\u6309\u56de\u8f66\u5373\u53ef\u3002\u7b49\u5f85\u7cfb\u7edf\u66f4\u65b0\u5b8c\u6210\u3002<\/p>\n<h4><strong>\u7b2c 1 \u6b65\uff1a\u5b89\u88c5\u5fc5\u8981\u7684\u5f00\u53d1\u5de5\u5177\u548c\u5e93<\/strong><\/h4>\n<p>\u6211\u4eec\u9700\u8981 C++ \u7f16\u8bd1\u5668\u3001\u9879\u76ee\u6784\u5efa\u5de5\u5177 (CMake) \u548c\u6838\u5fc3\u7684\u56fe\u50cf\u5904\u7406\u5e93 (OpenCV)\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>Bash<\/p>\n<pre><code>sudo pacman -S base-devel cmake opencv<\/code><\/pre>\n<ul>\n<li><code>base-devel<\/code>: \u8fd9\u662f\u4e00\u4e2a\u8f6f\u4ef6\u5305\u7ec4\uff0c\u5305\u542b\u4e86 <code>gcc<\/code> (C++ \u7f16\u8bd1\u5668), <code>make<\/code> (\u7f16\u8bd1\u5de5\u5177) \u7b49\u4e00\u7cfb\u5217\u6700\u57fa\u7840\u7684\u5f00\u53d1\u5de5\u5177\u3002<\/li>\n<li><code>cmake<\/code>: \u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u9879\u76ee\u6784\u5efa\u5de5\u5177\uff0c\u5b83\u80fd\u8bfb\u53d6\u6211\u4eec\u540e\u7eed\u7f16\u5199\u7684\u914d\u7f6e\u6587\u4ef6 (<code>CMakeLists.txt<\/code>) \u5e76\u751f\u6210 <code>make<\/code> \u6240\u9700\u7684 <code>Makefile<\/code>\u3002<\/li>\n<li><code>opencv<\/code>: \u6211\u4eec\u9879\u76ee\u6700\u6838\u5fc3\u7684\u4f9d\u8d56\u5e93\uff0c\u63d0\u4f9b\u4e86\u6240\u6709\u56fe\u50cf\u5904\u7406\u548c\u4eba\u8138\u8bc6\u522b\u7684\u529f\u80fd\u3002<\/li>\n<\/ul>\n<h4><strong>\u7b2c 2 \u6b65\uff1a\u521b\u5efa\u9879\u76ee\u6587\u4ef6\u5939\u7ed3\u6784<\/strong><\/h4>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u9700\u8981\u4e3a\u9879\u76ee\u521b\u5efa\u4e00\u4e2a\u5e72\u51c0\u6574\u6d01\u7684\u5de5\u4f5c\u7a7a\u95f4\u3002<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u4e00\u4e2a\u4e3b\u6587\u4ef6\u5939<\/strong>\u3002\u6211\u4eec\u628a\u5b83\u653e\u5728\u60a8\u7684\u4e3b\u76ee\u5f55 (<code>~<\/code>) \u4e0b\uff0c\u5e76\u547d\u540d\u4e3a <code>FaceRecProject<\/code>\u3002<\/p>\n<p>Bash<\/p>\n<pre><code># cd ~ \u4f1a\u786e\u4fdd\u60a8\u5f53\u524d\u5728\u4e3b\u76ee\u5f55\u4e0b\ncd ~\nmkdir FaceRecProject<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u8fdb\u5165\u8fd9\u4e2a\u4e3b\u6587\u4ef6\u5939<\/strong>\u3002\u4e4b\u540e\u7684\u6240\u6709\u64cd\u4f5c\u90fd\u5728\u8fd9\u91cc\u8fdb\u884c\u3002<\/p>\n<p>Bash<\/p>\n<pre><code>cd FaceRecProject<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u9879\u76ee\u6240\u9700\u7684\u5b50\u6587\u4ef6\u5939<\/strong>\u3002<\/p>\n<p>Bash<\/p>\n<pre><code>mkdir build\nmkdir data\nmkdir cascades<\/code><\/pre>\n<ul>\n<li><code>build<\/code>: \u7528\u4e8e\u5b58\u653e\u6240\u6709\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u4ea7\u751f\u7684\u4e34\u65f6\u6587\u4ef6\u548c\u6700\u7ec8\u751f\u6210\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\uff0c\u8ba9\u4e3b\u76ee\u5f55\u4fdd\u6301\u5e72\u51c0\u3002<\/li>\n<li><code>data<\/code>: \u7528\u4e8e\u5b58\u653e\u6211\u4eec\u63d0\u4f9b\u7ed9\u7a0b\u5e8f\u5b66\u4e60\u7684\u4eba\u8138\u7167\u7247\u3002<\/li>\n<li><code>cascades<\/code>: \u7528\u4e8e\u5b58\u653e OpenCV \u5b98\u65b9\u63d0\u4f9b\u7684\u4eba\u8138\u68c0\u6d4b\u6a21\u578b\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4><strong>\u7b2c 3 \u6b65\uff1a\u4e0b\u8f7d\u4eba\u8138\u68c0\u6d4b\u6a21\u578b<\/strong><\/h4>\n<p>\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u9884\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u6765\u544a\u8bc9\u7a0b\u5e8f\u201c\u4eba\u8138\u957f\u4ec0\u4e48\u6837\u201d\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u4e2d\uff08\u786e\u4fdd\u60a8\u4ecd\u5728 <code>FaceRecProject<\/code> \u6587\u4ef6\u5939\u4e0b\uff09\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>Bash<\/p>\n<pre><code>wget -P .\/cascades https:\/\/raw.githubusercontent.com\/opencv\/opencv\/master\/data\/haarcascades\/haarcascade_frontalface_alt.xml<\/code><\/pre>\n<ul>\n<li><code>wget<\/code>: \u4e00\u4e2a\u4ece\u7f51\u7edc\u4e0a\u4e0b\u8f7d\u6587\u4ef6\u7684\u547d\u4ee4\u884c\u5de5\u5177\u3002<\/li>\n<li><code>-P .\/cascades<\/code>: <code>-P<\/code> \u53c2\u6570\u544a\u8bc9 <code>wget<\/code> \u628a\u4e0b\u8f7d\u7684\u6587\u4ef6\u653e\u5230\u6307\u5b9a\u7684\u6587\u4ef6\u5939\u91cc\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u521a\u521b\u5efa\u7684 <code>cascades<\/code> \u6587\u4ef6\u5939\u3002<\/li>\n<li><code>https:\/\/...<\/code>: \u8fd9\u662f\u6a21\u578b\u6587\u4ef6\u7684\u4e0b\u8f7d\u5730\u5740\u3002<\/li>\n<\/ul>\n<h4><strong>\u7b2c 4 \u6b65\uff1a\u7f16\u5199\u9879\u76ee\u4ee3\u7801<\/strong><\/h4>\n<p>\u73b0\u5728\u6211\u4eec\u8981\u521b\u5efa\u4e09\u4e2a\u6838\u5fc3\u7684\u6587\u672c\u6587\u4ef6\uff1a\u6784\u5efa\u811a\u672c\u548c\u4e24\u4e2a C++ \u6e90\u4ee3\u7801\u6587\u4ef6\u3002<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u6784\u5efa\u811a\u672c <code>CMakeLists.txt<\/code><\/strong><\/p>\n<p>Bash<\/p>\n<pre><code># \u4f7f\u7528 nano \u6587\u672c\u7f16\u8f91\u5668\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\nnano CMakeLists.txt<\/code><\/pre>\n<p>\u5c06\u4e0b\u9762\u7684\u4ee3\u7801<strong>\u5b8c\u6574\u5730\u590d\u5236<\/strong>\u5e76\u7c98\u8d34\u5230 <code>nano<\/code> \u7f16\u8f91\u5668\u7a97\u53e3\u4e2d\uff1a<\/p>\n<p>CMake<\/p>\n<pre><code>cmake_minimum_required(VERSION 3.10)\nproject(FaceRecognition)\nset(CMAKE_CXX_STANDARD 17)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nfind_package(OpenCV REQUIRED COMPONENTS core highgui imgproc objdetect videoio face)\ninclude_directories(${OpenCV_INCLUDE_DIRS})\nadd_executable(train_model train_model.cpp)\ntarget_link_libraries(train_model ${OpenCV_LIBS} stdc++fs)\nadd_executable(recognize_face recognize_face.cpp)\ntarget_link_libraries(recognize_face ${OpenCV_LIBS})<\/code><\/pre>\n<p>\u7c98\u8d34\u5b8c\u6210\u540e\uff0c\u6309 <code>Ctrl+X<\/code>\uff0c\u7136\u540e\u6309 <code>Y<\/code>\uff0c\u6700\u540e\u6309 <code>\u56de\u8f66<\/code> \u6765\u4fdd\u5b58\u5e76\u9000\u51fa\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u8bad\u7ec3\u7a0b\u5e8f <code>train_model.cpp<\/code><\/strong><\/p>\n<p>Bash<\/p>\n<pre><code>nano train_model.cpp<\/code><\/pre>\n<p>\u5c06\u4e0b\u9762\u7684\u4ee3\u7801<strong>\u5b8c\u6574\u5730\u590d\u5236<\/strong>\u5e76\u7c98\u8d34\u8fdb\u53bb\uff1a<\/p>\n<p>C++<\/p>\n<pre><code>#include \n&lt;iostream&gt;\n#include \n&lt;fstream&gt;\n#include \n&lt;sstream&gt;\n#include \n&lt;vector&gt;\n#include \n&lt;string&gt;\n#include \n&lt;filesystem&gt;\n#include &lt;opencv2\/core.hpp&gt;\n#include &lt;opencv2\/imgcodecs.hpp&gt;\n#include &lt;opencv2\/imgproc.hpp&gt;\n#include &lt;opencv2\/face.hpp&gt;\n\nusing namespace cv;\nusing namespace cv::face;\nusing namespace std;\nnamespace fs = std::filesystem;\n\nvoid create_dataset_csv(const string&amp; data_path, const string&amp; output_file) {\n   ofstream csv_file(output_file);\n   int label = 0;\n   for (const auto&amp; entry : fs::directory_iterator(data_path)) {\n       if (entry.is_directory()) {\n           for (const auto&amp; img_entry : fs::directory_iterator(entry.path())) {\n               if (img_entry.is_regular_file()) {\n                   csv_file &lt;&lt; img_entry.path().string() &lt;&lt; &quot;;&quot; &lt;&lt; label &lt;&lt; endl;\n               }\n           }\n           label++;\n       }\n   }\n   csv_file.close();\n   cout &lt;&lt; &quot;Dataset CSV file created at &quot; &lt;&lt; output_file &lt;&lt; endl;\n}\n\nstatic void read_csv(const string&amp; filename, vector\n&lt;Mat&gt;&amp; images, vector&lt;int&gt;&amp; labels, char separator = ';') {\n   ifstream file(filename.c_str(), ifstream::in);\n   string line, path, classlabel;\n   while (getline(file, line)) {\n       stringstream liness(line);\n       getline(liness, path, separator);\n       getline(liness, classlabel);\n       if(!path.empty() &amp;&amp; !classlabel.empty()) {\n           images.push_back(imread(path, IMREAD_GRAYSCALE));\n           labels.push_back(atoi(classlabel.c_str()));\n       }\n   }\n}\n\nint main() {\n   string data_dir = &quot;.\/data&quot;;\n   string csv_file_path = &quot;.\/data.csv&quot;;\n   create_dataset_csv(data_dir, csv_file_path);\n\n   vector\n&lt;Mat&gt; images;\n   vector\n&lt;int&gt; labels;\n   try {\n       read_csv(csv_file_path, images, labels);\n   } catch (const cv::Exception&amp; e) {\n       cerr &lt;&lt; &quot;Error opening file \\&quot;&quot; &lt;&lt; csv_file_path &lt;&lt; &quot;\\&quot;. Reason: &quot; &lt;&lt; e.msg &lt;&lt; endl;\n       exit(1);\n   }\n   if(images.size() &lt;= 1) {\n       cerr &lt;&lt; &quot;Error: This program needs at least 2 images to train. Please add more images to your data directory.&quot; &lt;&lt; endl;\n       exit(1);\n   }\n\n   Ptr\n&lt;LBPHFaceRecognizer&gt; model = LBPHFaceRecognizer::create();\n   cout &lt;&lt; &quot;Training the model...&quot; &lt;&lt; endl;\n   model-&gt;train(images, labels);\n   string model_filename = &quot;face_model.yml&quot;;\n   model-&gt;save(model_filename);\n   cout &lt;&lt; &quot;Model trained and saved to &quot; &lt;&lt; model_filename &lt;&lt; endl;\n   return 0;\n}<\/code><\/pre>\n<p>\u540c\u6837\u6309 <code>Ctrl+X<\/code>, <code>Y<\/code>, <code>\u56de\u8f66<\/code> \u4fdd\u5b58\u9000\u51fa\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u8bc6\u522b\u7a0b\u5e8f <code>recognize_face.cpp<\/code><\/strong><\/p>\n<p>Bash<\/p>\n<pre><code>nano recognize_face.cpp<\/code><\/pre>\n<p>\u5c06\u4e0b\u9762\u7684\u4ee3\u7801<strong>\u5b8c\u6574\u5730\u590d\u5236<\/strong>\u5e76\u7c98\u8d34\u8fdb\u53bb\uff1a<\/p>\n<p>C++<\/p>\n<pre><code>#include \n&lt;iostream&gt;\n#include \n&lt;map&gt;\n#include \n&lt;string&gt;\n#include \n&lt;filesystem&gt;\n#include \n&lt;chrono&gt;\n#include \n&lt;iomanip&gt;\n#include \n&lt;sstream&gt;\n#include &lt;opencv2\/core.hpp&gt;\n#include &lt;opencv2\/highgui.hpp&gt;\n#include &lt;opencv2\/imgproc.hpp&gt;\n#include &lt;opencv2\/objdetect.hpp&gt;\n#include &lt;opencv2\/face.hpp&gt;\n\nusing namespace std;\nusing namespace cv;\nusing namespace cv::face;\nnamespace fs = std::filesystem;\n\nint main() {\n   string cascade_path = &quot;.\/cascades\/haarcascade_frontalface_alt.xml&quot;;\n   string model_path = &quot;face_model.yml&quot;;\n   CascadeClassifier face_cascade;\n   if (!face_cascade.load(cascade_path)) {\n       cerr &lt;&lt; &quot;Error: Could not load face cascade.&quot; &lt;&lt; endl;\n       return -1;\n   }\n\n   Ptr\n&lt;FaceRecognizer&gt; model = LBPHFaceRecognizer::create();\n   try {\n       model-&gt;read(model_path);\n   } catch (const cv::Exception&amp; e) {\n       cerr &lt;&lt; &quot;Error: Could not load trained model. Have you trained the model yet?&quot; &lt;&lt; endl;\n       return -1;\n   }\n\n   map&lt;int, string&gt; label_to_name;\n   label_to_name[0] = &quot;Person 1&quot;; \/\/ \u53ef\u5728\u6b64\u5904\u4fee\u6539\u8bc6\u522b\u51fa\u7684\u540d\u5b57\n   label_to_name[1] = &quot;Person 2&quot;;\n\n   string strangers_dir = &quot;strangers&quot;;\n   if (!fs::exists(strangers_dir)) {\n       fs::create_directory(strangers_dir);\n   }\n   auto last_stranger_save_time = chrono::steady_clock::now();\n   const auto save_cooldown = chrono::seconds(5);\n\n   VideoCapture cap(0);\n   if (!cap.isOpened()) {\n       cerr &lt;&lt; &quot;Error: Could not open camera.&quot; &lt;&lt; endl;\n       return -1;\n   }\n\n   Mat frame;\n   while (true) {\n       cap &gt;&gt; frame;\n       if (frame.empty()) break;\n\n       Mat gray;\n       cvtColor(frame, gray, COLOR_BGR2GRAY);\n       equalizeHist(gray, gray);\n\n       vector\n&lt;Rect&gt; faces;\n       face_cascade.detectMultiScale(gray, faces, 1.1, 4, 0|CASCADE_SCALE_IMAGE, Size(30, 30));\n\n       for (const auto&amp; face_rect : faces) {\n           Mat face_roi = gray(face_rect);\n           Mat resized_face;\n           resize(face_roi, resized_face, Size(92, 112), 1.0, 1.0, INTER_CUBIC);\n\n           int predicted_label = -1;\n           double confidence = 0.0;\n           model-&gt;predict(resized_face, predicted_label, confidence);\n\n           rectangle(frame, face_rect, Scalar(0, 255, 0), 2);\n\n           string text;\n           if (predicted_label != -1 &amp;&amp; confidence &lt; 85.0) {\n                string name = label_to_name.count(predicted_label) ? label_to_name[predicted_label] : &quot;Known Person&quot;;\n                text = format(&quot;%s (Conf: %.2f)&quot;, name.c_str(), confidence);\n           } else {\n               text = &quot;Stranger&quot;;\n               auto now = chrono::steady_clock::now();\n               if (chrono::duration_cast&lt;chrono::seconds&gt;(now - last_stranger_save_time) &gt; save_cooldown) {\n                   auto time_now_t = chrono::system_clock::to_time_t(chrono::system_clock::now());\n                   stringstream ss;\n                   ss &lt;&lt; put_time(localtime(&amp;time_now_t), &quot;%Y%m%d_%H%M%S&quot;);\n                   string filename = strangers_dir + &quot;\/stranger_&quot; + ss.str() + &quot;.jpg&quot;;\n                   imwrite(filename, frame(face_rect));\n                   cout &lt;&lt; &quot;Stranger detected! Image saved to &quot; &lt;&lt; filename &lt;&lt; endl;\n                   last_stranger_save_time = now;\n               }\n           }\n\n           Point text_pos(face_rect.x, face_rect.y - 10);\n           putText(frame, text, text_pos, FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 255, 0), 2);\n       }\n\n       imshow(&quot;Face Recognition&quot;, frame);\n\n       if (waitKey(10) == 'q') break;\n   }\n   return 0;\n}<\/code><\/pre>\n<p>\u6309 <code>Ctrl+X<\/code>, <code>Y<\/code>, <code>\u56de\u8f66<\/code> \u4fdd\u5b58\u9000\u51fa\u3002<\/p>\n<\/li>\n<\/ol>\n<h4><strong>\u7b2c 5 \u6b65\uff1a\u51c6\u5907\u8bad\u7ec3\u6570\u636e<\/strong><\/h4>\n<p>\u8fd9\u662f\u6559\u7a0b\u5e8f\u8ba4\u8bc6\u4eba\u8138\u7684\u5173\u952e\u3002<\/p>\n<ol>\n<li>\n<p>\u5728 <code>data<\/code> \u6587\u4ef6\u5939\u91cc\uff0c<strong>\u4e3a\u6bcf\u4e00\u4e2a\u4eba\u521b\u5efa\u4e00\u4e2a\u5355\u72ec\u7684\u5b50\u6587\u4ef6\u5939<\/strong>\u3002\u6587\u4ef6\u5939\u7684\u540d\u5b57\u6700\u597d\u662f\u82f1\u6587\uff0c\u6bd4\u5982 <code>zhangsan<\/code>, <code>lisi<\/code>\u3002<\/p>\n<p>Bash<\/p>\n<pre><code># \u4f8b\u5982\uff0c\u521b\u5efa\u4e24\u4e2a\u4eba\u7684\u6587\u4ef6\u5939\nmkdir data\/zhangsan\nmkdir data\/lisi<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5c06\u6bcf\u4e2a\u4eba\u7684\u7167\u7247\uff08JPG \u6216 PNG \u683c\u5f0f\uff09\u653e\u5165\u5bf9\u5e94\u7684\u6587\u4ef6\u5939\u3002\u6bcf\u4e2a\u4eba\u7684\u7167\u7247\u5efa\u8bae\u81f3\u5c1110\u5f20\uff0c\u8d8a\u591a\u8d8a\u597d\uff0c\u6700\u597d\u5305\u542b\u4e0d\u540c\u89d2\u5ea6\u3001\u4e0d\u540c\u8868\u60c5\u3001\u4e0d\u540c\u5149\u7ebf\u4e0b\u7684\u7167\u7247\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u7528\u6587\u4ef6\u7ba1\u7406\u5668\u6765\u590d\u5236\u7c98\u8d34\uff0c\u6216\u8005\u7528 cp \u547d\u4ee4\u3002<\/p>\n<\/li>\n<\/ol>\n<h4><strong>\u7b2c 6 \u6b65\uff1a\u7f16\u8bd1\u9879\u76ee<\/strong><\/h4>\n<p>\u73b0\u5728\uff0c\u6240\u6709\u4ee3\u7801\u548c\u6570\u636e\u90fd\u51c6\u5907\u597d\u4e86\uff0c\u8ba9\u6211\u4eec\u6765\u7f16\u8bd1\u5b83\u3002<\/p>\n<ol>\n<li>\n<p><strong>\u8fdb\u5165 <code>build<\/code> \u6587\u4ef6\u5939<\/strong>\u3002<\/p>\n<p>Bash<\/p>\n<pre><code>cd build<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c CMake<\/strong>\u3002\u5b83\u4f1a\u8bfb\u53d6\u4e0a\u4e00\u7ea7\u76ee\u5f55\u7684 <code>CMakeLists.txt<\/code> \u6587\u4ef6\u5e76\u751f\u6210\u914d\u7f6e\u3002<\/p>\n<p>Bash<\/p>\n<pre><code>cmake ..<\/code><\/pre>\n<ul>\n<li><code>..<\/code> \u4ee3\u8868\u4e0a\u4e00\u7ea7\u76ee\u5f55\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c make<\/strong>\u3002\u5b83\u4f1a\u6839\u636e CMake \u751f\u6210\u7684\u914d\u7f6e\uff0c\u8c03\u7528 C++ \u7f16\u8bd1\u5668\u6765\u7f16\u8bd1\u6e90\u4ee3\u7801\u3002<\/p>\n<p>Bash<\/p>\n<pre><code>make<\/code><\/pre>\n<p>\u7b49\u5f85\u7f16\u8bd1\u5b8c\u6210\u3002\u5982\u679c\u4e00\u5207\u987a\u5229\uff0c\u60a8\u4e0d\u4f1a\u770b\u5230\u4efb\u4f55\u7ea2\u8272\u7684\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<\/li>\n<\/ol>\n<h4><strong>\u7b2c 7 \u6b65\uff1a\u8fd0\u884c\u7a0b\u5e8f<\/strong><\/h4>\n<p>\u7f16\u8bd1\u6210\u529f\u540e\uff0c<code>build<\/code> \u6587\u4ef6\u5939\u91cc\u4f1a\u751f\u6210\u4e24\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff1a<code>train_model<\/code> \u548c <code>recognize_face<\/code>\u3002<\/p>\n<ol>\n<li>\n<p><strong>\u9996\u5148\uff0c\u8bad\u7ec3\u6a21\u578b<\/strong>\u3002\u6211\u4eec\u9700\u8981\u56de\u5230\u9879\u76ee\u4e3b\u76ee\u5f55\u6765\u8fd0\u884c\uff0c\u8fd9\u6837\u7a0b\u5e8f\u624d\u80fd\u627e\u5230 <code>data<\/code> \u6587\u4ef6\u5939\u3002<\/p>\n<p>Bash<\/p>\n<pre><code># \u56de\u5230\u4e3b\u76ee\u5f55 FaceRecProject\ncd ..\n\n# \u8fd0\u884c\u8bad\u7ec3\u7a0b\u5e8f\n.\/build\/train_model<\/code><\/pre>\n<p>\u7a0b\u5e8f\u4f1a\u8bfb\u53d6 <code>data<\/code> \u6587\u4ef6\u5939\u91cc\u7684\u7167\u7247\uff0c\u8bad\u7ec3\u6a21\u578b\uff0c\u7136\u540e\u5728\u4e3b\u76ee\u5f55\u751f\u6210\u4e00\u4e2a <code>face_model.yml<\/code> \u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6700\u540e\uff0c\u8fd0\u884c\u5b9e\u65f6\u8bc6\u522b\u7a0b\u5e8f<\/strong>\uff01<\/p>\n<p>Bash<\/p>\n<pre><code># \u786e\u4fdd\u4ecd\u5728\u4e3b\u76ee\u5f55\n.\/build\/recognize_face<\/code><\/pre>\n<p>\u7a0b\u5e8f\u4f1a\u8bf7\u6c42\u6253\u5f00\u60a8\u7684\u6444\u50cf\u5934\u3002\u6388\u6743\u540e\uff0c\u4e00\u4e2a\u540d\u4e3a \u201cFace Recognition\u201d \u7684\u7a97\u53e3\u5c31\u4f1a\u5f39\u51fa\u3002\u5b83\u4f1a\u5b9e\u65f6\u5730\u68c0\u6d4b\u548c\u8bc6\u522b\u4eba\u8138\uff0c\u5e76\u5c06\u964c\u751f\u4eba\u7684\u5934\u50cf\u4fdd\u5b58\u5728 <code>strangers<\/code> \u6587\u4ef6\u5939\u3002<\/p>\n<p><strong>\u6309 <code>q<\/code> \u952e\u53ef\u4ee5\u5173\u95ed\u7a97\u53e3\u5e76\u9000\u51fa\u7a0b\u5e8f\u3002<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>\u606d\u559c\u60a8\uff01\u60a8\u5df2\u7ecf\u4ece\u96f6\u5f00\u59cb\uff0c\u6210\u529f\u5730\u5728 Arch Linux \u4e0a\u6784\u5efa\u5e76\u8fd0\u884c\u4e86\u4e00\u4e2a\u5c5e\u4e8e\u60a8\u81ea\u5df1\u7684 C++ \u4eba\u8138\u8bc6\u522b\u5e94\u7528\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u672c\u6559\u7a0b\u5c06\u57fa\u4e8e\u5e26\u60a8\u5b8c\u6210\u4ece\u73af\u5883\u914d\u7f6e\u5230\u6700\u7ec8\u8fd0\u884c\u7a0b\u5e8f\u7684\u5168\u90e8\u6d41\u7a0b\u3002 \u7b2c 0 \u6b65\uff1a\u51c6\u5907\u60a8\u7684\u7cfb\u7edf \u9996\u5148\uff0c\u786e\u4fdd\u60a8\u7684 Arch Linux \u7cfb\u7edf\u662f\u6700 &#8230;<\/p>","protected":false},"author":1,"featured_media":179,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[6,1],"tags":[2,17],"class_list":["post-140","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-endeavoros","category-learn","tag-cpp","tag-opencv"],"_links":{"self":[{"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":1,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"predecessor-version":[{"id":141,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/posts\/140\/revisions\/141"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/media\/179"}],"wp:attachment":[{"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/caoxunyi.cn\/index.php\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}