import cv2 from tensorflow.keras.models import load_model resize = 224 label = ('戴口罩!', '没戴口罩') #face_detect = cv2.CascadeClassifier(r'C:\Users\1\Desktop\haarcascade_frontalface_alt.xml') # 识别电脑摄像头,并打开 cap = cv2.VideoCapture(0) while True: ret, img = cap.read() gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #faces = face_detect.detectMultiScale(gray, 1.1, 3) cv2.imshow('Cheney', img) img= cv2.resize((img), (resize, resize)) img = img.astype("float") img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2])) model = load_model(r'C:\Users\1\Desktop\mode_save') predict = model.predict(img) i = predict.argmax(axis=1)[0] print(label[i]) cv2.waitKey(3) cap.release() cv2.destroyAllWindows()
使用训练的模型进行口罩识别
最新推荐文章于 2023-07-03 13:24:09 发布