├── QQ
├── Resource.qrc
├── css
│ ├── LoginWindowCss.qss
│ ├── LoginWindowCss.css
│ └── BaseWindowCss.css
├── config.h
├── images
│ ├── back.gif
│ ├── shadow.png
│ ├── HeadImage.png
│ ├── arrowback.png
│ ├── checkbox.png
│ ├── closeback.png
│ ├── flicker.png
│ ├── headBack.gif
│ ├── keyboard.png
│ ├── minback.png
│ ├── state_Qme.png
│ ├── menu_border.png
│ ├── state_away.png
│ ├── state_busy.png
│ ├── state_hide.png
│ ├── TitleBar
│ │ ├── arrow.png
│ │ ├── close.png
│ │ ├── max.png
│ │ ├── min_.png
│ │ ├── restore.png
│ │ ├── min_hover.bmp
│ │ ├── min_press.bmp
│ │ ├── arrow_hover.png
│ │ ├── arrow_press.png
│ │ ├── close_hover.png
│ │ └── close_press.png
│ ├── state_online.png
│ ├── LoginImages
│ │ ├── back.gif
│ │ ├── flicker.png
│ │ ├── minback.png
│ │ ├── HeadImage.png
│ │ ├── arrowback.png
│ │ ├── checkbox.png
│ │ ├── closeback.png
│ │ ├── keyboard.png
│ │ ├── drop_down_Button.png
│ │ └── more_accountlogin.png
│ ├── drop_down_Button.png
│ ├── state_notdisturb.png
│ ├── more_accountlogin.png
│ └── LoginState
│ │ ├── state_Qme.png
│ │ ├── state_away.png
│ │ ├── state_busy.png
│ │ ├── state_hide.png
│ │ ├── state_online.png
│ │ └── state_notdisturb.png
├── basewindow.cpp
├── windowtoptitle.cpp
├── basewindow.h
├── main.cpp
├── qrcodedialog.cpp
├── logininterface.cpp
├── windowtoptitle.h
├── qrcodedialog.h
├── logininterface.h
├── qrcodedialog.ui
├── logininterface.ui
└── QQ.pro
├── STL_re
├── docs
│ ├── string.mdown
│ ├── vector.md
│ └── allocator.md
├── library
│ ├── xstl_algo_for_each.h
│ ├── xstl_algorithm.h
│ ├── xstl_algo_fill.h
│ ├── xstl_algo_find.h
│ ├── xstl_algo_copy.h
│ ├── xstl_algo_equal.h
│ ├── xstl_algo_unique.h
│ ├── xstl_allocator.h
│ ├── xstl_vector.h
│ └── xstl_string.h
└── test
│ ├── allocator_test.cpp
│ ├── string_test.cpp
│ ├── vector_test.cpp
│ └── algorithm_test.cpp
├── README.md
├── Face_Recognize
├── Python
│ └── tools
│ │ ├── createFile.py
│ │ └── camera.py
└── C++
│ ├── tools
│ ├── create_csv_file.cpp
│ └── camera.cpp
│ └── src
│ ├── CamerCapturemodel.h
│ ├── PredictModel.h
│ ├── DatabaseModel.h
│ ├── UserCenterModel.h
│ └── TrainningModel.h
├── MachineLearning
└── decision_tree
│ ├── C4.5
│ ├── watermelondatas.txt
│ ├── decisionstructure.h
│ ├── C4.5.cpp
│ └── require.h
│ └── ID3
│ ├── watermelondatas.txt
│ ├── decisionstructure.h
│ ├── ID3.cpp
│ └── require.h
└── Spider
└── Taobao
└── login_taobao.py
/QQ/Resource.qrc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/QQ/css/LoginWindowCss.qss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/QQ/config.h:
--------------------------------------------------------------------------------
1 | #ifndef CONFIG_H
2 | #define CONFIG_H
3 |
4 | #endif // CONFIG_H
5 |
--------------------------------------------------------------------------------
/QQ/images/back.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/back.gif
--------------------------------------------------------------------------------
/QQ/images/shadow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/shadow.png
--------------------------------------------------------------------------------
/QQ/basewindow.cpp:
--------------------------------------------------------------------------------
1 | #include "basewindow.h"
2 |
3 | BaseWindow::BaseWindow()
4 | {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/QQ/images/HeadImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/HeadImage.png
--------------------------------------------------------------------------------
/QQ/images/arrowback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/arrowback.png
--------------------------------------------------------------------------------
/QQ/images/checkbox.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/checkbox.png
--------------------------------------------------------------------------------
/QQ/images/closeback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/closeback.png
--------------------------------------------------------------------------------
/QQ/images/flicker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/flicker.png
--------------------------------------------------------------------------------
/QQ/images/headBack.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/headBack.gif
--------------------------------------------------------------------------------
/QQ/images/keyboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/keyboard.png
--------------------------------------------------------------------------------
/QQ/images/minback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/minback.png
--------------------------------------------------------------------------------
/QQ/images/state_Qme.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/state_Qme.png
--------------------------------------------------------------------------------
/QQ/images/menu_border.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/menu_border.png
--------------------------------------------------------------------------------
/QQ/images/state_away.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/state_away.png
--------------------------------------------------------------------------------
/QQ/images/state_busy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/state_busy.png
--------------------------------------------------------------------------------
/QQ/images/state_hide.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/state_hide.png
--------------------------------------------------------------------------------
/QQ/images/TitleBar/arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/arrow.png
--------------------------------------------------------------------------------
/QQ/images/TitleBar/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/close.png
--------------------------------------------------------------------------------
/QQ/images/TitleBar/max.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/max.png
--------------------------------------------------------------------------------
/QQ/images/TitleBar/min_.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/min_.png
--------------------------------------------------------------------------------
/QQ/images/state_online.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/state_online.png
--------------------------------------------------------------------------------
/QQ/images/LoginImages/back.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/back.gif
--------------------------------------------------------------------------------
/QQ/images/TitleBar/restore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/restore.png
--------------------------------------------------------------------------------
/QQ/images/drop_down_Button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/drop_down_Button.png
--------------------------------------------------------------------------------
/QQ/images/state_notdisturb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/state_notdisturb.png
--------------------------------------------------------------------------------
/QQ/images/LoginImages/flicker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/flicker.png
--------------------------------------------------------------------------------
/QQ/images/LoginImages/minback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/minback.png
--------------------------------------------------------------------------------
/QQ/images/TitleBar/min_hover.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/min_hover.bmp
--------------------------------------------------------------------------------
/QQ/images/TitleBar/min_press.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/min_press.bmp
--------------------------------------------------------------------------------
/QQ/images/more_accountlogin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/more_accountlogin.png
--------------------------------------------------------------------------------
/QQ/images/LoginImages/HeadImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/HeadImage.png
--------------------------------------------------------------------------------
/QQ/images/LoginImages/arrowback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/arrowback.png
--------------------------------------------------------------------------------
/QQ/images/LoginImages/checkbox.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/checkbox.png
--------------------------------------------------------------------------------
/QQ/images/LoginImages/closeback.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/closeback.png
--------------------------------------------------------------------------------
/QQ/images/LoginImages/keyboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/keyboard.png
--------------------------------------------------------------------------------
/QQ/images/LoginState/state_Qme.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginState/state_Qme.png
--------------------------------------------------------------------------------
/QQ/images/LoginState/state_away.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginState/state_away.png
--------------------------------------------------------------------------------
/QQ/images/LoginState/state_busy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginState/state_busy.png
--------------------------------------------------------------------------------
/QQ/images/LoginState/state_hide.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginState/state_hide.png
--------------------------------------------------------------------------------
/QQ/images/TitleBar/arrow_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/arrow_hover.png
--------------------------------------------------------------------------------
/QQ/images/TitleBar/arrow_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/arrow_press.png
--------------------------------------------------------------------------------
/QQ/images/TitleBar/close_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/close_hover.png
--------------------------------------------------------------------------------
/QQ/images/TitleBar/close_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/TitleBar/close_press.png
--------------------------------------------------------------------------------
/QQ/images/LoginState/state_online.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginState/state_online.png
--------------------------------------------------------------------------------
/STL_re/docs/string.mdown:
--------------------------------------------------------------------------------
1 | # string
2 |
3 | There are some bugs. But I don't want to debug now. So it will delay....
4 |
5 |
--------------------------------------------------------------------------------
/QQ/images/LoginImages/drop_down_Button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/drop_down_Button.png
--------------------------------------------------------------------------------
/QQ/images/LoginImages/more_accountlogin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginImages/more_accountlogin.png
--------------------------------------------------------------------------------
/QQ/images/LoginState/state_notdisturb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiafanxue/Coding/HEAD/QQ/images/LoginState/state_notdisturb.png
--------------------------------------------------------------------------------
/QQ/windowtoptitle.cpp:
--------------------------------------------------------------------------------
1 | #include "windowtoptitle.h"
2 |
3 | WindowTopTitle::WindowTopTitle(QWidget *parent) : QWidget(parent)
4 | {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 项目
2 |
3 | ## STL_Re
4 | 仿照标准模实现的部分STL容器,算法
5 |
6 | ## Face_Recognize
7 | 一个人脸识别程序
8 |
9 | ## QQ
10 | 仿照QQ,使用Qt开发的界面
11 |
--------------------------------------------------------------------------------
/QQ/basewindow.h:
--------------------------------------------------------------------------------
1 | #ifndef BASEWINDOW_H
2 | #define BASEWINDOW_H
3 |
4 |
5 | class BaseWindow
6 | {
7 | public:
8 | BaseWindow();
9 | };
10 |
11 | #endif // BASEWINDOW_H
--------------------------------------------------------------------------------
/QQ/main.cpp:
--------------------------------------------------------------------------------
1 | #include "logininterface.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | LoginInterface w;
8 | w.show();
9 |
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/QQ/qrcodedialog.cpp:
--------------------------------------------------------------------------------
1 | #include "qrcodedialog.h"
2 | #include "ui_qrcodedialog.h"
3 |
4 | QRcodeDialog::QRcodeDialog(QWidget *parent) :
5 | QDialog(parent),
6 | ui(new Ui::QRcodeDialog)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | QRcodeDialog::~QRcodeDialog()
12 | {
13 | delete ui;
14 | }
15 |
--------------------------------------------------------------------------------
/QQ/css/LoginWindowCss.css:
--------------------------------------------------------------------------------
1 | *{font-family:Microsoft YaHei;}
2 |
3 | QPushButton
4 | {
5 | border-image: url(:/LoginImages/images/LoginImages/arrowback.png) 0 60 0 0
6 | }
7 |
8 | QPushButton#FlipPushButton:hover
9 | {
10 | border-image:url(:/LoginImages/images/LoginImages/arrowback.png) 0 30 0 30 ;
11 | }
12 |
--------------------------------------------------------------------------------
/QQ/logininterface.cpp:
--------------------------------------------------------------------------------
1 | #include "logininterface.h"
2 | #include "ui_logininterface.h"
3 |
4 | LoginInterface::LoginInterface(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::LoginInterface)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | LoginInterface::~LoginInterface()
12 | {
13 | delete ui;
14 | }
15 |
--------------------------------------------------------------------------------
/QQ/windowtoptitle.h:
--------------------------------------------------------------------------------
1 | #ifndef WINDOWTOPTITLE_H
2 | #define WINDOWTOPTITLE_H
3 |
4 | #include
5 |
6 | class WindowTopTitle : public QWidget
7 | {
8 | Q_OBJECT
9 | public:
10 | explicit WindowTopTitle(QWidget *parent = nullptr);
11 |
12 | signals:
13 |
14 | public slots:
15 | };
16 |
17 | #endif // WINDOWTOPTITLE_H
--------------------------------------------------------------------------------
/QQ/qrcodedialog.h:
--------------------------------------------------------------------------------
1 | #ifndef QRCODEDIALOG_H
2 | #define QRCODEDIALOG_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class QRcodeDialog;
8 | }
9 |
10 | class QRcodeDialog : public QDialog
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit QRcodeDialog(QWidget *parent = 0);
16 | ~QRcodeDialog();
17 |
18 | private:
19 | Ui::QRcodeDialog *ui;
20 | };
21 |
22 | #endif // QRCODEDIALOG_H
23 |
--------------------------------------------------------------------------------
/QQ/logininterface.h:
--------------------------------------------------------------------------------
1 | #ifndef LOGININTERFACE_H
2 | #define LOGININTERFACE_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class LoginInterface;
8 | }
9 |
10 | class LoginInterface : public QWidget
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit LoginInterface(QWidget *parent = 0);
16 | ~LoginInterface();
17 |
18 | private:
19 | Ui::LoginInterface *ui;
20 | };
21 |
22 | #endif // LOGININTERFACE_H
23 |
--------------------------------------------------------------------------------
/QQ/qrcodedialog.ui:
--------------------------------------------------------------------------------
1 |
2 | QRcodeDialog
3 |
4 |
5 |
6 | 0
7 | 0
8 | 400
9 | 300
10 |
11 |
12 |
13 | Dialog
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Face_Recognize/Python/tools/createFile.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: UTF-8 -*-
3 |
4 | def createFile():
5 | # Information
6 | info = 'E:/WorkFor2017/ML/test_image/att_faces/s{0}/{1}.pgm;{2}\n'
7 |
8 | # Input filename
9 | filename = input('Enter file name: ')
10 |
11 | fp = open(filename, 'w')
12 |
13 | for i in range(1, 42):
14 | for j in range(1, 11):
15 | fp.write(info.format(i, j, i-1))
16 |
17 | fp.close()
18 |
19 | if __name__ == '__main__':
20 | createFile()
21 |
--------------------------------------------------------------------------------
/STL_re/docs/vector.md:
--------------------------------------------------------------------------------
1 | # vector
2 |
3 | ## 简介(后期可能会继续添加)
4 | 1.vector是STL中的循序容器,是一种动态的数组。vector的存储被自动处理,根据需要被扩展或者收缩。但由于vector中存放有额外的信息用来记录数据(如:大小,容量等等),因此,通常它比静态数组占用更多的内存空间。
5 |
6 | 2.与关联容器不同,vector中的元素存放是连续的,这意味着我们即可以通过iterator操作,也可以通过传统指针加上偏移量来进行操作。
7 |
8 | 3.vector优先于动态分配的数组。因为通过使用new申请的内存空间,存在内存泄漏的危险,有时还会泄漏资源和破坏内存。
9 |
10 | 4.vector的容量每次以2的倍数增长。
11 |
12 | 5.vector存在一个特例化vector
13 |
14 | 6.特别值得一提的是,vector是C++通向C和其他语言的通道。
15 |
16 | 7.注意迭代器失效的情况
17 |
18 | ## 资料
19 | 《Effective STL》 13 - 18条
--------------------------------------------------------------------------------
/QQ/logininterface.ui:
--------------------------------------------------------------------------------
1 |
2 | LoginInterface
3 |
4 |
5 |
6 | 0
7 | 0
8 | 400
9 | 300
10 |
11 |
12 |
13 | LoginInterface
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/STL_re/library/xstl_algo_for_each.h:
--------------------------------------------------------------------------------
1 | #ifndef LIBRARY_XSTL_ALGO_FOR_EACH_H__
2 | #define LIBRARY_XSTL_ALGO_FOR_EACH_H__
3 |
4 | namespace xstl
5 | {
6 | namespace algo
7 | {
8 | template
9 | UnaryFunction for_each(InputIt first, InputIt last, UnaryFunction f)
10 | {
11 | for(; first != last; ++first) {
12 | f(*first);
13 | }
14 | return f;
15 | }
16 |
17 | /* Since C++17
18 | template
19 | void for_each(ExecutionPolicy&& policy, InputIt first, InputIt last, UnaryFunction2 f)
20 | {
21 |
22 | }
23 | */
24 |
25 | }
26 | }
27 |
28 | #endif // LIBRARY_XSTL_ALGO_FOR_EACH_H__
--------------------------------------------------------------------------------
/Face_Recognize/C++/tools/create_csv_file.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 | using namespace boost;
6 |
7 | int main(int argc, char const *argv[])
8 | {
9 | cout << "Please input filename: ";
10 | string filename;
11 | cin >> filename;
12 | fstream s(filename, ios::out | ios::trunc);
13 |
14 | if (!s.is_open()) {
15 | cout << "failed to open " << filename << endl;
16 | }
17 | else {
18 | format fmt("E:/WorkFor2017/ML/test_image/att_faces/s%d/%d.pgm;%d\n");
19 | for(int i = 1; i <= 41; ++i) {
20 | for(int j = 1; j <= 10; ++j) {
21 | fmt %i %j %(i-1);
22 | s << fmt;
23 | }
24 | }
25 | }
26 | s.close();
27 | return 0;
28 | }
29 |
--------------------------------------------------------------------------------
/STL_re/library/xstl_algorithm.h:
--------------------------------------------------------------------------------
1 | #ifndef LIBRARY_XSTL_ALGORITHM_H__
2 | #define LIBRARY_XSTL_ALGORITHM_H__
3 |
4 | // Non-modifying sequence operations
5 | #include "xstl_algo_find.h" // find && find_if && find_if_not
6 | #include "xstl_algo_for_each.h" // for_each
7 | #include "xstl_algo_equal.h" // equal
8 |
9 | // Modifying sequence operations
10 | #include "xstl_algo_copy.h" // copy && copy_if && copy_n && copy_backward
11 | #include "xstl_algo_fill.h" // fill && fill_n
12 |
13 | #include "xstl_algo_unique.h" // unique && unique_copy
14 |
15 | // Sorting operations(on sorted ranges)
16 | // #include "xstl_algo_sort.h" // is_sorted && is_srted_until && sort &&
17 | // partial_sort && partial_sort_copy && stable_sort && nth_element
18 |
19 | #endif // LIBRARY_XSTL_ALGORITHM_H__
--------------------------------------------------------------------------------
/STL_re/test/allocator_test.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "../library/xstl_allocator.h"
5 |
6 | int main(int argc, char const *argv[])
7 | {
8 | xstl::allocator a1;
9 | int* a = a1.allocate(10);
10 |
11 | a[9] = 7;
12 |
13 | std::cout << a[9] << std::endl;
14 |
15 | a1.deallocate(a, 10);
16 |
17 | std::allocator a2;
18 |
19 | // decltype(a1)::rebind::other a2_1;
20 |
21 | // std::allocator_traits::rebind_alloc a2_2;
22 |
23 | std::string* s = a2.allocate(2);
24 |
25 | a2.construct(s, "foo");
26 | a2.construct(s + 1, "bar");
27 |
28 | std::cout << s[0] << " " << s[1] << std::endl;
29 |
30 | a2.destroy(s);
31 | a2.destroy(s + 1);
32 | a2.deallocate(s, 2);
33 |
34 | return 0;
35 | }
--------------------------------------------------------------------------------
/Face_Recognize/Python/tools/camera.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: UTF-8 -*-
3 |
4 | import cv2
5 |
6 | def camera():
7 | capture = cv2.VideoCapture(0)
8 | index = 1
9 | while capture.isOpened():
10 | # 返回一个元组,value和image,value用来检查是否读入成功
11 | ok, frame = capture.read()
12 | if not ok:
13 | break;
14 | else:
15 | cv2.imshow("MyPicture", frame)
16 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
17 | # cv2.imshow("MyPicture", gray)
18 | dst = cv2.resize(gray, (92, 112));
19 | c = cv2.waitKey(100)
20 | if c & 0xFF == ord('q'): # q退出
21 | break;
22 | elif c & 0xFF == ord('a'): # a拍照
23 | filename = '%d.pgm' % index
24 | index += 1
25 | cv2.imwrite(filename, dst)
26 | else:
27 | continue
28 | capture.release()
29 | cv2.destroyAllWindows()
30 |
31 | if __name__ == '__main__':
32 | camera()
33 |
--------------------------------------------------------------------------------
/Face_Recognize/C++/tools/camera.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace cv;
4 | using namespace std;
5 |
6 | int main(int argc, char const *argv[])
7 | {
8 | // 创建VideoCapture对象,打开默认摄像机
9 | VideoCapture capture(0);
10 | // 检查是否打开摄像头
11 | if (!capture.isOpened()) {
12 | cerr << "VideoCapture construct error!" << endl;
13 | exit(1);
14 | }
15 |
16 | Mat dst;
17 | Mat frame;
18 | Mat changeframe;
19 | int i = 1;
20 | while (1) {
21 | // 从摄像机中获取一个新的框架
22 | capture >> frame;
23 | if (frame.empty()) {
24 | cerr << "New frame is empty" << endl;
25 | exit(1);
26 | }
27 |
28 | // 显示灰度图
29 | imshow("MyPicture", frame);
30 |
31 | // 转为灰度图
32 | cvtColor(frame, changeframe, CV_BGR2GRAY);
33 |
34 | // 改变图片大小
35 | resize(changeframe, dst, Size(92, 112), 0, 0, INTER_LINEAR);
36 | char c = waitKey(100);
37 | if (c == 97) { // 'a'开始拍照
38 | ++i;
39 | string filename = format("%d.jpg", i); // 定义图片存储的位置
40 | imwrite(filename, dst); // 保存灰度图
41 | }
42 | else if (c == 27) { // Esc推出程序
43 | break;
44 | }
45 | }
46 |
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/MachineLearning/decision_tree/C4.5/watermelondatas.txt:
--------------------------------------------------------------------------------
1 | id color pedicle sound texture umbilical touch good
2 | 1 darkgreen curled turbid clear sunken hardslip yes
3 | 2 jetblack curled dull clear sunken hardslip yes
4 | 3 jetblack curled turbid clear sunken hardslip yes
5 | 4 darkgreen curled dull clear sunken hardslip yes
6 | 5 lightwhite curled turbid clear sunken hardslip yes
7 | 6 darkgreen slightlycurled turbid clear slightlysunken softsticky yes
8 | 7 jetblack slightlycurled turbid lightblur slightlysunken softsticky yes
9 | 8 jetblack slightlycurled turbid clear slightlysunken hardslip yes
10 | 9 jetblack slightlycurled dull lightblur slightlysunken hardslip no
11 | 10 darkgreen stiffened crisp clear flat softsticky no
12 | 11 lightwhite stiffened crisp blur flat hardslip no
13 | 12 lightwhite curled turbid blur flat softsticky no
14 | 13 darkgreen slightlycurled turbid lightblur sunken hardslip no
15 | 14 lightwhite slightlycurled dull lightblur sunken hardslip no
16 | 15 jetblack slightlycurled turbid clear slightlysunken softsticky no
17 | 16 lightwhite curled turbid blur flat hardslip no
18 | 17 darkgreen curled dull lightblur slightlysunken hardslip no
--------------------------------------------------------------------------------
/MachineLearning/decision_tree/ID3/watermelondatas.txt:
--------------------------------------------------------------------------------
1 | id color pedicle sound texture umbilical touch good
2 | 1 darkgreen curled turbid clear sunken hardslip yes
3 | 2 jetblack curled dull clear sunken hardslip yes
4 | 3 jetblack curled turbid clear sunken hardslip yes
5 | 4 darkgreen curled dull clear sunken hardslip yes
6 | 5 lightwhite curled turbid clear sunken hardslip yes
7 | 6 darkgreen slightlycurled turbid clear slightlysunken softsticky yes
8 | 7 jetblack slightlycurled turbid lightblur slightlysunken softsticky yes
9 | 8 jetblack slightlycurled turbid clear slightlysunken hardslip yes
10 | 9 jetblack slightlycurled dull lightblur slightlysunken hardslip no
11 | 10 darkgreen stiffened crisp clear flat softsticky no
12 | 11 lightwhite stiffened crisp blur flat hardslip no
13 | 12 lightwhite curled turbid blur flat softsticky no
14 | 13 darkgreen slightlycurled turbid lightblur sunken hardslip no
15 | 14 lightwhite slightlycurled dull lightblur sunken hardslip no
16 | 15 jetblack slightlycurled turbid clear slightlysunken softsticky no
17 | 16 lightwhite curled turbid blur flat hardslip no
18 | 17 darkgreen curled dull lightblur slightlysunken hardslip no
--------------------------------------------------------------------------------
/MachineLearning/decision_tree/ID3/decisionstructure.h:
--------------------------------------------------------------------------------
1 | #ifndef DECISIONSTRUCTURE_H__
2 | #define DECISIONSTRUCTURE_H__
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | // 西瓜个体定义
9 | class Watermelon
10 | {
11 | public:
12 | std::string id; // 编号
13 | std::string color; // 颜色
14 | std::string pedicle; // 根蒂
15 | std::string sound; // 声音
16 | std::string texture; // 纹理
17 | std::string umbilical; // 脐部
18 | std::string touch; // 触感
19 | std::string good; // 好瓜?
20 |
21 | friend
22 | std::ostream& operator<<(std::ostream& os, const Watermelon& wm)
23 | {
24 | os << wm.id << " " << wm.color << " " << wm.pedicle << " "
25 | << wm.sound << " " << wm.texture << " " << wm.umbilical << " "
26 | << wm.touch << " " << wm.good;
27 | os << std::endl;
28 | return os;
29 | }
30 | };
31 |
32 | struct Node
33 | {
34 | std::string attribute;
35 | std::string edgeValue;
36 | std::vector childs;
37 | Node() : attribute(""), edgeValue("") { }
38 | };
39 |
40 | template
41 | using Ptr = T*;
42 | using TreeRoot = Ptr;
43 |
44 | #endif // DECISIONSTRUCTURE_H__
45 |
--------------------------------------------------------------------------------
/MachineLearning/decision_tree/C4.5/decisionstructure.h:
--------------------------------------------------------------------------------
1 | #ifndef DECISIONSTRUCTURE_H__
2 | #define DECISIONSTRUCTURE_H__
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | // 西瓜个体定义
9 | class Watermelon
10 | {
11 | public:
12 | std::string id; // 编号
13 | std::string color; // 颜色
14 | std::string pedicle; // 根蒂
15 | std::string sound; // 声音
16 | std::string texture; // 纹理
17 | std::string umbilical; // 脐部
18 | std::string touch; // 触感
19 | std::string good; // 好瓜?
20 |
21 | friend
22 | std::ostream& operator<<(std::ostream& os, const Watermelon& wm)
23 | {
24 | os << wm.id << " " << wm.color << " " << wm.pedicle << " "
25 | << wm.sound << " " << wm.texture << " " << wm.umbilical << " "
26 | << wm.touch << " " << wm.good;
27 | os << std::endl;
28 | return os;
29 | }
30 | };
31 |
32 | struct Node
33 | {
34 | std::string attribute;
35 | std::string edgeValue;
36 | std::vector childs;
37 | Node() : attribute(""), edgeValue("") { }
38 | };
39 |
40 | template
41 | using Ptr = T*;
42 | using TreeRoot = Ptr;
43 |
44 | #endif // DECISIONSTRUCTURE_H__
45 |
--------------------------------------------------------------------------------
/QQ/QQ.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2017-08-03T15:40:23
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | TARGET = QQ
12 | TEMPLATE = app
13 |
14 | # The following define makes your compiler emit warnings if you use
15 | # any feature of Qt which as been marked as deprecated (the exact warnings
16 | # depend on your compiler). Please consult the documentation of the
17 | # deprecated API in order to know how to port your code away from it.
18 | DEFINES += QT_DEPRECATED_WARNINGS
19 |
20 | # You can also make your code fail to compile if you use deprecated APIs.
21 | # In order to do so, uncomment the following line.
22 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24 |
25 |
26 | SOURCES += \
27 | main.cpp \
28 | logininterface.cpp
29 |
30 | HEADERS += \
31 | logininterface.h
32 |
33 | FORMS += \
34 | logininterface.ui
35 |
--------------------------------------------------------------------------------
/Face_Recognize/C++/src/CamerCapturemodel.h:
--------------------------------------------------------------------------------
1 | #ifndef CAMERACAPTUREMODEL_H__
2 | #define CAMERACAPTUREMODEL_H__
3 |
4 | #include "PredictModel.h"
5 | #include
6 |
7 | class CameraCaptureModel
8 | {
9 | public:
10 | // Use the default constructor (PredictModel)
11 | CameraCaptureModel()
12 | : m_vCapture(0)
13 | {
14 | // empty
15 | }
16 |
17 | CameraCaptureModel(const std::string src_)
18 | : m_vCapture(0),
19 | m_Predict(src_)
20 | {
21 | // empty
22 | }
23 |
24 | void openCamera()
25 | {
26 | if (!m_vCapture.isOpened()) {
27 | std::cerr << "VideoCapture construct error!" << std::endl;
28 | exit(1);
29 | }
30 |
31 | while (1) {
32 | m_vCapture >> m_mFrame;
33 | if (m_mFrame.empty()) {
34 | std::cerr << "New frame is empty" << std::endl;
35 | exit(1);
36 | }
37 |
38 | imshow("MyPicture", m_mFrame);
39 |
40 | cv::cvtColor(m_mFrame, m_mGray, CV_BGR2GRAY);
41 |
42 | cv::resize(m_mGray, m_mEdge, cv::Size(92, 112), 0, 0, CV_INTER_LINEAR);
43 |
44 | m_Predict.prediction(m_mEdge);
45 |
46 | char c = cv::waitKey(100);
47 | if (c == 27) { // Esc推出程序
48 | break;
49 | }
50 | }
51 | }
52 |
53 | private:
54 | cv::VideoCapture m_vCapture;
55 | cv::Mat m_mFrame;
56 | cv::Mat m_mEdge;
57 | cv::Mat m_mGray;
58 | PredictModel m_Predict;
59 | };
60 |
61 | #endif // !CAMERACAPTUREMODEL_H__
62 |
--------------------------------------------------------------------------------
/STL_re/library/xstl_algo_fill.h:
--------------------------------------------------------------------------------
1 | #ifndef LIBRARY_XSTL_ALGO_FILL_H__
2 | #define LIBRARY_XSTL_ALGO_FILL_H__
3 |
4 | namespace xstl
5 | {
6 | namespace algo
7 | {
8 | template
9 | void fill(ForwardIt first, ForwardIt last, const T& value)
10 | {
11 | for(; first != last; ++first) {
12 | *first = value;
13 | }
14 | }
15 |
16 | /* Since C++17
17 | template
18 | void fill(ExecutionPolicy&& policy, ForwardIt first, ForwardIt last, const T& value)
19 | {
20 |
21 | }
22 | */
23 |
24 | /* Unitl C++11
25 | template
26 | void fill_n(OutputIt first, Size count, const T& value)
27 | {
28 | for(Size i = 0; i < count; ++i) {
29 | *first++ = value;
30 | }
31 | }
32 | */
33 |
34 | template
35 | OutputIt fill_n(OutputIt first, Size count, const T& value)
36 | {
37 | for(Size i = 0; i < count; ++i) {
38 | *first++ = value;
39 | }
40 | return first;
41 | }
42 |
43 | /* Since C++17
44 | template
45 | OutputIt fill_n(ExecutionPolicy&& policy, OutputIt first, OutputIt last,
46 | Size count, const T& value)
47 | {
48 |
49 | }
50 | */
51 | }
52 | }
53 |
54 | #endif // LIBRARY_XSTL_ALGO_FILL_H__
--------------------------------------------------------------------------------
/STL_re/docs/allocator.md:
--------------------------------------------------------------------------------
1 | # allocator
2 |
3 | ## Introduction
4 | This is the first version of the allocator, can only achieve a simple operation.
5 |
6 | ## Member type
7 | The type of the Allocator:
8 |
9 | allocator::value_type
10 | allocator::pointer
11 | allocator::const_pointer
12 | allocator::reference
13 | allocator::const_reference
14 | allocator::size_type
15 | allocator::difference_type
16 | allocator::rebind --- template struct rebind { typedef allocator other; };
17 |
18 | ## Function
19 | The interface function of the Allocator:
20 |
21 | allocator() -- Default constructor
22 | allocaotr(const allocator&) -- Copy constructor
23 | template allocator(const allocator& other ); -- template construcotr
24 | ~allocator() -- Destructor
25 |
26 | pointer address(reference x) const -- Return the address of object. e.g. a.address(x) <=> &x
27 | const_pointer address(const_reference x) const -- Return the const address of object
28 | pointer allocate(size_type n, const void* = 0) -- Allocate memory, enough to store the n size of T objects. The
29 | second parameter is used prompting
30 | void deallocate(pointer p, size_type n) -- Release memory
31 | size_type max_size() const -- Return the max size of the memory
32 | void construct(pointer p, const T& x) -- Equal 'new((void*)p) T(x)'
33 | void destroy(pointer p) -- Equal 'p->~T()'
--------------------------------------------------------------------------------
/QQ/css/BaseWindowCss.css:
--------------------------------------------------------------------------------
1 | *{font-family:Microsoft YaHei;}
2 |
3 | QLabel#TitleContent
4 | {
5 | color:black;
6 | }
7 |
8 | /*最小化按钮*/
9 | QPushButton#ButtonMin
10 | {
11 | border-image:url(:/Resources/MyTitle/min.png) 0 60 0 0 ;
12 | }
13 |
14 | QPushButton#ButtonMin:hover
15 | {
16 | border-image:url(:/Resources/MyTitle/min.png) 0 30 0 30 ;
17 | }
18 |
19 | QPushButton#ButtonMin:pressed
20 | {
21 | border-image:url(:/Resources/MyTitle/min.png) 0 0 0 60 ;
22 | }
23 |
24 | /*最大化按钮*/
25 | QPushButton#ButtonMax
26 | {
27 | border-image:url(:/Resources/MyTitle/max.png) 0 81 0 0 ;
28 | }
29 |
30 | QPushButton#ButtonMax:hover
31 | {
32 | border-image:url(:/Resources/MyTitle/max.png) 0 54 0 27 ;
33 | }
34 |
35 | QPushButton#ButtonMax:pressed
36 | {
37 | border-image:url(:/Resources/MyTitle/max.png) 0 27 0 54 ;
38 | }
39 |
40 | /*还原按钮*/
41 | QPushButton#ButtonRestore
42 | {
43 | border-image:url(:/Resources/MyTitle/restore.png) 0 81 0 0 ;
44 | }
45 |
46 | QPushButton#ButtonRestore:hover
47 | {
48 | border-image:url(:/Resources/MyTitle/restore.png) 0 54 0 27 ;
49 | }
50 |
51 | QPushButton#ButtonRestore:pressed
52 | {
53 | border-image:url(:/Resources/MyTitle/restore.png) 0 27 0 54 ;
54 | }
55 |
56 | /*关闭按钮*/
57 | QPushButton#ButtonClose
58 | {
59 | border-image:url(:/Resources/MyTitle/close.png) 0 60 0 0 ;
60 | border-top-right-radius:3 ;
61 | }
62 |
63 | QPushButton#ButtonClose:hover
64 | {
65 | border-image:url(:/Resources/MyTitle/close.png) 0 30 0 30 ;
66 | border-top-right-radius:3 ;
67 | }
68 |
69 | QPushButton#ButtonClose:pressed
70 | {
71 | border-image:url(:/Resources/MyTitle/close.png) 0 0 0 60 ;
72 | border-top-right-radius:3 ;
73 | }
74 |
--------------------------------------------------------------------------------
/STL_re/test/string_test.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include "../library/xstl_allocator.h"
6 | #include "../library/xstl_string.h"
7 | using namespace std;
8 |
9 | int main(int argc, char const *argv[])
10 | {
11 | {
12 | xstl::string s;
13 | assert(s.empty() && (s.length() == 0) && (s.size() == 0));
14 | }
15 |
16 | {
17 | xstl::string s(4, '=');
18 | cout << s << endl;
19 | }
20 |
21 | {
22 | xstl::string const other("Exemplary");
23 | // string::string(string const& other, size_type pos, size_type count)
24 | xstl::string s(other, 0, other.length() - 1);
25 | cout << s << endl; // "Exemplar"
26 | }
27 |
28 | {
29 | // string::string(charT const* s, size_type count)
30 | xstl::string s("C-style string", 7);
31 | cout << s << endl; // "C-style"
32 | }
33 |
34 | {
35 | // string::string(charT const* s)
36 | xstl::string s("C-style\0string");
37 | cout << s << endl; // "C-style"
38 | }
39 |
40 | {
41 | char mutable_c_str[] = "another C-style string";
42 | // string::string(InputIt first, InputIt last)
43 | xstl::string s(std::begin(mutable_c_str) + 8, std::end(mutable_c_str) - 1);
44 | cout << s << endl; // "C-style string"
45 | }
46 |
47 | {
48 | xstl::string const other("Exemplar");
49 | xstl::string s(other);
50 | cout << s << endl; // "Exemplar"
51 | }
52 |
53 | {
54 | // string::string(string&& str)
55 | //xstl::string s(xstl::string("C++ by ") + xstl::string("example"));
56 | //cout << s << endl; // "C++ by example"
57 | }
58 |
59 | {
60 | // string(std::initializer_list ilist)
61 | //xstl::string s({ 'C', '-', 's', 't', 'y', 'l', 'e' });
62 | //cout << s << endl; // "C-style"
63 | }
64 |
65 | return 0;
66 | }
--------------------------------------------------------------------------------
/STL_re/library/xstl_algo_find.h:
--------------------------------------------------------------------------------
1 | #ifndef LIBRARY_XSTL_ALGO_FIND_H__
2 | #define LIBRARY_XSTL_ALGO_FIND_H__
3 |
4 | namespace xstl
5 | {
6 | namespace algo
7 | {
8 | template
9 | InputIt find(InputIt first, InputIt last, const T& value)
10 | {
11 | for(; first != last; ++first) {
12 | if(*first == value) {
13 | return first;
14 | }
15 | }
16 | return last;
17 | }
18 |
19 | /* Since C++17
20 | template
21 | InputIt find(ExecutionPolicy&& policy, InputIt first, InputIt last, const T& value)
22 | {
23 |
24 | }
25 | */
26 |
27 | template
28 | InputIt find_if(InputIt first, InputIt last,
29 | UnaryPredicate p)
30 | {
31 | for(; first != last; ++first) {
32 | if(p(*first)) {
33 | return first;
34 | }
35 | }
36 | return last;
37 | }
38 |
39 | /* Since C++17
40 | template
41 | InputIt find_if(ExecutionPolicy&& policy, InputIt first, InputIt last,
42 | UnaryPredicate p)
43 | {
44 |
45 | }
46 | */
47 |
48 | template
49 | InputIt find_if_not(InputIt first, InputIt last,
50 | UnaryPredicate q)
51 | {
52 | for(; first != last; ++first) {
53 | if(!q(*first)) {
54 | return first;
55 | }
56 | }
57 | return last;
58 | }
59 |
60 | /* Since C++17
61 | template
62 | InputIt find_if_not(ExecutionPolicy&& policy, InputIt first, InputIt last,
63 | UnaryPredicate q)
64 | {
65 |
66 | }
67 | */
68 | }
69 | }
70 |
71 | #endif // LIBRARY_XSTL_ALGO_FIND_H__
--------------------------------------------------------------------------------
/STL_re/library/xstl_algo_copy.h:
--------------------------------------------------------------------------------
1 | #ifndef LIBRARY_XSTL_ALGO_COPY_H__
2 | #define LIBRARY_XSTL_ALGO_COPY_H__
3 |
4 | namespace xstl
5 | {
6 | namespace algo
7 | {
8 | template
9 | OutputIt copy(InputIt first, InputIt last, OutputIt d_first)
10 | {
11 | while(first != last) {
12 | *d_first++ = *first++;
13 | }
14 | return d_first;
15 | }
16 |
17 | /* Since C++17
18 | template
19 | OutputIt copy(ExecutionPolicy&& policy, InputIt first, InputIt last,
20 | OutputIt d_first)
21 | {
22 |
23 | }
24 | */
25 |
26 | template
27 | OutputIt copy_if(InputIt first, InputIt last,
28 | OutputIt d_first, UnaryPredicate pred)
29 | {
30 | while(first != last) {
31 | if(pred(*first)) {
32 | *d_first++ = *first;
33 | }
34 | *first++;
35 | }
36 | return d_first;
37 | }
38 |
39 | /* Since C++17
40 | template
41 | OutputIt copy_if(ExecutionPolicy&& policy, InputIt first, InputIt last,
42 | OutputIt d_first, UnaryPredicate pred)
43 | {
44 |
45 | }
46 | */
47 |
48 | template
49 | OutputIt copy_n(InputIt first, Size count, OutputIt result)
50 | {
51 | if(count > 0) {
52 | *result++ = *first;
53 | for(Size i = 1; i < count; ++i) {
54 | *result++ = *++first;
55 | }
56 |
57 | /*
58 | why not ?
59 | for(Size = 0; i < count; ++i) {
60 | *result = *first++;
61 | }
62 | */
63 | }
64 | return result;
65 | }
66 |
67 | /* Since C++17
68 | template
69 | OutputIt copy_n(ExecutionPolicy&& policy, InputIt first, InputIt last,
70 | Size count, OutputIt result)
71 | {
72 |
73 | }
74 | */
75 |
76 | template
77 | BidirIt2 copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 d_last)
78 | {
79 | while(first != last) {
80 | *(--d_last) = *(--last);
81 | }
82 | return d_last;
83 | }
84 | }
85 | }
86 |
87 | #endif // LIBRARY_XSTL_ALGO_COPY_H__
--------------------------------------------------------------------------------
/STL_re/library/xstl_algo_equal.h:
--------------------------------------------------------------------------------
1 | #ifndef LIBRARY_XSTL_ALGO_EQUAL_H__
2 | #define LIBRARY_XSTL_ALGO_EQUAL_H__
3 |
4 | namespace xstl
5 | {
6 | namespace algo
7 | {
8 | template
9 | bool equal(InputIt1 first1, InputIt1 last1,
10 | InputIt2 first2)
11 | {
12 | for(; first1 != last1; ++first1, ++first2) {
13 | if(!(*first1 == *first2)) {
14 | return false;
15 | }
16 | }
17 | return true;
18 | }
19 |
20 | /* Since C++17
21 | template
22 | bool equal(ExecutionPolicy&& policy, ForwardIt1 first1, ForwardIt1 last1,
23 | ForwardIt2 first2)
24 | {
25 |
26 | }
27 | */
28 |
29 | template
30 | bool equal(InputIt1 first1, InputIt1 last1,
31 | InputIt2 first2, BinaryPredicate p)
32 | {
33 | for(; first1 != last1; ++first1, ++first2) {
34 | if(!p(*first1, *first2)) {
35 | return false;
36 | }
37 | }
38 | return true;
39 | }
40 |
41 | /* Since C++17
42 | template
43 | bool equal(ExecutionPolicy&& policy, ForwardIt1 first1, ForwardIt1 last1,
44 | ForwardIt2 first2, BinaryPredicate p)
45 | {
46 |
47 | }
48 | */
49 |
50 | // Since C++14
51 | template
52 | bool equal(InputIt1 first1, InputIt1 last1,
53 | InputIt2 first2, InputIt2 last2)
54 | {
55 | int size1 = last1 - first1;
56 | int size2 = last2 - first2;
57 | if(size1 != size2) {
58 | return false;
59 | }
60 | for(; first1 != last1; ++first1, ++first2) {
61 | if(!(*first1 == *first2)) {
62 | return false;
63 | }
64 | }
65 | return true;
66 | }
67 |
68 |
69 | /* Since C++17
70 | template
71 | bool equal(ExecutionPolicy%% policy, ForwardIt1 first1, ForwardIt1 last1,
72 | ForwardIt2 first2, ForwardIt2 last2)
73 | {
74 |
75 | }
76 | */
77 |
78 | /* Since C++14
79 | template
80 | bool equal(InputIt1 first1, InputIt1 last1,
81 | InputIt2 first2, InputIt2 last2,
82 | BinaryPredicate p)
83 | {
84 |
85 | }
86 | */
87 |
88 | /* Since C++17
89 | template
90 | bool equal(ExecutionPolicy&& policy, ForwardIt1 first1, ForwardIt1 last1,
91 | ForwardIt2 first2, ForwardIt2 last2,
92 | BinaryPredicate p)
93 | {
94 |
95 | }
96 | */
97 | }
98 | }
99 |
100 | #endif // LIBRARY_XSTL_ALGO_EQUAL_H__
--------------------------------------------------------------------------------
/Face_Recognize/C++/src/PredictModel.h:
--------------------------------------------------------------------------------
1 | #ifndef SRC_PREDICTMODEL_H__
2 | #define SRC_PREDICTMODEL_H__
3 |
4 | #include "UserCenterModel.h"
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | using namespace cv::face;
14 |
15 | class PredictModel : boost::noncopyable
16 | {
17 | public:
18 | PredictModel(
19 | const std::string& src = "",
20 | const std::string& mapfile = "information.txt",
21 | const std::string& xml = "MyFaceEigen.xml")
22 | : m_sFilename(src), m_pfModel(createEigenFaceRecognizer())
23 | {
24 | if (m_mMap.empty()) {
25 | initMap(mapfile);
26 | }
27 |
28 | m_pfModel->load(xml);
29 |
30 | }
31 |
32 | void initMap(const std::string& information, const std::string& pattern_ = ";")
33 | {
34 | // Open csv file and put the data into the relevent container.
35 | //
36 | FILE* fp = fopen(information.c_str(), "r");
37 | char szTest[100] = { 0 };
38 | while (fgets(szTest, sizeof(szTest), fp)) {
39 | char* label = strtok(szTest, pattern_.c_str());
40 | char* name = strtok(NULL, pattern_.c_str());
41 | if (sizeof(label) != 0 && sizeof(name) != 00) {
42 | m_mMap.insert(
43 | std::make_pair(
44 | atoi(label),
45 | name
46 | )
47 | );
48 | }
49 | }
50 | }
51 |
52 | void loadXml(const std::string& xml_)
53 | {
54 | m_pfModel->load(xml_);
55 | }
56 |
57 | void loadImage(const std::string& filename_)
58 | {
59 | m_sFilename = filename_;
60 | }
61 |
62 | void prediction()
63 | {
64 | if (m_sFilename.empty()) {
65 | std::cout << "No images loaded" << std::endl;
66 | }
67 | else {
68 | cv::Mat img = cv::imread(m_sFilename, CV_LOAD_IMAGE_GRAYSCALE);
69 | int predicted = m_pfModel->predict(img);
70 | try
71 | {
72 | m_upUser = std::make_unique();
73 | m_upUser->setUsername(m_mMap[predicted]);
74 | m_upUser->queryUser();
75 | m_upUser->showUser();
76 | }
77 | catch (const std::exception& e)
78 | {
79 | std::cerr << e.what() << std::endl;
80 | }
81 |
82 | }
83 | }
84 |
85 | void prediction(cv::Mat& img_)
86 | {
87 | int predicted = m_pfModel->predict(img_);
88 |
89 | try
90 | {
91 | m_upUser = std::make_unique();
92 | m_upUser->setUsername(m_mMap[predicted]);
93 | m_upUser->queryUser();
94 | m_upUser->showUser();
95 | }
96 | catch (const std::exception& e)
97 | {
98 | std::cerr << e.what() << std::endl;
99 | }
100 |
101 | }
102 |
103 | private:
104 | std::string m_sFilename;
105 | cv::Ptr m_pfModel;
106 | std::map m_mMap;
107 | std::unique_ptr m_upUser;
108 | };
109 |
110 | #endif // !SRC_PREDICTMODEL_H__
111 |
--------------------------------------------------------------------------------
/Face_Recognize/C++/src/DatabaseModel.h:
--------------------------------------------------------------------------------
1 | #ifndef SRC_DATABASE_DATABASEMODEL_H__
2 | #define SRC_DATABASE_DATABASEMODEL_H__
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | class DataBaseModel : boost::noncopyable
10 | {
11 | public:
12 | explicit DataBaseModel(
13 | const std::string& host_,
14 | const std::string& user_,
15 | const std::string& pwd_,
16 | const std::string& database_,
17 | unsigned int port_ = 3306)
18 | : m_sHost(host_), m_sUser(user_), m_sPasswd(pwd_), m_sDatabase(database_), m_uiPort(port_)
19 | {
20 | initConnect();
21 | }
22 |
23 | // 由于专门针对的数据库,所以这里做了特别处理
24 | MYSQL_ROW query(const std::string& query_string)
25 | {
26 | MYSQL_RES* result;
27 | MYSQL_ROW sql_row;
28 |
29 | unsigned int num_fields;
30 | unsigned int num_rows;
31 |
32 | if (!mysql_query(&m_Mysql, query_string.c_str())) {
33 | // Call mysql_store_result() and gotten back a result that is not a null pointer
34 | //
35 | result = mysql_store_result(&m_Mysql);
36 | num_rows = mysql_num_rows(result);
37 |
38 | if (result && num_rows >= 1) {
39 | // Find out how many rows are in the result set.
40 | //
41 | num_fields = mysql_num_fields(result);
42 |
43 | if ((sql_row = mysql_fetch_row(result))) {
44 | mysql_free_result(result);
45 | return sql_row;
46 | }
47 | }
48 | else {
49 | if (mysql_errno(&m_Mysql)) {
50 | std::cerr << "Error: " << mysql_error(&m_Mysql) << std::endl;
51 | }
52 | else if (mysql_field_count(&m_Mysql) == 0) {
53 | // query does not return data
54 | // (it was not a SELECT)
55 | num_rows = mysql_affected_rows(&m_Mysql);
56 | // ...
57 | }
58 | else if (num_rows == 0) {
59 | std::cout << "No data!" << std::endl;
60 | }
61 | }
62 | }
63 | else {
64 | std::cout << "query sql failed!" << std::endl;
65 | return NULL;
66 | }
67 | }
68 |
69 |
70 | private:
71 | void initConnect()
72 | {
73 | mysql_init(&m_Mysql);
74 |
75 | //mysql_options()
76 |
77 | if (!mysql_real_connect(
78 | &m_Mysql,
79 | m_sHost.c_str(), m_sUser.c_str(), m_sPasswd.c_str(), m_sDatabase.c_str(),
80 | m_uiPort, nullptr, 0))
81 | {
82 | std::cerr << "Failed to connect to database: Error: " << mysql_error(&m_Mysql) << std::endl;
83 | // exception handler
84 | }
85 | else {
86 | // zero for success. Nonzero if an error eccurred.
87 | if (mysql_query(&m_Mysql, "SET NAMES GBK")) {
88 | std::cerr << "Failed to query: Error: " << mysql_error(&m_Mysql) << std::endl;
89 | // exception handler
90 | }
91 | }
92 | }
93 |
94 | private:
95 | MYSQL m_Mysql;
96 | std::string m_sHost;
97 | std::string m_sUser;
98 | std::string m_sPasswd;
99 | std::string m_sDatabase;
100 | unsigned int m_uiPort;
101 | };
102 |
103 | #endif // !SRC_DATABASE_DATABASEMODEL_H__
104 |
--------------------------------------------------------------------------------
/MachineLearning/decision_tree/C4.5/C4.5.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * ========================================
3 | * @Author = xefvan
4 | * @Remark = C4.5
5 | * @Version = 1.0
6 | * @DateTime = 2017-09-16 21:31:03
7 | * ========================================
8 | */
9 |
10 | #include "require.h"
11 | #include "decisionstructure.h"
12 | #include
13 | #include
14 | #include
15 |
16 | // C4.5决策算法 -- 西瓜决策树
17 | TreeRoot TreeGenerate(TreeRoot pTree,
18 | std::vector datas, // 训练集
19 | std::vector attributes, // 属性集
20 | std::map> map_attr)
21 | {
22 | if (belongs_same_label(datas, "yes")) {
23 | // All samples are positive.
24 | pTree->attribute = "yes";
25 | return pTree;
26 | }
27 | else if (belongs_same_label(datas, "no")) {
28 | // All samples are negative.
29 | pTree->attribute = "no";
30 | return pTree;
31 | }
32 | else {
33 | if (attributes.empty()) {
34 | pTree->attribute = majority_of_category(datas);
35 | return pTree;
36 | }
37 | else {
38 | std::pair> optimal_attrs = \
39 | optimal_attribute(datas, attributes, map_attr);
40 | pTree->attribute = optimal_attrs.first;
41 | for (auto aptimal_attr : optimal_attrs.second) {
42 | Node* new_node = new Node();
43 | new_node->edgeValue = aptimal_attr;
44 |
45 | std::vector new_datas = remain_watermelon_datas(
46 | datas, aptimal_attr, optimal_attrs.first);
47 | if (new_datas.empty()) {
48 | new_node->attribute = majority_of_category(datas);
49 | // return pTree;
50 | }
51 | else {
52 | std::vector new_attributes;
53 | for (auto train_attribute : attributes) {
54 | if (train_attribute.compare(optimal_attrs.first)) {
55 | new_attributes.push_back(train_attribute);
56 | }
57 | }
58 | TreeGenerate(new_node, new_datas, new_attributes, map_attr);
59 | }
60 |
61 | pTree->childs.push_back(new_node);
62 | }
63 | }
64 | }
65 |
66 | return pTree;
67 | }
68 |
69 | int main(int argc, char const *argv[])
70 | {
71 | std::vector datas;
72 | std::vector attributes;
73 | std::vector train_attributes;
74 |
75 | train_attributes.push_back("color");
76 | train_attributes.push_back("pedicle");
77 | train_attributes.push_back("sound");
78 | train_attributes.push_back("texture");
79 | train_attributes.push_back("umbilical");
80 | train_attributes.push_back("touch");
81 |
82 | // load the datas and attributes..
83 | //
84 | load_file(datas, attributes, "watermelondatas.txt");
85 |
86 | std::map> map_attr;
87 |
88 | // match attribute set..
89 | //
90 | match_properties(datas, attributes, map_attr);
91 |
92 | TreeRoot pTree = new Node();
93 | pTree = TreeGenerate(pTree, datas, train_attributes, map_attr);
94 | print_tree(pTree, 0);
95 |
96 |
97 | return 0;
98 | }
99 |
--------------------------------------------------------------------------------
/STL_re/library/xstl_algo_unique.h:
--------------------------------------------------------------------------------
1 | #ifndef LIBRARY_XSTL_ALGO_UNIQUE_H__
2 | #define LIBRARY_XSTL_ALGO_UNIQUE_H__
3 |
4 | namespace xstl
5 | {
6 | namespace algo
7 | {
8 | template
9 | ForwardIt unique(ForwardIt first, ForwardIt last)
10 | {
11 | if(first == last) {
12 | return last;
13 | }
14 |
15 | ForwardIt result = first;
16 | while(++first != last) {
17 | if(!(*result == *first) && ++result != first) {
18 | *result = std::move(*first);
19 | }
20 | }
21 | return result;
22 | }
23 |
24 | /* Since C++17
25 | template
26 | ForwardIt unique(ExecutionPolicy&& policy, ForwardIt first, ForwardIt last)
27 | {
28 |
29 | }
30 | */
31 |
32 | template
33 | ForwardIt unique(ForwardIt first, ForwardIt last, BinaryPredicate p)
34 | {
35 | if(first == last) {
36 | return last;
37 | }
38 |
39 | ForwardIt result = first;
40 | while(++first != last) {
41 | if(!p(*result, *first) && ++result != first) {
42 | *result = std::move(*first);
43 | }
44 | }
45 | return result;
46 | }
47 |
48 | /* Since C++17
49 | template
50 | ForwardIt unique(ExecutionPolicy&& policy, ForwardIt first, ForwardIt last, BinaryPredicate p)
51 | {
52 |
53 | }
54 | */
55 |
56 | template
57 | OutputIt unique_copy(InputIt first, InputIt last,
58 | OutputIt d_first)
59 | {
60 | if(first == last) {
61 | return d_first;
62 | }
63 |
64 | InputIt result = first;
65 | *d_first = *first;
66 | while(++first != last) {
67 | if(!(*result == *first) && ++result != first) {
68 | *result = std::move(*first);
69 | }
70 | *++d_first = *result;
71 | }
72 | return ++d_first;
73 | }
74 |
75 | /* Since C++17
76 | template
77 | OutputIt unqiue_copy(ExecutionPolicy&& policy, InputIt first, InputIt last,
78 | OutputIt d_first)
79 | {
80 |
81 | }
82 | */
83 |
84 | template
85 | OutputIt unique_copy(InputIt first, InputIt last,
86 | OutputIt d_first, BinaryPredicate p)
87 | {
88 | if(first == last) {
89 | return d_first;
90 | }
91 |
92 | InputIt result = first;
93 | *d_first = *first;
94 | while(++first != last) {
95 | if(!p(*result, *first) && ++result != first) {
96 | *result = std::move(*first);
97 | }
98 | *++d_first = *result;
99 | }
100 | return ++d_first;
101 | }
102 |
103 | /* Since C++17
104 | template
105 | OutputIt unqiue_copy(ExecutionPolicy&& policy, InputIt first, InputIt last,
106 | OutputIt d_first, BinaryPredicate p)
107 | {
108 |
109 | }
110 | */
111 | }
112 | }
113 |
114 | #endif // LIBRARY_XSTL_ALGO_UNIQUE_H__
--------------------------------------------------------------------------------
/MachineLearning/decision_tree/ID3/ID3.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * ========================================
3 | * @Author = xefvan
4 | * @Remark = TreeGenerate(D, A)
5 | * @Version = 1.0
6 | * @DateTime = 2017-09-06 20:30:44
7 | * ========================================
8 | */
9 |
10 | #include "require.h"
11 | #include "decisionstructure.h"
12 | #include
13 | #include
14 | #include
15 |
16 | // ID3决策算法 -- 西瓜决策树
17 | TreeRoot TreeGenerate(TreeRoot pTree,
18 | std::vector datas, // 训练集
19 | std::vector attributes, // 属性集
20 | std::map> map_attr)
21 | {
22 | if (belongs_same_label(datas, "yes")) {
23 | // All samples are positive.
24 | pTree->attribute = "yes";
25 | return pTree;
26 | }
27 | else if (belongs_same_label(datas, "no")) {
28 | // All samples are negative.
29 | pTree->attribute = "no";
30 | return pTree;
31 | }
32 | else {
33 | if (attributes.empty()) {
34 | pTree->attribute = majority_of_category(datas);
35 | return pTree;
36 | }
37 | else {
38 | std::pair> optimal_attrs = \
39 | optimal_attribute(datas, attributes, map_attr);
40 | pTree->attribute = optimal_attrs.first;
41 | for (auto aptimal_attr : optimal_attrs.second) {
42 | Node* new_node = new Node();
43 | new_node->edgeValue = aptimal_attr;
44 |
45 | std::vector new_datas = remain_watermelon_datas(
46 | datas, aptimal_attr, optimal_attrs.first);
47 | if (new_datas.empty()) {
48 | new_node->attribute = majority_of_category(datas);
49 | // return pTree;
50 | }
51 | else {
52 | std::vector new_attributes;
53 | for (auto train_attribute : attributes) {
54 | if (train_attribute.compare(optimal_attrs.first)) {
55 | new_attributes.push_back(train_attribute);
56 | }
57 | }
58 | TreeGenerate(new_node, new_datas, new_attributes, map_attr);
59 | }
60 |
61 | pTree->childs.push_back(new_node);
62 | }
63 | }
64 | }
65 |
66 | return pTree;
67 | }
68 |
69 | int main(int argc, char const *argv[])
70 | {
71 | std::vector datas;
72 | std::vector attributes;
73 | std::vector train_attributes;
74 |
75 | train_attributes.push_back("color");
76 | train_attributes.push_back("pedicle");
77 | train_attributes.push_back("sound");
78 | train_attributes.push_back("texture");
79 | train_attributes.push_back("umbilical");
80 | train_attributes.push_back("touch");
81 |
82 | // load the datas and attributes..
83 | //
84 | load_file(datas, attributes, "watermelondatas.txt");
85 |
86 | std::map> map_attr;
87 |
88 | // match attribute set..
89 | //
90 | match_properties(datas, attributes, map_attr);
91 |
92 | TreeRoot pTree = new Node();
93 |
94 | pTree = TreeGenerate(pTree, datas, train_attributes, map_attr);
95 |
96 | print_tree(pTree, 0);
97 |
98 |
99 | return 0;
100 | }
101 |
--------------------------------------------------------------------------------
/STL_re/test/vector_test.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "../library/xstl_allocator.h"
5 | #include "../library/xstl_vector.h"
6 | using namespace std;
7 |
8 | int main(int argc, char const *argv[])
9 | {
10 | xstl::vector vec1 = { 1, 2, 3 };
11 | for (unsigned i = 0; i < vec1.size(); ++i) {
12 | cout << vec1[i] << " ";
13 | }
14 | cout << endl;
15 |
16 | xstl::vector vec2(vec1.begin(), vec1.end());
17 | for (unsigned i = 0; i < vec2.size(); ++i) {
18 | cout << vec2[i] << " ";
19 | }
20 | cout << endl;
21 |
22 | xstl::vector vec3(vec1);
23 | for (unsigned i = 0; i < vec3.size(); ++i) {
24 | cout << vec3[i] << " ";
25 | }
26 | cout << endl;
27 |
28 | xstl::vector vec4(3, 0);
29 | for (unsigned i = 0; i < vec4.size(); ++i) {
30 | cout << vec4[i] << " ";
31 | }
32 | cout << endl;
33 |
34 | xstl::vector vec5;
35 | vec5 = vec1;
36 | for (unsigned i = 0; i < vec5.size(); ++i) {
37 | cout << vec5[i] << " ";
38 | }
39 | cout << endl;
40 |
41 | xstl::vector vec6;
42 | vec6.assign(5, 1);
43 | for (unsigned i = 0; i < vec6.size(); ++i) {
44 | cout << vec6[i] << " ";
45 | }
46 | cout << endl;
47 |
48 | cout << vec1.at(1) << endl;
49 | cout << vec1[1] << endl;
50 | cout << vec1.front() << endl;
51 | cout << vec1.back() << endl;
52 | int* p = vec1.data();
53 | *p = 10;
54 | ++p;
55 | *p = 20;
56 | *++p = 100;
57 |
58 | for (xstl::vector::iterator i = vec1.begin(); i != vec1.end(); ++i) {
59 | cout << *i << " ";
60 | }
61 | cout << endl;
62 |
63 | for (xstl::vector::const_iterator i = vec1.cbegin(); i != vec1.cend(); ++i) {
64 | cout << *i << " ";
65 | }
66 | cout << endl;
67 |
68 | for (xstl::vector::reverse_iterator i = vec1.rbegin(); i != vec1.rend(); ++i) {
69 | cout << *i << " ";
70 | }
71 | cout << endl;
72 |
73 | for (xstl::vector::const_reverse_iterator i = vec1.crbegin(); i != vec1.crend(); ++i) {
74 | cout << *i << " ";
75 | }
76 | cout << endl;
77 |
78 | if (!vec1.empty()) {
79 | cout << "vec1 is not empty" << endl;
80 | }
81 | else {
82 | cout << "vec1 is empty" << endl;
83 | }
84 |
85 | cout << vec1.size() << endl;
86 |
87 | cout << vec1.max_size() << endl;
88 |
89 | cout << vec1.capacity() << endl;
90 |
91 | vec1.clear();
92 | if (vec1.empty()) {
93 | cout << "After clear() the vec1 is empty" << endl;
94 | }
95 |
96 | xstl::vector::iterator i = vec1.begin();
97 | vec1.insert(i, 100);
98 | cout << vec1[0] << endl;
99 |
100 | vec1.erase(vec1.begin());
101 |
102 | if (vec1.empty()) {
103 | cout << "After erase() the vec1 is empty" << endl;
104 | }
105 |
106 | vec1.push_back(100);
107 | cout << vec1[0] << endl;
108 |
109 | vec1.pop_back();
110 | cout << vec1.size() << endl;
111 |
112 | vec2.resize(5);
113 | for (unsigned i = 0; i < vec2.size(); ++i) {
114 | cout << vec2[i] << " ";
115 | }
116 | cout << endl;
117 |
118 | cout << "Before swap ---" << endl;
119 | for (unsigned i = 0; i < vec4.size(); ++i) {
120 | cout << vec4[i] << " ";
121 | }
122 | cout << endl;
123 | cout << "After swap ---" << endl;
124 | vec4.swap(vec2);
125 | for (unsigned i = 0; i < vec4.size(); ++i) {
126 | cout << vec4[i] << " ";
127 | }
128 | cout << endl;
129 |
130 |
131 | return 0;
132 | }
--------------------------------------------------------------------------------
/STL_re/test/algorithm_test.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "../library/xstl_algorithm.h"
7 |
8 | struct Sum
9 | {
10 | Sum() : sum{0} { }
11 | void operator()(int n) { sum += n; }
12 | int sum;
13 | };
14 |
15 | bool is_palindrome(const std::string& s)
16 | {
17 | return xstl::algo::equal(s.begin(), s.begin() + s.size() / 2, s.rbegin());
18 | }
19 |
20 | void test(const std::string& s)
21 | {
22 | std::cout << "\"" << s << "\""
23 | << (is_palindrome(s) ? "is" : "is not")
24 | << " a is_palindrome" << std::endl;
25 | }
26 |
27 | int main(int argc, char const *argv[])
28 | {
29 | std::vector v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
30 | // fill
31 | xstl::algo::fill(v.begin(), v.end(), 1);
32 | // fill_n
33 | xstl::algo::fill_n(std::back_inserter(v), 5, -1);
34 | // copy
35 | xstl::algo::copy(v.cbegin(), v.cend(), std::ostream_iterator(std::cout, " "));
36 | std::cout << std::endl;
37 | // copy_n
38 | std::string in = "123456";
39 | std::string out;
40 | xstl::algo::copy_n(in.cbegin(), 4, std::back_inserter(out));
41 | std::cout << out << std::endl;
42 | // copy_backward
43 | std::vector from_vector;
44 | from_vector.reserve(10);
45 | for(int i = 1; i <= 10; ++i) {
46 | from_vector.push_back(i);
47 | }
48 | std::vector to_vector(15);
49 | xstl::algo::copy_backward(from_vector.cbegin(), from_vector.cend(), to_vector.end());
50 | xstl::algo::copy(to_vector.cbegin(), to_vector.cend(), std::ostream_iterator(std::cout, " "));
51 | std::cout << std::endl;
52 |
53 | // unique
54 | std::vector vec{1, 1, 2, 3, 3, 3, 4};
55 | xstl::algo::unique(vec.begin(), vec.end());
56 | xstl::algo::copy(vec.cbegin(), vec.cend(), std::ostream_iterator(std::cout, " "));
57 | std::cout << std::endl;
58 |
59 | std::string s = "wanna go to space?";
60 | std::cout << s << std::endl;
61 | auto send = xstl::algo::unique(s.begin(), s.end(), [](char l, char r){
62 | return std::isspace(l) && std::isspace(r) && l == r;
63 | });
64 | std::cout << std::string(s.begin(), send) << std::endl;
65 |
66 | // unique_copy
67 | std::string s1 = "The string with many spaces!";
68 | std::cout << "before: " << s1 << std::endl;
69 | std::string s2;
70 | std::string s3;
71 | xstl::algo::unique_copy(s1.begin(), s1.end(), std::back_inserter(s2));
72 | std::cout << "s2: " << s2 << std::endl;
73 | xstl::algo::unique_copy(s1.begin(), s1.end(), std::back_inserter(s3),
74 | [](char c1, char c2){ return c1 == ' ' && c2 == ' '; });
75 | std::cout << "after: " << s3 << std::endl;
76 |
77 | // for_each
78 | std::vector nums{3, 4, 2, 8, 15, 267};
79 | auto print = [](const int& i) { std::cout << " " << i; };
80 |
81 | std::cout << "before:";
82 | std::for_each(nums.begin(), nums.end(), print);
83 | std::cout << std::endl;
84 |
85 | std::for_each(nums.begin(), nums.end(), [](int& n) { n++; });
86 |
87 | Sum sss = std::for_each(nums.begin(), nums.end(), Sum());
88 |
89 | std::cout << "after: ";
90 | std::for_each(nums.begin(), nums.end(), print);
91 | std::cout << std::endl;
92 | std::cout << "sum:" << sss.sum << std::endl;
93 |
94 | // equal
95 | test("radar");
96 | test("hello");
97 | std::string str1 = "radar";
98 | if(xstl::algo::equal(str1.begin(), str1.end(), str1.rbegin(), str1.rend())) {
99 | std::cout << "Yes" << std::endl;
100 | }
101 | else {
102 | std::cout << "No" << std::endl;
103 | }
104 |
105 | return 0;
106 | }
--------------------------------------------------------------------------------
/Face_Recognize/C++/src/UserCenterModel.h:
--------------------------------------------------------------------------------
1 | #ifndef SRC_USERCENTERMODEL_H__
2 | #define SRC_USERCENTERMODEL_H__
3 |
4 | #include "DatabaseModel.h"
5 | #include
6 | #include
7 |
8 | template
9 | auto CheckIfNull(T t)
10 | {
11 | return t == nullptr ? "" : t;
12 | }
13 |
14 | class UserCenterModel
15 | {
16 | public:
17 | UserCenterModel(const std::string& name_ = "") :
18 | m_sUsername(name_),
19 | m_dbMysql("数据库地址", "数据库用户名", "数据库密码", "数据库表"),
20 | fmt("SQL语句")
21 | {
22 | // empty
23 | }
24 |
25 | void queryUser()
26 | {
27 | if (!m_sUsername.empty()) {
28 | fmt % m_sUsername;
29 |
30 | m_mSql_row = m_dbMysql.query(fmt.str());
31 |
32 | m_sStudentId = CheckIfNull(m_mSql_row[0]);
33 | m_sName = CheckIfNull(m_mSql_row[1]);
34 | m_sType = CheckIfNull(m_mSql_row[2]);
35 | m_sAdmissionTime = CheckIfNull(m_mSql_row[3]);
36 | m_sIDcard = CheckIfNull(m_mSql_row[4]);
37 | m_sSex = CheckIfNull(m_mSql_row[5]);
38 | m_sBirthday = CheckIfNull(m_mSql_row[6]);
39 | m_sNativeplace = CheckIfNull(m_mSql_row[7]);
40 | m_sTelephone = CheckIfNull(m_mSql_row[8]);
41 | m_sBedroom = CheckIfNull(m_mSql_row[9]);
42 | m_sQQ = CheckIfNull(m_mSql_row[10]);
43 | }
44 | }
45 |
46 | void showUser()
47 | {
48 | if (!m_sUsername.empty()) {
49 | std::cout << "m_sStudentId :" << m_sStudentId << std::endl;
50 | std::cout << "m_sName :" << m_sName << std::endl;
51 | std::cout << "m_sType :" << m_sType << std::endl;
52 | std::cout << "m_sAdmissionTime :" << m_sAdmissionTime << std::endl;
53 | std::cout << "m_sIDcard :" << m_sIDcard << std::endl;
54 | std::cout << "m_sSex :" << m_sSex << std::endl;
55 | std::cout << "m_sBirthday :" << m_sBirthday << std::endl;
56 | std::cout << "m_sNativeplace :" << m_sNativeplace << std::endl;
57 | std::cout << "m_sTelephone :" << m_sTelephone << std::endl;
58 | std::cout << "m_sBedroom :" << m_sBedroom << std::endl;
59 | std::cout << "m_sQQ :" << m_sQQ << std::endl;
60 | std::cout << std::endl;
61 | }
62 | }
63 |
64 | void setUsername(const std::string& username_)
65 | {
66 | m_sUsername = username_;
67 | }
68 |
69 | const std::string Id() const
70 | {
71 | return m_sStudentId;
72 | }
73 |
74 | const std::string Name() const
75 | {
76 | return m_sName;
77 | }
78 |
79 | const std::string Type() const
80 | {
81 | return m_sType;
82 | }
83 |
84 | const std::string Admission() const
85 | {
86 | return m_sAdmissionTime;
87 | }
88 |
89 | const std::string Idcard() const
90 | {
91 | return m_sIDcard;
92 | }
93 |
94 | const std::string Sex() const
95 | {
96 | return m_sSex;
97 | }
98 |
99 | const std::string Birthday() const
100 | {
101 | return m_sBirthday;
102 | }
103 |
104 | const std::string Native() const
105 | {
106 | return m_sNativeplace;
107 | }
108 |
109 | const std::string Telephone() const
110 | {
111 | return m_sTelephone;
112 | }
113 |
114 | const std::string Bedroom() const
115 | {
116 | return m_sBedroom;
117 | }
118 |
119 | const std::string QQ() const
120 | {
121 | return m_sQQ;
122 | }
123 |
124 | private:
125 | std::string m_sUsername;
126 |
127 | std::string m_sStudentId; // 学号
128 | std::string m_sName; // 姓名
129 | std::string m_sType; // 学生类别
130 | std::string m_sAdmissionTime; // 入学年月
131 | std::string m_sIDcard; // 身份号
132 | std::string m_sSex; // 性别
133 | std::string m_sBirthday; // 出生年月
134 | std::string m_sNativeplace; // 籍贯
135 | std::string m_sTelephone; // 手机号码
136 | std::string m_sBedroom; // 寝室号
137 | std::string m_sQQ; // qq号
138 | DataBaseModel m_dbMysql; // 数据库
139 | boost::format fmt; // 搜索匹配字符
140 | MYSQL_ROW m_mSql_row;
141 |
142 | };
143 |
144 | #endif // !SRC_USERCENTERMODEL_H__
145 |
--------------------------------------------------------------------------------
/Spider/Taobao/login_taobao.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # coding=utf-8
3 |
4 | import random
5 | from urllib import request, parse
6 | import time
7 | from selenium import webdriver
8 | from selenium.webdriver.common.action_chains import ActionChains
9 | from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
10 |
11 | class Taobao:
12 |
13 | def __init__(self):
14 |
15 | # 淘宝个人页面
16 | self.url='https://i.taobao.com/my_taobao.htm'
17 | # 淘宝登录页面
18 | self.login_url = "https://login.taobao.com/member/login.jhtml"
19 | # 帐号和密码
20 | self.username = ''
21 | self.password = ''
22 |
23 | self.proxy = '117.36.103.170'
24 | self.port = '8118'
25 |
26 | # Chrome浏览器
27 | # chrome_options = webdriver.ChromeOptions()
28 | # chrome_options.add_argument('--proxy-server=http://' + self.proxy + self.port)
29 | # self.driver = webdriver.Chrome(chrome_options=chrome_options)
30 |
31 | # # Firefox浏览器
32 | profile = FirefoxProfile()
33 | profile.set_preference("network.proxy.type", 1)
34 | profile.set_preference("network.proxy.http", self.proxy)
35 | profile.set_preference("network.proxy.http_port", self.port)
36 | profile.set_preference("network.proxy.share_proxy_settings", True)
37 | self.driver = webdriver.Firefox(profile)
38 | self.driver.implicitly_wait(5)
39 |
40 | # Token
41 | self._tb_token_ = ''
42 |
43 | def login(self):
44 | self.driver.get(self.login_url)
45 | time.sleep(3)
46 |
47 | # 普通登录
48 | self.driver.find_element_by_id("J_Quick2Static").click()
49 |
50 | # 输入帐号密码
51 | username = self.driver.find_element_by_id("TPL_username_1")
52 | username.clear()
53 | username.send_keys(self.username)
54 | password = self.driver.find_element_by_id("TPL_password_1")
55 | password.clear()
56 | password.send_keys(self.password)
57 |
58 | time.sleep(3)
59 |
60 | while True:
61 | try:
62 | # 检验是否需要滑动解锁
63 | check = self.driver.find_element_by_xpath("//*[@id='nocaptcha']")
64 | if not check.is_displayed():
65 | break
66 |
67 | #定位滑块元素
68 | source = self.driver.find_element_by_xpath("//*[@id='nc_1_n1z']")
69 | time.sleep(3)
70 |
71 | #定义鼠标拖放动作
72 | action = ActionChains(self.driver)
73 | action.click_and_hold(source).perform()
74 |
75 | for index in range(3):
76 | try:
77 | action.move_by_offset(100, 0).perform() #平行移动鼠标
78 | except Exception as e:
79 | print(e)
80 | break
81 | if(index == 3):
82 | action.release()
83 | time.sleep(1)
84 | else:
85 | time.sleep(0.01) #等待停顿时间
86 |
87 | #等待JS认证运行,如果不等待容易报错
88 | time.sleep(3)
89 | #查看是否认证成功,获取text值
90 | text = self.driver.find_element_by_xpath("//*[@id='nc_1__scale_text']/span")
91 | if text.text.startswith(u'验证通过'):
92 | print('成功滑动')
93 | break
94 | if text.text.startswith(u'请点击'):
95 | print('成功滑动')
96 | break
97 | if text.text.startswith(u'请按住'):
98 | continue
99 | except Exception as e:
100 | print(e)
101 | self.driver.find_element_by_xpath("//div[@id='nocaptcha']/div/span/a").click()
102 |
103 | res = ""
104 | while True:
105 | url = self.driver.current_url
106 | if not url.startswith("https://login.taobao.com"):
107 | cookies = self.driver.get_cookies()
108 | for cookie in cookies:
109 | res += cookie.get('name')+'='+cookie.get('value')+';'
110 | res = res[:-1]
111 | break
112 |
113 | try:
114 | self.driver.find_element_by_id("J_SubmitStatic").click()
115 | except Exception as e:
116 | print(e)
117 |
118 | time.sleep(3)
119 |
120 | self.driver.quit()
121 | return res
122 |
123 | # cookie登录
124 | def getInfo(self, cookie):
125 | try:
126 | headers = {
127 | 'Host': 'i.taobao.com',
128 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0',
129 | 'Accept': '*/*',
130 | 'Referer': 'https://www.taobao.com/',
131 | 'Connection': 'keep-alive',
132 | 'Cookie': cookie
133 | }
134 | req = request.Request(url = self.url, headers = headers)
135 | response = request.urlopen(req)
136 | html = response.read().decode()
137 |
138 | # 获取信息的各种操作
139 | print("获取到各种信息...")
140 | with open("rsp.html","w",encoding="utf-8") as f:
141 | f.write(html)
142 | except:
143 | print("获取信息失败...")
144 |
145 | def main(self):
146 | cookie = self.login()
147 | self.getInfo(cookie)
148 |
149 | taobao = Taobao()
150 | taobao.main()
151 |
--------------------------------------------------------------------------------
/STL_re/library/xstl_allocator.h:
--------------------------------------------------------------------------------
1 | #ifndef LIBRARY_XSTL_ALLOCATOR_H__
2 | #define LIBRARY_XSTL_ALLOCATOR_H__
3 |
4 | #include // for UINT_MAX
5 | #include // for std::ptrdiff_t, std::size_t
6 | #include // for exit()
7 | #include // for std::cerr, std::endl;
8 | #include // for placement new
9 | #include // for std::true_type
10 |
11 | namespace xstl
12 | {
13 | template
14 | inline T* _allocate(std::ptrdiff_t size, T*)
15 | {
16 | std::set_new_handler(0);
17 | T* tmp = (T*)(::operator new((static_cast(size * sizeof(T)))));
18 | if(tmp == 0) {
19 | std::cerr << "Out of memory" << std::endl;
20 | exit(1);
21 | }
22 | return tmp;
23 | }
24 |
25 | template
26 | inline void _deallocate(T* buffer, std::size_t /* n */)
27 | {
28 | ::operator delete(buffer);
29 | }
30 |
31 | template
32 | inline void _construct(T1* p, const T2& val)
33 | {
34 | new ((void *)p) T1(val);
35 | }
36 |
37 | template
38 | inline void _destroy(T* ptr)
39 | {
40 | ptr->~T();
41 | }
42 |
43 | // simple_alloc
44 | template
45 | class simple_alloc
46 | {
47 | public:
48 | static T* allocate(std::size_t n)
49 | {
50 | // return 0 == n ? 0 : (T*) Alloc::allocate(n * sizeof(T));
51 | // return 0 == n ? 0 : (T*) _allocate(n * sizeof(T));
52 | return _allocate(static_cast(n * sizeof(T)),
53 | static_cast(0));
54 | }
55 |
56 | static T* allocate(void)
57 | {
58 | // return (T*)Alloc::allocate(sizeof(T));
59 | // return (T*)_allocate(sizeof(T));
60 | return _allocate(static_cast(sizeof(T)),
61 | static_cast(0));
62 | }
63 |
64 | static void deallocate(T* p, std::size_t n)
65 | {
66 | if(0 != n) {
67 | // Alloc::deallocate(p, n * sizeof(T));
68 | _deallocate(p, n * sizeof(T));
69 | }
70 | }
71 |
72 | static void deallocate(T* p)
73 | {
74 | // Alloc::deallocate(p, sizeof(T));
75 | _deallocate(p, sizeof(T));
76 | }
77 | };
78 |
79 |
80 | template
81 | class allocator
82 | {
83 | public:
84 | // Member types
85 | using value_type = T;
86 | using pointer = T*;
87 | using const_pointer = const T*;
88 | using reference = T&;
89 | using const_reference = const T&;
90 | using size_type = std::size_t;
91 | using difference_type = std::ptrdiff_t;
92 | // using propagate_on_container_move_assignment = std::true_type;
93 |
94 | // template struct rebind {
95 | // typedef allocator other;
96 | // };
97 | template
98 | using rebind = allocator;
99 | // using is_always_equal = std::true_type;
100 |
101 | public:
102 | // Member functions
103 | /*
104 | costructor && destructor
105 | */
106 | allocator() {}
107 | allocator(const allocator& other) {}
108 | template allocator(const allocator& other) {}
109 | ~allocator() {}
110 |
111 | /*
112 | address : obtains the address of an object, even if operator& is overloaded
113 | */
114 | pointer address(reference x) const
115 | {
116 | return static_cast(&x);
117 | }
118 |
119 | const_pointer address(const_reference x) const
120 | {
121 | return static_cast(&x);
122 | /*
123 | In sgi stl only return &x;
124 | */
125 | }
126 |
127 | /*
128 | allocate : allocates uninitialized storage
129 | */
130 | pointer allocate(size_type n, const void * hint = 0)
131 | {
132 | return _allocate(static_cast(n),
133 | static_cast(0));
134 | /*
135 | return n != 0 ? static_cast(_Alloc::allocte(n * sizeof(T*))) : 0;
136 | */
137 | }
138 |
139 | /*
140 | T* allocate(std::size_t n)
141 | {
142 | return _allocate(static_cast(n),
143 | static_cast(0));
144 | }
145 | */
146 |
147 | /*
148 | deallocate : deallocates storage
149 | */
150 | void deallocate(T* p, std::size_t n)
151 | {
152 | _deallocate(p, n * sizeof(T));
153 | }
154 |
155 | /*
156 | max_size : returns the largest supported allocation size
157 | */
158 | size_type max_size() const
159 | {
160 | return static_cast(UINT_MAX / sizeof(T));
161 | /*
162 | return size_t(-1) / sizeof(T);
163 | */
164 | }
165 |
166 | /*
167 | construct : constructs an object in allocated storage
168 | */
169 | void construct(pointer p, const_reference val)
170 | {
171 | _construct(p, val);
172 | }
173 |
174 | /*
175 | destroy : destructs an object in allocated storage
176 | */
177 | void destroy(pointer p)
178 | {
179 | _destroy(p);
180 | }
181 | };
182 |
183 | template<>
184 | class allocator
185 | {
186 | public:
187 | // Member types
188 | using value_type = void;
189 | using pointer = void*;
190 | using const_pointer = const void*;
191 | using size_type = std::size_t;
192 | using difference_type = std::ptrdiff_t;
193 | // using propagate_on_container_move_assignment = std::true_type;
194 |
195 | // template struct rebind {
196 | // typedef allocator other;
197 | // };
198 | template
199 | using rebind = allocator;
200 |
201 | // using is_always_equal = std::true_type;
202 | };
203 |
204 | template
205 | bool operator==(const allocator& lhs, const allocator& rhs)
206 | {
207 | return true;
208 | }
209 |
210 | template
211 | bool operator!=(const allocator& lhs, const allocator& rhs)
212 | {
213 | return false;
214 | }
215 | }
216 |
217 | #endif // LIBRARY_XSTL_ALLOCATOR_H__
--------------------------------------------------------------------------------
/Face_Recognize/C++/src/TrainningModel.h:
--------------------------------------------------------------------------------
1 | #ifndef SRC_TRAININGMODEL_H__
2 | #define SRC_TRAININGMODEL_H__
3 |
4 | //#include "PredictModel.h"
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | using namespace cv::face;
15 |
16 | class TrainningModel : boost::noncopyable/*, public Predict*/
17 | {
18 | public:
19 | explicit TrainningModel(
20 | const std::string& filename_,
21 | const std::string& mapfile = "information.txt") : m_sFilename(filename_)
22 | {
23 | initMap(mapfile);
24 | }
25 |
26 | /*
27 | TrainningModel() = delete;
28 | TrainningModel(const TrainningModel&) = delete;
29 | TrainningModel& operator=(const TrainningModel&) = delete;
30 | */
31 |
32 | void read_csv(const std::string& pattern_ = ";")
33 | {
34 | // Open csv file and put the data into the relevent container.
35 | //
36 | std::fstream fstrm(m_sFilename, std::ios::in | std::ios::binary | std::ios::ate);
37 | if (!fstrm.is_open()) {
38 | std::string error_message = "File read failed (One param): No file named " + m_sFilename;
39 | CV_Error(CV_StsInternal, error_message);
40 | }
41 | else {
42 | auto size = fstrm.tellg();
43 | std::string allStr(size, '\0');
44 | // Read back to the beginning
45 | //
46 | fstrm.seekg(0);
47 | if (fstrm.read(&allStr[0], size)) {
48 | std::istringstream toReadOL(allStr);
49 | // Read every line
50 | //
51 | for(std::array a; toReadOL.getline(&a[0], 100, '\n'); ) {
52 | // Being String split by pattern_
53 | std::string tmpStr = &a[0];
54 | size_t pos = tmpStr.find(pattern_);
55 | size_t size = tmpStr.size();
56 |
57 | // Cutting is done. Check if get to the end of file.
58 | if (pos != std::string::npos) {
59 | // holds images and labels
60 | m_vMImages.push_back(cv::imread(tmpStr.substr(0, pos), 0));
61 | m_vILabels.push_back(std::stoi(tmpStr.substr(pos + 1, size)));
62 | }
63 | }
64 | }
65 |
66 | // End read
67 | }
68 |
69 | if (m_vMImages.size() <= 1) {
70 | std::string error_message = "The number of images is insufficient";
71 | CV_Error(CV_BadImageSize, error_message);
72 | }
73 | }
74 |
75 | void read_csv(const std::string& filename_, const std::string& pattern_ = ";")
76 | {
77 | // Update the filename
78 | m_sFilename = filename_;
79 |
80 | // Open csv file and put the data into the relevent container.
81 | //
82 | std::fstream fstrm(m_sFilename, std::ios::in | std::ios::binary | std::ios::ate);
83 | if (!fstrm.is_open()) {
84 | std::string error_message = "File read failed (One param): No file named " + m_sFilename;
85 | CV_Error(CV_StsInternal, error_message);
86 | }
87 | else {
88 | auto size = fstrm.tellg();
89 | std::string allStr(size, '\0');
90 | // Read back to the beginning
91 | //
92 | fstrm.seekg(0);
93 | if (fstrm.read(&allStr[0], size)) {
94 | std::istringstream toReadOL(allStr);
95 | // Read every line
96 | //
97 | for (std::array a; toReadOL.getline(&a[0], 100, '\n'); ) {
98 | // Being String split by pattern_
99 | std::string tmpStr = &a[0];
100 | size_t pos = tmpStr.find(pattern_);
101 | size_t size = tmpStr.size();
102 |
103 | // Cutting is done. Check if get to the end of file.
104 | if (pos != std::string::npos) {
105 | // holds images and labels
106 | m_vMImages.push_back(cv::imread(tmpStr.substr(0, pos), 0));
107 | m_vILabels.push_back(std::stoi(tmpStr.substr(pos + 1, size)));
108 | }
109 | }
110 | }
111 |
112 | // End read
113 | }
114 |
115 | if (m_vMImages.size() <= 1) {
116 | std::string error_message = "The number of images is insufficient";
117 | CV_Error(CV_BadImageSize, error_message);
118 | }
119 | }
120 |
121 | std::pair, std::vector> read_csv_p(
122 | const std::string& filename_, const std::string& pattern_ = ";")
123 | {
124 | std::vector newImages;
125 | std::vector newLabels;
126 | // Open csv file and put the data into the relevent container.
127 | //
128 | std::fstream fstrm(m_sFilename, std::ios::in | std::ios::binary | std::ios::ate);
129 | if (!fstrm.is_open()) {
130 | std::string error_message = "File read failed (One param): No file named " + m_sFilename;
131 | CV_Error(CV_StsInternal, error_message);
132 | }
133 | else {
134 | auto size = fstrm.tellg();
135 | std::string allStr(size, '\0');
136 | // Read back to the beginning
137 | //
138 | fstrm.seekg(0);
139 | if (fstrm.read(&allStr[0], size)) {
140 | std::istringstream toReadOL(allStr);
141 | // Read every line
142 | //
143 | for (std::array a; toReadOL.getline(&a[0], 100, '\n'); ) {
144 | // Being String split by pattern_
145 | std::string tmpStr = &a[0];
146 | size_t pos = tmpStr.find(pattern_);
147 | size_t size = tmpStr.size();
148 |
149 | // Cutting is done. Check if get to the end of file.
150 | if (pos != std::string::npos) {
151 | // holds images and labels
152 | newImages.push_back(cv::imread(tmpStr.substr(0, pos), 0));
153 | newLabels.push_back(std::stoi(tmpStr.substr(pos + 1, size)));
154 | }
155 | }
156 | }
157 |
158 | // End read
159 | }
160 |
161 | if (newImages.size() <= 1) {
162 | std::string error_message = "The number of images is insufficient";
163 | CV_Error(CV_BadImageSize, error_message);
164 | }
165 |
166 | return std::make_pair(newImages, newLabels);
167 | }
168 |
169 | void train()
170 | {
171 | trainEigen();
172 | trainFisher();
173 | trainLBPH();
174 | }
175 |
176 | void trainEigen(const std::string& savefilename_ = "MyFaceEigen.xml")
177 | {
178 | if (m_pfEigenModel.empty()) {
179 | m_pfEigenModel = createEigenFaceRecognizer();
180 | m_pfEigenModel->train(m_vMImages, m_vILabels);
181 | //m_pfEigenModel->save(savefilename_);
182 | save(m_pfEigenModel, savefilename_);
183 | }
184 | }
185 |
186 | void trainFisher(const std::string& savefilename_ = "MyFaceFisher.xml")
187 | {
188 | if (m_pfFisherModel.empty()) {
189 | m_pfFisherModel = createFisherFaceRecognizer();
190 | m_pfFisherModel->train(m_vMImages, m_vILabels);
191 | //m_pfFisherModel->save(savefilename_);
192 | save(m_pfFisherModel, savefilename_);
193 | }
194 | }
195 |
196 | void trainLBPH(const std::string& savefilename_ = "MyFaceLBPH.xml")
197 | {
198 | if (m_pfLBPHModel.empty()) {
199 | m_pfLBPHModel = createLBPHFaceRecognizer();
200 | m_pfLBPHModel->train(m_vMImages, m_vILabels);
201 | //m_pfLBPHModel->save(savefilename_);
202 | save(m_pfLBPHModel, savefilename_);
203 | }
204 | }
205 |
206 | // Only createLBPHFaceRecognizer model supports updating
207 | //
208 | //void update(const std::string& filename_, const std::string& savefilename_ = "MyFaceLBPH.xml", const std::string& pattern_ = ";")
209 | //{
210 | // if (m_pfLBPHModel.empty()) {
211 | // m_pfLBPHModel = createLBPHFaceRecognizer();
212 | // }
213 | // auto new_container = read_csv_p(filename_, pattern_);
214 | // m_pfLBPHModel->update(new_container.first, new_container.second);
215 | // //m_pfLBPHModel->save(savefilename_);
216 | // save(m_pfLBPHModel, savefilename_);
217 | //}
218 |
219 | // 暂时只提供Eigen预测,等我想到如何解决不同算法参数的设置的时候在回来改这段代码
220 | void predict(const std::string& src)
221 | {
222 | // Read in a sample image:
223 | cv::Mat img = cv::imread(src, CV_LOAD_IMAGE_GRAYSCALE);
224 |
225 | // And get a prediction from cv::FaceRecognizer
226 | predicted = m_pfEigenModel->predict(img);
227 | /*std::cout << predicted << std::endl;*/
228 | }
229 |
230 | // If predicted is already trained.
231 | const std::string predictToName()
232 | {
233 | return m_mMap[predicted];
234 | }
235 |
236 | const std::string predictToName(const std::string& src)
237 | {
238 | // Read in a sample image:
239 | cv::Mat img = cv::imread(src, CV_LOAD_IMAGE_GRAYSCALE);
240 |
241 | // And get a prediction from cv::FaceRecognizer
242 | predicted = m_pfEigenModel->predict(img);
243 | return m_mMap[predicted];
244 | }
245 |
246 | void predict(const std::string& src, int& label, double& confidence)
247 | {
248 | // Read in a sample image:
249 | cv::Mat img = cv::imread(src, CV_LOAD_IMAGE_GRAYSCALE);
250 |
251 | // Get the prediction and associated confidence from the model
252 | m_pfEigenModel->predict(img, label, confidence);
253 | }
254 |
255 | inline void save(cv::Ptr& ptrFR_, const std::string& savefilename_)
256 | {
257 | ptrFR_->save(savefilename_);
258 | }
259 |
260 | void initMap(const std::string& information, const std::string& pattern_ = ";")
261 | {
262 | // Open csv file and put the data into the relevent container.
263 | //
264 | FILE* fp = fopen(information.c_str(), "r");
265 | char szTest[100] = { 0 };
266 | while (fgets(szTest, sizeof(szTest), fp)) {
267 | char* label = strtok(szTest, pattern_.c_str());
268 | char* name = strtok(NULL, pattern_.c_str());
269 | if (sizeof(label) != 0 && sizeof(name) != 00) {
270 | m_mMap.insert(
271 | std::make_pair(
272 | atoi(label),
273 | name
274 | )
275 | );
276 | }
277 | }
278 | }
279 |
280 | private:
281 | int predicted; // predictive value
282 | std::string m_sFilename; // csv file
283 | std::vector m_vMImages; // relevant container
284 | std::vector m_vILabels;
285 | cv::Ptr m_pfEigenModel;
286 | cv::Ptr m_pfFisherModel;
287 | cv::Ptr m_pfLBPHModel;
288 | std::map m_mMap;
289 | };
290 |
291 | #endif // !SRC_TRAININGMODEL_H__
292 |
--------------------------------------------------------------------------------
/MachineLearning/decision_tree/ID3/require.h:
--------------------------------------------------------------------------------
1 | #ifndef REQUIRE_H__
2 | #define REQUIRE_H__
3 |
4 | #include "decisionstructure.h"
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include