├── rbp_py2 ├── _libfcnn.so ├── _mat.so ├── libfcnn.py └── mat.py ├── rbp_py3 ├── _libfcnn.so ├── _mat.so ├── libfcnn.py └── mat.py ├── readme.md ├── results └── output.mp4 ├── test.py └── videos └── neck-exercise.mp4 /rbp_py2/_libfcnn.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CharlieXie/libfacedetection-python-bindings/96e0fa45d287b1f1391e9c3126c97c0f029c989d/rbp_py2/_libfcnn.so -------------------------------------------------------------------------------- /rbp_py2/_mat.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CharlieXie/libfacedetection-python-bindings/96e0fa45d287b1f1391e9c3126c97c0f029c989d/rbp_py2/_mat.so -------------------------------------------------------------------------------- /rbp_py3/_libfcnn.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CharlieXie/libfacedetection-python-bindings/96e0fa45d287b1f1391e9c3126c97c0f029c989d/rbp_py3/_libfcnn.so -------------------------------------------------------------------------------- /rbp_py3/_mat.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CharlieXie/libfacedetection-python-bindings/96e0fa45d287b1f1391e9c3126c97c0f029c989d/rbp_py3/_mat.so -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## High-Speed(about 38 fps) face detector for python 2 | 3 | This a python binding for libfacedetection([https://github.com/ShiqiYu/libfacedetection](https://github.com/ShiqiYu/libfacedetection)). 4 | 5 | It is only tested on raspberry pi 3B which can reach about 38 fps even faster. Here is the [output](https://github.com/CharlieXie/libfacedetection-python-bindings/tree/master/results). 6 | 7 | ## How to use 8 | 9 | 1. You can just download the repo and run test.py which will find right lib according to default version of python in your system. 10 | 11 | 2. Or here is an example. 12 | 13 | ```python 14 | import cv2 15 | import numpy as np 16 | # import mat and libfcnn for python3 17 | from rbp_py3 import mat 18 | from rbp_py3 import libfcnn 19 | image = cv2.imread("yourimage.jpg") 20 | # you can scale down your image to speed up. 21 | # minimal face which can be detected is 12*12 22 | # image = cv2.resize(image,(0,0),fx=0.4,fy=0.4) 23 | rect = libfcnn.inference(mat.Mat.from_array(image),4) 24 | # rect is a list of [xmin,ymin,height,width] 25 | # now this lib just returns coordinate of the biggest face in the image 26 | # if no face detected , rect is [0,0,0,0] 27 | if rect[2]!=0: 28 | cv2.rectangle(image,(xmin,ymin),(xmax, ymax),(255,0, 0),2) 29 | while 1: 30 | cv2.imshow("Frame",image) 31 | key = cv2.waitKey(1) & 0xFF 32 | if key == ord("q"): 33 | break 34 | ``` 35 | 36 | 37 | NOTE: Now this lib just returns coordinate of the biggest face in the image. I will finish this when I can spare some time. 38 | -------------------------------------------------------------------------------- /results/output.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CharlieXie/libfacedetection-python-bindings/96e0fa45d287b1f1391e9c3126c97c0f029c989d/results/output.mp4 -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import time 4 | from collections import deque 5 | import sys 6 | PY2 = sys.version_info[0] == 2 7 | PY3 = sys.version_info[0] == 3 8 | if PY2: 9 | path = "rbp_py2" 10 | sys.path.insert(0,path) 11 | import mat 12 | import libfcnn 13 | elif PY3: 14 | from rbp_py3 import mat 15 | from rbp_py3 import libfcnn 16 | 17 | 18 | vc = cv2.VideoCapture("videos/neck-exercise.mp4") 19 | scaler = 8 20 | 21 | # Setting video writer for RBP 3 model B. This may be slight different for different devices. 22 | vid_out = cv2.VideoWriter("results/result.mp4",0x00000021,30.0,(720,720),isColor=1) 23 | 24 | # Create deque to store frames. 300 here is total frames of neck-exercise.mp4, because I know it. 25 | fra_que = deque([],300) 26 | while 1: 27 | ts = time.time() 28 | ret,frame = vc.read() 29 | if ret: 30 | resized_frame = cv2.resize(frame,(0,0),fx=0.125,fy=0.125) 31 | a = libfcnn.inference(mat.Mat.from_array(resized_frame),4) 32 | if a[2] != 0: 33 | xmin = a[0]*scaler 34 | ymin = a[1]*scaler 35 | xmax = (a[0]+a[2])*scaler 36 | ymax = (a[1]+a[2])*scaler 37 | cv2.rectangle(frame, (xmin,ymin), (xmax, ymax), (255,0, 0), 2) 38 | 39 | fps = "FPS: "+str(1/(time.time()-ts))[:5] 40 | cv2.putText(frame,fps,(0,60),cv2.FONT_HERSHEY_SIMPLEX,0.7,(0,0,255),2) 41 | fra_que.append(frame) 42 | 43 | # cv2.imshow("Frame",frame) 44 | # key = cv2.waitKey(1) & 0xFF 45 | # if key == ord("q"): 46 | # break 47 | 48 | else: 49 | while len(fra_que): 50 | poped_fra = fra_que.popleft() 51 | vid_out.write(poped_fra) 52 | vid_out.release() 53 | break 54 | 55 | -------------------------------------------------------------------------------- /videos/neck-exercise.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CharlieXie/libfacedetection-python-bindings/96e0fa45d287b1f1391e9c3126c97c0f029c989d/videos/neck-exercise.mp4 --------------------------------------------------------------------------------