faces = detector(img, 0) if len(faces): print '==> Found %d face in this image.' % len(faces) for i in range(len(faces)): landmarks = np.matrix([[p.x, p.y] for p in predictor(img, faces[i]).parts()]) for point in landmarks: pos = (point[0, 0], point[0, 1]) cv2.circle(img, pos, 3, color=(0, 255, 0),thickness=3) else: print 'Face not found!'
def check_file(self,path): if os.path.exists(path): img = cv2.imread(path) return img else: raise IOError('No such file : "%s", please check!' % path)
def detective(self, frame): faces = self.detector(frame, 0) if len(faces): print '==> Found %d face in this frame.' % len(faces) for i in range(len(faces)): landmarks = np.matrix([[p.x, p.y] for p in self.predictor(frame, faces[i]).parts()]) for point in landmarks: pos = (point[0, 0], point[0, 1]) cv2.circle(frame, pos, 3, color=(0, 0, 255),thickness=3) else: print 'Face not found!' return frame
def run_camera(self): camera = cv2.VideoCapture(0) camera.set(cv2.CAP_PROP_FRAME_WIDTH, Config.width) camera.set(cv2.CAP_PROP_FRAME_HEIGHT, Config.height) while True: detected, frame = camera.read()
if __name__ == '__main__': p = FaceDetective() #p.single_image(Config.test_img) p.run_camera()
错误
运行时可能提示错误
qt.qpa.plugin: Could not find the Qt platform plugin “cocoa” in “” This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.