self调用face_recognition的方法
时间: 2023-08-07 17:05:56 浏览: 88
Python3 利用face_recognition实现人脸识别的方法
在类中调用face_recognition模块中的face_locations()方法,示例代码如下:
```python
import face_recognition
class FaceDetector:
def __init__(self, image_path):
self.image_path = image_path
def detect_face(self):
image = face_recognition.load_image_file(self.image_path)
face_locations = face_recognition.face_locations(image)
return face_locations
```
其中,初始化方法__init__()接收一个图片路径参数image_path,并将其保存在类属性中。detect_face()方法调用face_recognition模块中的face_locations()方法对图片进行人脸检测,并返回人脸位置信息。在外部调用时,可以先创建FaceDetector类的实例,然后调用detect_face()方法即可:
```python
detector = FaceDetector("picture.jpg")
face_locations = detector.detect_face()
print(face_locations)
```
阅读全文