人脸识别保存和退出代码
时间: 2024-06-20 17:03:08 浏览: 11
人脸识别的保存和退出代码具体实现方式取决于使用的人脸识别库和语言。以下是一些常见的人脸识别库和语言的保存和退出代码实现方式供参考:
1. OpenCV + Python
保存人脸识别模型:
```python
import cv2
# 训练并保存模型
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.train(faces, labels)
recognizer.save('model.yml')
```
退出程序:
```python
cv2.destroyAllWindows()
```
2. Face Recognition + Python
保存人脸识别模型:
```python
import face_recognition
# 生成编码并保存
known_encodings = []
known_encodings.append(face_recognition.face_encodings(image_to_train))
with open("encodings.pkl", "wb") as f:
pickle.dump(known_encodings, f)
```
退出程序:
```python
sys.exit()
```
3. Dlib + C++
保存人脸识别模型:
```c++
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
using namespace dlib;
// 训练并保存模型
frontal_face_detector detector = get_frontal_face_detector();
shape_predictor sp;
deserialize("shape_predictor_68_face_landmarks.dat") >> sp;
serialize("shape_predictor_68_face_landmarks.dat") << sp;
```
退出程序:
```c++
return 0;
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)