C:\WINDOWS\system32>pip install opencv-python
Collecting opencv-python
Downloading https://files.pythonhosted.org/packages/a3/50/04d0669afe884f137c2f490642756e8c4a658254300a9eaf253d1e643085/opencv_python-4.1.0.25-cp37-cp37m-win_amd64.whl (37.3MB)
100% |████████████████████████████████| 37.4MB 534kB/s
Collecting numpy>=1.14.5 (from opencv-python)
Downloading https://files.pythonhosted.org/packages/ce/61/be72eee50f042db3acf0b1fb86650ad36d6c0d9be9fc29f8505d3b9d6baa/numpy-1.16.4-cp37-cp37m-win_amd64.whl (11.9MB)
100% |████████████████████████████████| 11.9MB 2.4MB/s
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.16.4 opencv-python-4.1.0.25
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\WINDOWS\system32>
https://github.com/Mjrovai/OpenCV-Face-Recognition
https://www.jianshu.com/p/3e3b295e0e98 | https://blog.csdn.net/u012679707/article/details/80410094 |
---|---|
http://www.sohu.com/a/259092417_172964 | https://blog.csdn.net/yefeng215315434/article/details/80690539 |
#coding=utf8
import cv2, time
print('Press Esc to exit')
faceCascade = cv2.CascadeClassifier('Cascades/haarcascade_frontalface_default.xml')
imgWindow = cv2.namedWindow('FaceDetect', cv2.WINDOW_NORMAL)
def detect_face():
source = "http://192.168.0.100:8080/video"
capInput = cv2.VideoCapture(source)
# 避免处理时间过长造成画面卡顿
nextCaptureTime = time.time()
faces = []
if not capInput.isOpened(): print('Capture failed because of camera')
while 1:
ret, img = capInput.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
if nextCaptureTime < time.time():
nextCaptureTime = time.time() + 0.1
faces = faceCascade.detectMultiScale(gray, 1.1,3,0,(140,140))
if 0 < len(faces):
for x, y, w, h in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.imshow('FaceDetect', img)
# 这是简单的读取键盘输入,27即Esc的acsii码
if cv2.waitKey(1) & 0xFF == 27: break
capInput.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
detect_face()
sudo apt-get install libopencv-dev
sudo apt-get install python-opencv