Display VDO OpenCV tkinter Python, Fae Mask Detection

Hi there,

I gets stuck on this code for a while. I can only make the Camera blink but doesnt pop up GUI with VDO and also get this Error “None of the MLIR optimization passes are enabled (registered 2)”

from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.models import load_model
from imutils.video import VideoStream
import numpy as np
import argparse
import imutils
import time
import cv2
import os
import datetime

from tkinter import *
import tkinter.ttk as ttk
from PIL import ImageTk, Image
import cv2

mainFrame = Tk()
app = Frame(mainFrame, bg=“white”)
mainFrame.title(‘Face Mask Detector’)

app.grid()

Create a label in the frame

lmain = Label(app)
lmain.grid()

protopath = “face_detector/deploy.prototxt”
modelpath = “face_detector/res10_300x300_ssd_iter_140000.caffemodel”
detector = cv2.dnn.readNetFromCaffe(prototxt=protopath, caffeModel=modelpath)

mask_detector = load_model(‘face_mask.model’)

Capture from camera

cap = cv2.VideoCapture(0)
def video_stream():
_, frame = cap.read()
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
lmain.after(1, video_stream)
while True:
ret, frame = cap.read()
frame = imutils.resize(frame, width=400)
(h, w) = frame.shape[:2]
blob = cv2.dnn.blobFromImage(frame, 1.0, (300, 300), (104, 177, 123))

detector.setInput(blob)
detections = detector.forward()

faces = []
bbox = []
results = []

for i in range(0, detections.shape[2]):
    confidence = detections[0, 0, i, 2]

    if confidence > 0.5:
        box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
        (startX, startY, endX, endY) = box.astype("int")

        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)
        bbox.append((startX, startY, endX, endY))

if len(faces) > 0:
    results = mask_detector.predict(faces)

for (face_box, results) in zip(bbox, results):
    (startX, startY, endX, endY) = face_box
    (WithoutMask,SurgicalMask,ClothMask) = results


    if (ClothMask > WithoutMask and ClothMask > SurgicalMask):
        label = "Cloth Mask"
    elif (WithoutMask > SurgicalMask and WithoutMask > ClothMask):
        label = "Without Mask"
    else:
        label = "SurgicalMask"

    if label == "Cloth Mask":
        color = (0, 255, 0)
    elif label == "Without Mask":
        color = (0, 0, 255)
    else:
        color = (255, 0, 0)

    # include the probability in the label
    label = "{}: {:.2f}%".format(label, max(WithoutMask, ClothMask, SurgicalMask) * 100)

        # display the label and bounding box rectangle on the output
        # frame
    cv2.putText(frame, label, (startX, startY - 10),
    cv2.FONT_HERSHEY_SIMPLEX, 0.45, color, 2)
    cv2.rectangle(frame, (startX, startY), (endX, endY), color, 2)

#Build Button Widget
btnClose = ttk.Button(mainFrame, text = ‘Close’,width = 10)
#Button Widget position
btnClose.grid(sticky=‘S’,pady =10)
#Command Button
btnClose.configure(command= lambda: mainFrame.destroy())

video_stream()
mainFrame.mainloop()