python使用opencv实现人脸检测并模糊人脸功能代码
代码语言:python
所属分类:人工智能
代码描述:python使用opencv实现人脸检测并模糊人脸功能代码,可以实时模糊照片、视频、摄像头中的人脸
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
import cv2 import numpy as np # https://raw.githubusercontent.com/opencv/opencv/master/samples/dnn/face_detector/deploy.prototxt prototxt_path = "/data/wwwroot/default/model/deploy.prototxt" # https://raw.githubusercontent.com/opencv/opencv_3rdparty/dnn_samples_face_detector_20180205_fp16/res10_300x300_ssd_iter_140000_fp16.caffemodel model_path = "/data/wwwroot/default/model/res10_300x300_ssd_iter_140000_fp16.caffemodel" # load Caffe model model = cv2.dnn.readNetFromCaffe(prototxt_path, model_path) # read the desired image image = cv2.imread("/data/wwwroot/default/asset/man.png") # get width and height of the image h, w = image.shape[:2] # gaussian blur kernel size depends on width and height of original image kernel_width = (w // 7) | 1 kernel_height = (h // 7) | 1 # preprocess the image: resize and performs mean subtraction blob = cv2.dnn.blobFromImage(image, 1.0, (300, 300), (104.0, 177.0, 123.0)) # set the image into the input of the neural network model.setInput(blob) # perform i.........完整代码请登录后点击上方下载按钮下载查看
网友评论0