<gh_stars>0
# Form implementation generated from reading ui file 'pyqt.ui'
#
# Created by: PyQt6 UI code generator 6.0.3
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import Qt
import cv2 
from PyQt5.Qt import QImage, QPixmap, QTimer
from PyQt5.QtWidgets import QFileDialog
import numpy as np
import keras
import keras.backend as k
import keras.applications.inception_resnet_v2
from keras.preprocessing import image
import cv2
import datetime
from FaceMaskDetection import tensorflow_infer as tsf

class Ui_MainWindow(QtWidgets.QMainWindow):                      
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(900, 600)
        self.timer_camera = QtCore.QTimer() 
        self.timer_camera2 = QtCore.QTimer() 
        self.cap = cv2.VideoCapture()
        self.vidcap = cv2.VideoCapture()       
        self.CAM_NUM = 0                    
        self.slot_init() 
        self.model = keras.models.load_model('FMD.h5')
        self.face_cascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
        self.is_Detecting = False
        

        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(570, 20, 321, 41))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.about_btn = QtWidgets.QPushButton(self.horizontalLayoutWidget, clicked= lambda: self.about_us_btn_clicked(self))
        self.about_btn.setMaximumSize(QtCore.QSize(16777215, 20))
        self.about_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 157, 148);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}\n"
"")
        self.about_btn.setObjectName("about_btn")
        self.horizontalLayout.addWidget(self.about_btn)
        self.abstract_btn = QtWidgets.QPushButton(self.horizontalLayoutWidget, clicked= lambda: self.abstract_btn_clicked(self))
        self.abstract_btn.setMaximumSize(QtCore.QSize(16777215, 20))
        self.abstract_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 157, 148);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}")
        self.abstract_btn.setObjectName("abstract_btn")
        self.horizontalLayout.addWidget(self.abstract_btn)
        self.whyMask_btn = QtWidgets.QPushButton(self.horizontalLayoutWidget, clicked= lambda: self.why_mask_clicked(self))
        self.whyMask_btn.setMaximumSize(QtCore.QSize(16777215, 20))
        self.whyMask_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 157, 148);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}")
        self.whyMask_btn.setObjectName("whyMask_btn")
        self.horizontalLayout.addWidget(self.whyMask_btn)
        self.detection_btn = QtWidgets.QPushButton(self.centralwidget,clicked= lambda: self.start_detect_btn_clicked(self))
        self.detection_btn.setGeometry(QtCore.QRect(410, 440, 141, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.detection_btn.setFont(font)
        self.detection_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(213, 213, 213);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(255, 246, 240);\n"
"}\n"
"")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("imagesIcons/check.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.detection_btn.setIcon(icon)
        self.detection_btn.setIconSize(QtCore.QSize(32, 32))
        self.detection_btn.setObjectName("detection_btn")
        self.cancel_btn = QtWidgets.QPushButton(self.centralwidget)
        self.cancel_btn.setGeometry(QtCore.QRect(670, 440, 141, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.cancel_btn.setFont(font)
        self.cancel_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(213, 213, 213);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(255, 246, 240);\n"
"}")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("imagesIcons/close.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.cancel_btn.setIcon(icon1)
        self.cancel_btn.setIconSize(QtCore.QSize(32, 32))
        self.cancel_btn.setObjectName("cancel_btn")
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setGeometry(QtCore.QRect(0, 60, 901, 16))
        self.line.setFrameShape(QtWidgets.QFrame.Shape.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken)
        self.line.setObjectName("line")
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setGeometry(QtCore.QRect(300, 70, 20, 531))
        self.line_2.setFrameShape(QtWidgets.QFrame.Shape.VLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken)
        self.line_2.setObjectName("line_2")
        self.Face_Mask_Detection = QtWidgets.QLabel(self.centralwidget)
        self.Face_Mask_Detection.setGeometry(QtCore.QRect(10, 0, 261, 61))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.Face_Mask_Detection.setFont(font)
        self.Face_Mask_Detection.setObjectName("Face_Mask_Detection")
        self.preview_window = QtWidgets.QFrame(self.centralwidget)
        self.preview_window.setGeometry(QtCore.QRect(9, 79, 291, 291))
        self.preview_window.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.preview_window.setFrameShadow(QtWidgets.QFrame.Shadow.Plain)
        self.preview_window.setLineWidth(7)
        self.preview_window.setObjectName("preview_window")
        self.preview_label = QtWidgets.QLabel(self.preview_window)
        self.preview_label.setGeometry(QtCore.QRect(6, 12, 281, 271))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.preview_label.setFont(font)
        self.preview_label.setObjectName("preview_label")
        self.detect_window = QtWidgets.QFrame(self.centralwidget)
        self.detect_window.setGeometry(QtCore.QRect(320, 80, 571, 351))
        self.detect_window.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.detect_window.setFrameShadow(QtWidgets.QFrame.Shadow.Plain)
        self.detect_window.setLineWidth(7)
        self.detect_window.setObjectName("detect_window")
        self.detect_label = QtWidgets.QLabel(self.detect_window)
        self.detect_label.setGeometry(QtCore.QRect(6, 12, 561, 337))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.detect_label.setFont(font)
        self.detect_label.setObjectName("detect_label")
        self.result_frame = QtWidgets.QFrame(self.centralwidget)
        self.result_frame.setGeometry(QtCore.QRect(320, 500, 571, 71))
        self.result_frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.result_frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
        self.result_frame.setObjectName("result_frame")
        self.label = QtWidgets.QLabel(self.result_frame)
        self.label.setGeometry(QtCore.QRect(220, 30, 141, 21))
        self.label.setObjectName("label")
        self.buttom_frame = QtWidgets.QFrame(self.centralwidget)
        self.buttom_frame.setGeometry(QtCore.QRect(9, 379, 291, 191))
        self.buttom_frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.buttom_frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
        self.buttom_frame.setObjectName("buttom_frame")
        self.information_btn = QtWidgets.QPushButton(self.buttom_frame, clicked= lambda: self.why_mask_clicked(self))
        self.information_btn.setGeometry(QtCore.QRect(170, 120, 111, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.information_btn.setFont(font)
        self.information_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(107, 255, 132);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"}\n"
"")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("imagesIcons/exclaimation.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.information_btn.setIcon(icon2)
        self.information_btn.setIconSize(QtCore.QSize(32, 32))
        self.information_btn.setObjectName("information_btn")
        self.video_btn = QtWidgets.QPushButton(self.buttom_frame, clicked= lambda: self.open_video(self))
        self.video_btn.setGeometry(QtCore.QRect(20, 120, 111, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.video_btn.setFont(font)
        self.video_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 251, 190);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"}\n"
"")
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap("imagesIcons/playIcon.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.video_btn.setIcon(icon3)
        self.video_btn.setIconSize(QtCore.QSize(32, 32))
        self.video_btn.setObjectName("video_btn")
        self.camera_btn = QtWidgets.QPushButton(self.buttom_frame, clicked= lambda: self.button_open_camera_clicked(self))
        self.camera_btn.setGeometry(QtCore.QRect(20, 40, 111, 51))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.camera_btn.sizePolicy().hasHeightForWidth())
        self.camera_btn.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        font.setKerning(True)
        font.setStyleStrategy(QtGui.QFont.StyleStrategy.PreferAntialias)
        self.camera_btn.setFont(font)
        self.camera_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 251, 190);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"}\n"
"")
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap("imagesIcons/camera-131965017355314519_32.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.camera_btn.setIcon(icon4)
        self.camera_btn.setIconSize(QtCore.QSize(32, 32))
        self.camera_btn.setObjectName("camera_btn")
        self.image_btn = QtWidgets.QPushButton(self.buttom_frame, clicked= lambda: self.open_image(self))
        self.image_btn.setGeometry(QtCore.QRect(170, 40, 111, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.image_btn.setFont(font)
        self.image_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 251, 190);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"}\n"
"\n"
"")
        icon5 = QtGui.QIcon()
        icon5.addPixmap(QtGui.QPixmap("imagesIcons/imageIcon.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.image_btn.setIcon(icon5)
        self.image_btn.setIconSize(QtCore.QSize(32, 32))
        self.image_btn.setObjectName("image_btn")
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Face Mask Detection"))
        self.about_btn.setText(_translate("MainWindow", "About Us"))
        self.abstract_btn.setText(_translate("MainWindow", "Abstract"))
        self.whyMask_btn.setText(_translate("MainWindow", "Why Mask"))
        self.detection_btn.setText(_translate("MainWindow", "Start Detection"))
        self.cancel_btn.setText(_translate("MainWindow", "Cancel"))
        self.Face_Mask_Detection.setText(_translate("MainWindow", "Face Mask Detection"))
        self.preview_label.setText(_translate("MainWindow", "                 Preview Window"))
        self.detect_label.setText(_translate("MainWindow", "                                          Detection Display window"))
        self.label.setText(_translate("MainWindow", "Outcome Display window"))
        self.information_btn.setText(_translate("MainWindow", "Information"))
        self.video_btn.setText(_translate("MainWindow", "Video"))
        self.camera_btn.setText(_translate("MainWindow", "Camera"))
        self.image_btn.setText(_translate("MainWindow", "Image"))

    def abstract_btn_clicked(self,MainWindow):
        image = QtGui.QImage(QtGui.QImageReader("picture/abstract.png").read())
        pixmap_resized = image.smoothScaled(565, 337)
        self.detect_label.setPixmap(QtGui.QPixmap(pixmap_resized))

    def about_us_btn_clicked(self,MainWindow):
        image = QtGui.QImage(QtGui.QImageReader("picture/Aboutus.png").read())
        pixmap_resized = image.smoothScaled(565, 337)
        self.detect_label.setPixmap(QtGui.QPixmap(pixmap_resized))

    def why_mask_clicked(self,MainWindow):
        image = QtGui.QImage(QtGui.QImageReader("picture/whymask.png").read())
        pixmap_resized = image.smoothScaled(550, 337)
        self.detect_label.setPixmap(QtGui.QPixmap(pixmap_resized))

    def info_btn_clicked(self,MainWindow):
        image = QtGui.QImage(QtGui.QImageReader("picture/help.png").read())
        pixmap_resized = image.smoothScaled(550, 337)
        self.detect_label.setPixmap(QtGui.QPixmap(pixmap_resized))

    def start_detect_btn_clicked(self,MainWindow):
        self.is_Detecting = True

    def open_image(self,MainWindow):
        imgName, imgType = QFileDialog.getOpenFileName(self, 'Open Image', '', '*.jpg;;*.png;;All Files(*)')
        jpg = QtGui.QPixmap(imgName).scaled(self.preview_label.width(), self.preview_label.height())
        self.preview_label.setPixmap(jpg)

    def open_video(self,MainWindow):
        vidName, vidType = QFileDialog.getOpenFileName(self, 'Open Video', '', '*.mp4;;All Files(*)')
        self.vidcap = cv2.VideoCapture(vidName)
        self.frameRate = self.vidcap.get(cv2.CAP_PROP_FPS)
        self.timer_camera2.start(self.frameRate)
        self.timer_camera2.timeout.connect(self.get_image_frame)


    def slot_init(self):
        self.timer_camera.timeout.connect(self.get_frame) 

    
    
    def button_open_camera_clicked(self, MainWindow):
        if self.timer_camera.isActive() == False:   
            flag = self.cap.open(self.CAM_NUM) 
            if flag == False:       
                msg = QtWidgets.QMessageBox.warning(self,'warning',"check camera",buttons=QtWidgets.QMessageBox.Ok)
            else:
                self.timer_camera.start(30)  
                self.camera_btn.setText(QtCore.QCoreApplication.translate("MainWindow", "Camera OFF"))

        else:
            self.timer_camera.stop()  
            self.cap.release()        
            self.detect_label.clear()  
            self.camera_btn.setText(QtCore.QCoreApplication.translate("MainWindow", "Camera"))


    def get_frame(self): 
        flag,self.image = self.cap.read()  

        if self.is_Detecting == False:
            show = cv2.resize(self.image,(640,480))     
            show = cv2.cvtColor(show,cv2.COLOR_BGR2RGB) 
            showImage = QtGui.QImage(show.data,show.shape[1],show.shape[0],QtGui.QImage.Format_RGB888) 
            self.detect_label.setPixmap(QtGui.QPixmap.fromImage(showImage))
        else:
            show = cv2.resize(self.image,(640,480))
            show = cv2.cvtColor(show,cv2.COLOR_BGR2RGB)  
            faces=self.face_cascade.detectMultiScale(show,scaleFactor=1.1,minNeighbors=4) 
            for i in range(len(faces)):
                (x, y, w, h) = faces[i]
                crop = show[y:y + h, x:x + w]
                crop = cv2.resize(crop, (128, 128))
                crop = np.reshape(crop, [1, 128, 128, 3]) / 255.0
                mask_label = self.model.predict_classes(crop)
                if (mask_label == 0):#print(mask_label)  0 :WithMask, 1 :'WithoutMask'
                    text="WithMask"
                    cv2.rectangle(show, (x, y), (x + w, y + h), (23, 204, 66), 1) # the bounfding box color 255, 51, 63 red
                    cv2.putText(show, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 1,(23, 204, 66),3) # font color
                elif (mask_label ==1):
                    text="WithoutMask"
                    cv2.rectangle(show, (x, y), (x + w, y + h), (255, 51, 63), 1) # the bounfding box color 255, 51, 63 red
                    cv2.putText(show, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5,(255, 51, 63),1)
            showImage = QtGui.QImage(show.data,show.shape[1],show.shape[0],QtGui.QImage.Format_RGB888)
            self.detect_label.setPixmap(QtGui.QPixmap.fromImage(showImage))


    def get_image_frame(self): 

        flag,self.image = self.vidcap.read() 
        if flag: 
            show = cv2.resize(self.image,(280,158))     
            show = cv2.cvtColor(show,cv2.COLOR_BGR2RGB) 
            showImage = QtGui.QImage(show.data,show.shape[1],show.shape[0],QtGui.QImage.Format_RGB888) 
            self.preview_label.setPixmap(QtGui.QPixmap.fromImage(showImage))
        else:
            self.vidcap.release()
            self.timer_camera2.stop()


    
                    
        




if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec())

# Form implementation generated from reading ui file 'pyqt.ui'
#
# Created by: PyQt6 UI code generator 6.0.3
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import Qt
import cv2 
from PyQt5.Qt import QImage, QPixmap, QTimer
from PyQt5.QtWidgets import QFileDialog
import numpy as np
import keras
import keras.backend as k
import keras.applications.inception_resnet_v2
from keras.preprocessing import image
import cv2
import datetime
from FaceMaskDetection import tensorflow_infer as tsf

class Ui_MainWindow(QtWidgets.QMainWindow):                      
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(900, 600)
        self.timer_camera = QtCore.QTimer() 
        self.timer_camera2 = QtCore.QTimer() 
        self.cap = cv2.VideoCapture()
        self.vidcap = cv2.VideoCapture()       
        self.CAM_NUM = 0                    
        self.slot_init() 
        self.model = keras.models.load_model('FMD.h5')
        self.face_cascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
        self.is_Detecting = False
        

        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(570, 20, 321, 41))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.about_btn = QtWidgets.QPushButton(self.horizontalLayoutWidget, clicked= lambda: self.about_us_btn_clicked(self))
        self.about_btn.setMaximumSize(QtCore.QSize(16777215, 20))
        self.about_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 157, 148);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}\n"
"")
        self.about_btn.setObjectName("about_btn")
        self.horizontalLayout.addWidget(self.about_btn)
        self.abstract_btn = QtWidgets.QPushButton(self.horizontalLayoutWidget, clicked= lambda: self.abstract_btn_clicked(self))
        self.abstract_btn.setMaximumSize(QtCore.QSize(16777215, 20))
        self.abstract_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 157, 148);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}")
        self.abstract_btn.setObjectName("abstract_btn")
        self.horizontalLayout.addWidget(self.abstract_btn)
        self.whyMask_btn = QtWidgets.QPushButton(self.horizontalLayoutWidget, clicked= lambda: self.why_mask_clicked(self))
        self.whyMask_btn.setMaximumSize(QtCore.QSize(16777215, 20))
        self.whyMask_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 157, 148);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"border-right: 1px solid rgb(255, 217, 198);\n"
"border-bottom: 1px solid rgb(255, 217, 198);\n"
"}")
        self.whyMask_btn.setObjectName("whyMask_btn")
        self.horizontalLayout.addWidget(self.whyMask_btn)
        self.detection_btn = QtWidgets.QPushButton(self.centralwidget,clicked= lambda: self.start_detect_btn_clicked(self))
        self.detection_btn.setGeometry(QtCore.QRect(410, 440, 141, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.detection_btn.setFont(font)
        self.detection_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(213, 213, 213);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(255, 246, 240);\n"
"}\n"
"")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("imagesIcons/check.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.detection_btn.setIcon(icon)
        self.detection_btn.setIconSize(QtCore.QSize(32, 32))
        self.detection_btn.setObjectName("detection_btn")
        self.cancel_btn = QtWidgets.QPushButton(self.centralwidget)
        self.cancel_btn.setGeometry(QtCore.QRect(670, 440, 141, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.cancel_btn.setFont(font)
        self.cancel_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(213, 213, 213);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(255, 246, 240);\n"
"}")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("imagesIcons/close.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.cancel_btn.setIcon(icon1)
        self.cancel_btn.setIconSize(QtCore.QSize(32, 32))
        self.cancel_btn.setObjectName("cancel_btn")
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setGeometry(QtCore.QRect(0, 60, 901, 16))
        self.line.setFrameShape(QtWidgets.QFrame.Shape.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken)
        self.line.setObjectName("line")
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setGeometry(QtCore.QRect(300, 70, 20, 531))
        self.line_2.setFrameShape(QtWidgets.QFrame.Shape.VLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Shadow.Sunken)
        self.line_2.setObjectName("line_2")
        self.Face_Mask_Detection = QtWidgets.QLabel(self.centralwidget)
        self.Face_Mask_Detection.setGeometry(QtCore.QRect(10, 0, 261, 61))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.Face_Mask_Detection.setFont(font)
        self.Face_Mask_Detection.setObjectName("Face_Mask_Detection")
        self.preview_window = QtWidgets.QFrame(self.centralwidget)
        self.preview_window.setGeometry(QtCore.QRect(9, 79, 291, 291))
        self.preview_window.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.preview_window.setFrameShadow(QtWidgets.QFrame.Shadow.Plain)
        self.preview_window.setLineWidth(7)
        self.preview_window.setObjectName("preview_window")
        self.preview_label = QtWidgets.QLabel(self.preview_window)
        self.preview_label.setGeometry(QtCore.QRect(6, 12, 281, 271))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.preview_label.setFont(font)
        self.preview_label.setObjectName("preview_label")
        self.detect_window = QtWidgets.QFrame(self.centralwidget)
        self.detect_window.setGeometry(QtCore.QRect(320, 80, 571, 351))
        self.detect_window.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.detect_window.setFrameShadow(QtWidgets.QFrame.Shadow.Plain)
        self.detect_window.setLineWidth(7)
        self.detect_window.setObjectName("detect_window")
        self.detect_label = QtWidgets.QLabel(self.detect_window)
        self.detect_label.setGeometry(QtCore.QRect(6, 12, 561, 337))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.detect_label.setFont(font)
        self.detect_label.setObjectName("detect_label")
        self.result_frame = QtWidgets.QFrame(self.centralwidget)
        self.result_frame.setGeometry(QtCore.QRect(320, 500, 571, 71))
        self.result_frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.result_frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
        self.result_frame.setObjectName("result_frame")
        self.label = QtWidgets.QLabel(self.result_frame)
        self.label.setGeometry(QtCore.QRect(220, 30, 141, 21))
        self.label.setObjectName("label")
        self.buttom_frame = QtWidgets.QFrame(self.centralwidget)
        self.buttom_frame.setGeometry(QtCore.QRect(9, 379, 291, 191))
        self.buttom_frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
        self.buttom_frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
        self.buttom_frame.setObjectName("buttom_frame")
        self.information_btn = QtWidgets.QPushButton(self.buttom_frame, clicked= lambda: self.why_mask_clicked(self))
        self.information_btn.setGeometry(QtCore.QRect(170, 120, 111, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.information_btn.setFont(font)
        self.information_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(107, 255, 132);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"}\n"
"")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("imagesIcons/exclaimation.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.information_btn.setIcon(icon2)
        self.information_btn.setIconSize(QtCore.QSize(32, 32))
        self.information_btn.setObjectName("information_btn")
        self.video_btn = QtWidgets.QPushButton(self.buttom_frame, clicked= lambda: self.open_video(self))
        self.video_btn.setGeometry(QtCore.QRect(20, 120, 111, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.video_btn.setFont(font)
        self.video_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 251, 190);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"}\n"
"")
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap("imagesIcons/playIcon.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.video_btn.setIcon(icon3)
        self.video_btn.setIconSize(QtCore.QSize(32, 32))
        self.video_btn.setObjectName("video_btn")
        self.camera_btn = QtWidgets.QPushButton(self.buttom_frame, clicked= lambda: self.button_open_camera_clicked(self))
        self.camera_btn.setGeometry(QtCore.QRect(20, 40, 111, 51))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.camera_btn.sizePolicy().hasHeightForWidth())
        self.camera_btn.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        font.setKerning(True)
        font.setStyleStrategy(QtGui.QFont.StyleStrategy.PreferAntialias)
        self.camera_btn.setFont(font)
        self.camera_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 251, 190);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"}\n"
"")
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap("imagesIcons/camera-131965017355314519_32.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.camera_btn.setIcon(icon4)
        self.camera_btn.setIconSize(QtCore.QSize(32, 32))
        self.camera_btn.setObjectName("camera_btn")
        self.image_btn = QtWidgets.QPushButton(self.buttom_frame, clicked= lambda: self.open_image(self))
        self.image_btn.setGeometry(QtCore.QRect(170, 40, 111, 51))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.image_btn.setFont(font)
        self.image_btn.setStyleSheet("QPushButton{\n"
"border: none;\n"
"background-color: rgb(255, 251, 190);\n"
"}\n"
"QPushButton:hover{\n"
"background-color: rgb(196, 255, 203);\n"
"}\n"
"\n"
"")
        icon5 = QtGui.QIcon()
        icon5.addPixmap(QtGui.QPixmap("imagesIcons/imageIcon.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
        self.image_btn.setIcon(icon5)
        self.image_btn.setIconSize(QtCore.QSize(32, 32))
        self.image_btn.setObjectName("image_btn")
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Face Mask Detection"))
        self.about_btn.setText(_translate("MainWindow", "About Us"))
        self.abstract_btn.setText(_translate("MainWindow", "Abstract"))
        self.whyMask_btn.setText(_translate("MainWindow", "Why Mask"))
        self.detection_btn.setText(_translate("MainWindow", "Start Detection"))
        self.cancel_btn.setText(_translate("MainWindow", "Cancel"))
        self.Face_Mask_Detection.setText(_translate("MainWindow", "Face Mask Detection"))
        self.preview_label.setText(_translate("MainWindow", "                 Preview Window"))
        self.detect_label.setText(_translate("MainWindow", "                                          Detection Display window"))
        self.label.setText(_translate("MainWindow", "Outcome Display window"))
        self.information_btn.setText(_translate("MainWindow", "Information"))
        self.video_btn.setText(_translate("MainWindow", "Video"))
        self.camera_btn.setText(_translate("MainWindow", "Camera"))
        self.image_btn.setText(_translate("MainWindow", "Image"))

    def abstract_btn_clicked(self,MainWindow):
        image = QtGui.QImage(QtGui.QImageReader("picture/abstract.png").read())
        pixmap_resized = image.smoothScaled(565, 337)
        self.detect_label.setPixmap(QtGui.QPixmap(pixmap_resized))

    def about_us_btn_clicked(self,MainWindow):
        image = QtGui.QImage(QtGui.QImageReader("picture/Aboutus.png").read())
        pixmap_resized = image.smoothScaled(565, 337)
        self.detect_label.setPixmap(QtGui.QPixmap(pixmap_resized))

    def why_mask_clicked(self,MainWindow):
        image = QtGui.QImage(QtGui.QImageReader("picture/whymask.png").read())
        pixmap_resized = image.smoothScaled(550, 337)
        self.detect_label.setPixmap(QtGui.QPixmap(pixmap_resized))

    def info_btn_clicked(self,MainWindow):
        image = QtGui.QImage(QtGui.QImageReader("picture/help.png").read())
        pixmap_resized = image.smoothScaled(550, 337)
        self.detect_label.setPixmap(QtGui.QPixmap(pixmap_resized))

    def start_detect_btn_clicked(self,MainWindow):
        self.is_Detecting = True

    def open_image(self,MainWindow):
        imgName, imgType = QFileDialog.getOpenFileName(self, 'Open Image', '', '*.jpg;;*.png;;All Files(*)')
        jpg = QtGui.QPixmap(imgName).scaled(self.preview_label.width(), self.preview_label.height())
        self.preview_label.setPixmap(jpg)

    def open_video(self,MainWindow):
        vidName, vidType = QFileDialog.getOpenFileName(self, 'Open Video', '', '*.mp4;;All Files(*)')
        self.vidcap = cv2.VideoCapture(vidName)
        self.frameRate = self.vidcap.get(cv2.CAP_PROP_FPS)
        self.timer_camera2.start(self.frameRate)
        self.timer_camera2.timeout.connect(self.get_image_frame)


    def slot_init(self):
        self.timer_camera.timeout.connect(self.get_frame) 

    
    
    def button_open_camera_clicked(self, MainWindow):
        if self.timer_camera.isActive() == False:   
            flag = self.cap.open(self.CAM_NUM) 
            if flag == False:       
                msg = QtWidgets.QMessageBox.warning(self,'warning',"check camera",buttons=QtWidgets.QMessageBox.Ok)
            else:
                self.timer_camera.start(30)  
                self.camera_btn.setText(QtCore.QCoreApplication.translate("MainWindow", "Camera OFF"))

        else:
            self.timer_camera.stop()  
            self.cap.release()        
            self.detect_label.clear()  
            self.camera_btn.setText(QtCore.QCoreApplication.translate("MainWindow", "Camera"))


    def get_frame(self): 
        flag,self.image = self.cap.read()  

        if self.is_Detecting == False:
            show = cv2.resize(self.image,(640,480))     
            show = cv2.cvtColor(show,cv2.COLOR_BGR2RGB) 
            showImage = QtGui.QImage(show.data,show.shape[1],show.shape[0],QtGui.QImage.Format_RGB888) 
            self.detect_label.setPixmap(QtGui.QPixmap.fromImage(showImage))
        else:
            show = cv2.resize(self.image,(640,480))
            show = cv2.cvtColor(show,cv2.COLOR_BGR2RGB)  
            faces=self.face_cascade.detectMultiScale(show,scaleFactor=1.1,minNeighbors=4) 
            for i in range(len(faces)):
                (x, y, w, h) = faces[i]
                crop = show[y:y + h, x:x + w]
                crop = cv2.resize(crop, (128, 128))
                crop = np.reshape(crop, [1, 128, 128, 3]) / 255.0
                mask_label = self.model.predict_classes(crop)
                if (mask_label == 0):#print(mask_label)  0 :WithMask, 1 :'WithoutMask'
                    text="WithMask"
                    cv2.rectangle(show, (x, y), (x + w, y + h), (23, 204, 66), 1) # the bounfding box color 255, 51, 63 red
                    cv2.putText(show, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 1,(23, 204, 66),3) # font color
                elif (mask_label ==1):
                    text="WithoutMask"
                    cv2.rectangle(show, (x, y), (x + w, y + h), (255, 51, 63), 1) # the bounfding box color 255, 51, 63 red
                    cv2.putText(show, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5,(255, 51, 63),1)
            showImage = QtGui.QImage(show.data,show.shape[1],show.shape[0],QtGui.QImage.Format_RGB888)
            self.detect_label.setPixmap(QtGui.QPixmap.fromImage(showImage))


    def get_image_frame(self): 

        flag,self.image = self.vidcap.read() 
        if flag: 
            show = cv2.resize(self.image,(280,158))     
            show = cv2.cvtColor(show,cv2.COLOR_BGR2RGB) 
            showImage = QtGui.QImage(show.data,show.shape[1],show.shape[0],QtGui.QImage.Format_RGB888) 
            self.preview_label.setPixmap(QtGui.QPixmap.fromImage(showImage))
        else:
            self.vidcap.release()
            self.timer_camera2.stop()


    
                    
        




if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec())
# Form implementation generated from reading ui file 'pyqt.ui' # # Created by: PyQt6 UI code generator 6.0.3 # # WARNING: Any manual changes made to this file will be lost when pyuic6 is # run again.  Do not edit this file unless you know what you are doing. #print(mask_label)  0 :WithMask, 1 :'WithoutMask' # the bounfding box color 255, 51, 63 red # font color # the bounfding box color 255, 51, 63 red