from tensorflow.keras.applications.mobilenet_v2 import preprocess_inputfrom tensorflow.keras.preprocessing.image import img_to_arrayfrom tensorflow.keras.models import load_modelfrom imutils.video import VideoStreamimport numpy as npimport argparseimport imutilsimport timeimport cv2import osdef detect_and_predict_mask(frame, faceNet, maskNet): (h, w) = frame.shape[:2] blob = cv2.dnn.blobFromImage(frame, 1.0, (300, 300), (104.0, 177.0, 123.0)) faceNet.setInput(blob) detections = faceNet.forward() faces = [] locs = [] preds = [] for i in range(0, detections.shape[2]): confidence = detections[0, 0, i, 2] if confidence > args["confidence"]: box = detections[0, 0, i, 3:7] * np.array([w, h, w, h]) (startX, startY, endX, endY) = box.astype("int") (startX, startY) = (max(0, startX), max(0, startY)) (endX, endY) = (min(w - 1, endX), min(h - 1, endY)) face = frame[startY:endY, startX:endX] face = cv2.cvtColor(face, cv2.COLOR_BGR2RGB) face = cv2.resize(face, (224, 224)) face = img_to_array(face) face = preprocess_input(face) face = np.expand_dims(face, axis=0) faces.append(face) locs.append((startX, startY, endX, endY)) if len(faces) > 0: preds = maskNet.predict(faces) return (locs, preds)ap = argparse.ArgumentParser()ap.add_argument("-f", "--face", type=str, default="face_detector", help="path to face detector model directory")ap.add_argument("-m", "--model", type=str, default="mask_detector.model", help="path to trained face mask detector model")ap.add_argument("-c", "--confidence", type=float, default=0.5, help="minimum probability to filter weak detections")有没有我需要导入的模块或者是否全部正确导入。我不调试它我重新格式化文件一次。我已经获得了所有需要的 xml 和 jpg 文件。我已经导入了所有需要的模块......我想是的下面是错误你能帮我吗?我是 OpenCV 新手,遇到了这样的复杂错误
添加回答
举报
0/150
提交
取消