示例#1
0
    def start_video_stream(self, stream_source):
        """
        Starts a video stream using a camera source
        :param stream_source: Sets the stream source (camera source) of the stream.
                                stream_source = 0 stream using system webcam,
                                stream_source = 1, 2, 3 .. : stream using connected camera/camera's.
        """
        vs = cv2.VideoCapture(stream_source)
        time.sleep(2.0)
        Interface.update_progress_bar(100)
        Interface.update_info_text(
            "Press 'q' to quit window | press 's' to send email of last detection"
        )
        while True:
            frame_exist, frame = vs.read()
            frame = imutils.resize(frame, width=400)
            self.start_mask_detection(frame=frame)
            key = cv2.waitKey(1) & 0xFF
            if key == ord("q"):
                Interface.canvas.create_image(
                    150, 150, image=VideoMaskDetection.offender_img)
                Interface.update_progress_bar(0)
                Interface.update_info_text("")
                break
            elif key == ord("s"):
                Notification.notify()

        vs.release()
        cv2.destroyAllWindows()
示例#2
0
    def __init__(self):
        # Text
        self.selected_image = 'last_capture.png'
        title = Label(text="Face Mask Detection Software",
                      font=FONT_LARGE,
                      padx=10,
                      pady=10,
                      fg=GREY,
                      bg=BACKGROUND)
        please_choose_text = Label(text="Please Choose Detection Mode",
                                   font=FONT_MEDIUM,
                                   padx=5,
                                   pady=5,
                                   bg=BACKGROUND,
                                   fg=BLACK)
        email_setup_text = Label(text="Email Setup",
                                 font=FONT_MEDIUM,
                                 padx=5,
                                 pady=5,
                                 bg=BACKGROUND,
                                 fg=BLACK)
        from_email_text = Label(text="Sender Email: ",
                                font=FONT_SMALL,
                                padx=5,
                                pady=5,
                                bg=BACKGROUND,
                                fg=BLACK)
        camera_source_text = Label(text="Camera Source: ",
                                   font=FONT_SMALL,
                                   padx=5,
                                   pady=5,
                                   bg=BACKGROUND,
                                   fg=BLACK)
        space = Label(text="                           ",
                      font=FONT_SMALL,
                      padx=5,
                      pady=5,
                      bg=BACKGROUND,
                      fg=BLACK)
        password_text = Label(text="Password: "******"Please Upload or Provide File Directory",
            font=FONT_SMALL,
            padx=10,
            pady=10,
            fg=BLACK,
            bg=BACKGROUND)
        to_email_text = Label(text="Receiver Email: ",
                              font=FONT_SMALL,
                              padx=5,
                              pady=5,
                              bg=BACKGROUND,
                              fg=BLACK)
        target_detection_text = Label(text="Last Detection",
                                      font=FONT_MEDIUM,
                                      padx=5,
                                      pady=5,
                                      bg=BACKGROUND,
                                      fg=RED)
        smtp_server_text = Label(text="SMTP Server: ",
                                 font=FONT_SMALL,
                                 padx=5,
                                 pady=5,
                                 bg=BACKGROUND,
                                 fg=BLACK)

        #
        auto_send = Checkbutton(Interface.window,
                                text="automatically send email",
                                variable=Interface.auto_send_is_on,
                                onvalue=1,
                                offvalue=0,
                                bg=BACKGROUND)

        # Buttons
        send_bttn_image = PhotoImage(file='buttons/send.png')
        send_bttn = Button(
            image=send_bttn_image,
            highlightthickness=0,
            command=lambda: Notification.notify(image=self.selected_image),
            font=FONT_MEDIUM,
            bg=BACKGROUND,
            relief='raised',
            bd=0)

        # Radio Buttons
        self.radio_state = IntVar()
        webcam_radio_bttn = Radiobutton(text="Camera",
                                        value=0,
                                        variable=self.radio_state,
                                        command=self.radio_chosen,
                                        anchor='c',
                                        bg=BACKGROUND,
                                        fg=BLACK)
        image_radio_bttn = Radiobutton(text="Image",
                                       value=1,
                                       variable=self.radio_state,
                                       command=self.radio_chosen,
                                       anchor='c',
                                       bg=BACKGROUND,
                                       fg=BLACK)
        video_radio_bttn = Radiobutton(text="Video  ",
                                       value=2,
                                       variable=self.radio_state,
                                       command=self.radio_chosen,
                                       anchor='c',
                                       bg=BACKGROUND,
                                       fg=BLACK)

        # Entries, Buttons and Separator
        self.file_directory_ent = Entry(width=50, bd=0, highlightcolor=BLUE)
        upload_bttn_image = PhotoImage(file='buttons/upload.png')
        upload_bttn = Button(highlightthickness=0,
                             command=self.upload_file,
                             image=upload_bttn_image,
                             bg=BACKGROUND)
        sep = ttk.Separator(Interface.window, orient='vertical')
        start_bttn_image = PhotoImage(file='buttons/power.png')
        start_bttn = Button(image=start_bttn_image,
                            highlightthickness=0,
                            command=self.start,
                            font=FONT_MEDIUM,
                            bg=BACKGROUND,
                            relief='groove',
                            bd=0)

        # ComboBox
        smtp_combo = Combobox(Interface.window,
                              width=19,
                              textvariable=Interface.smtp_label)
        smtp_combo['values'] = ('Google:smtp.gmail.com',
                                'Outlook:smtp.live.com',
                                'Office365:smtp.office365.com',
                                'Yahoo:smtp.mail.yahoo.com',
                                'YahooPlus:plus.smtp.mail.yahoo.com',
                                'YahooUK:smtp.mail.yahoo.co.uk',
                                'Hotmail:smtp.live.com',
                                'AT&T:smtp.att.yahoo.com',
                                'O2UK:smtp.o2.co.uk')
        camera_src_label = StringVar()
        self.camera_combo = Combobox(Interface.window,
                                     width=5,
                                     textvariable=camera_src_label)
        self.camera_combo['values'] = ('0', '1', '2', '3')
        self.camera_combo.current(1)
        smtp_combo.current(0)
        browse_detections_bttn = Button(text="Browse Detections",
                                        command=self.browse_images,
                                        bg=BACKGROUND,
                                        highlightthickness=0)

        # Grid Setup
        title.grid(row=1, column=0, sticky='w', columnspan=3)
        please_choose_text.grid(row=2, column=0, sticky='w')
        self.file_directory_ent.grid(row=7, column=0, columnspan=2, sticky='w')
        please_upload_text.grid(row=6, column=0, sticky='w')
        upload_bttn.grid(row=7, column=2)
        sep.grid(row=0, column=7, rowspan=9, sticky='ns', padx=20)
        smtp_server_text.grid(row=5, column=5)
        webcam_radio_bttn.grid(row=3, column=0, sticky='w')
        image_radio_bttn.grid(row=5, column=0, sticky='w')
        video_radio_bttn.grid(row=5, column=1, sticky='w')
        email_setup_text.grid(row=2, column=5)
        camera_source_text.grid(row=3, column=1, sticky='w')
        space.grid(row=3, column=3)
        self.from_email_ent.grid(row=3, column=6)
        password_text.grid(row=4, column=5)
        from_email_text.grid(row=3, column=5)
        smtp_combo.grid(row=5, column=6)
        self.to_email_ent.grid(row=6, column=6)
        self.camera_combo.grid(row=3, column=2)
        to_email_text.grid(row=6, column=5)
        target_detection_text.grid(row=0, column=8, columnspan=2)
        start_bttn.grid(row=8, column=6, columnspan=2, padx=30, pady=30)

        Interface.info_text.grid(row=8, column=0, columnspan=3)
        Interface.from_password_ent.grid(row=4, column=6)
        browse_detections_bttn.grid(row=2, column=8, columnspan=2)
        auto_send.grid(row=3, column=8, columnspan=2)
        Interface.timer_label.grid(row=4, column=8, columnspan=2)
        send_bttn.grid(row=5, column=8, columnspan=2)
        Interface.canvas.grid(row=1, column=8, columnspan=2)
        Interface.progress_bar.grid(row=9, column=6, columnspan=2)

        Interface.window.mainloop()