177 lines
5.5 KiB
Python
177 lines
5.5 KiB
Python
|
|
import tkinter as tk
|
||
|
|
from tkinter import messagebox, filedialog
|
||
|
|
import cv2
|
||
|
|
from PIL import Image, ImageTk
|
||
|
|
import numpy as np
|
||
|
|
import tensorflow as tf
|
||
|
|
import pygame
|
||
|
|
import time
|
||
|
|
from moviepy.editor import VideoFileClip
|
||
|
|
|
||
|
|
is_paused = False
|
||
|
|
cap = None
|
||
|
|
model = None
|
||
|
|
audio_path = None
|
||
|
|
|
||
|
|
|
||
|
|
def validar_login():
|
||
|
|
user = userdig.get()
|
||
|
|
password = passdig.get()
|
||
|
|
if user == "admin" and password == "12345":
|
||
|
|
login.destroy()
|
||
|
|
abrir_menu_principal()
|
||
|
|
else:
|
||
|
|
messagebox.showerror("Erro", "User ou password incorretos!")
|
||
|
|
|
||
|
|
def abrir_menu_principal():
|
||
|
|
menu_principal = tk.Tk()
|
||
|
|
menu_principal.title("Menu Principal")
|
||
|
|
menu_principal.geometry("400x300")
|
||
|
|
|
||
|
|
label_menu = tk.Label(menu_principal, text="Escolha uma opção", font=("Arial", 16))
|
||
|
|
label_menu.pack(pady=20)
|
||
|
|
|
||
|
|
|
||
|
|
botao_analise_video = tk.Button(menu_principal, text="Analisar Videos", width=20, command=abrir_janela_principal)
|
||
|
|
botao_analise_video.pack(pady=10)
|
||
|
|
|
||
|
|
|
||
|
|
botao_carregar_modelo = tk.Button(menu_principal, text="Carregar Modelo", width=20, command=abrir_janela_modelo)
|
||
|
|
botao_carregar_modelo.pack(pady=10)
|
||
|
|
|
||
|
|
|
||
|
|
botao_configuracoes = tk.Button(menu_principal, text="Configurações", width=20, command=abrir_janela_configuracoes)
|
||
|
|
botao_configuracoes.pack(pady=10)
|
||
|
|
|
||
|
|
menu_principal.mainloop()
|
||
|
|
|
||
|
|
# Janela de análise de vídeo
|
||
|
|
def abrir_janela_principal():
|
||
|
|
global root, video, placeholder_text, play_button, pause_button
|
||
|
|
root = tk.Tk()
|
||
|
|
root.title("Análise de Vídeo")
|
||
|
|
root.geometry("1000x800")
|
||
|
|
|
||
|
|
botao_carregar_video = tk.Button(root, text="Carregar Vídeo", command=carregar_video)
|
||
|
|
botao_carregar_video.place(relx=0.5, rely=0.05, anchor='n', x=5, y=10)
|
||
|
|
|
||
|
|
video = tk.Label(root, width=70, height=20, bg="grey")
|
||
|
|
video.place(x=50, y=100)
|
||
|
|
|
||
|
|
botao_sair = tk.Button(root, text="Sair", command=sair)
|
||
|
|
botao_sair.place(relx=1.0, rely=1.0, anchor='se', x=-30, y=-30)
|
||
|
|
|
||
|
|
play_button = tk.Button(root, text="Play", command=play_video)
|
||
|
|
play_button.place(relx=0.3, rely=0.05, anchor='n', x=10, y=10)
|
||
|
|
|
||
|
|
pause_button = tk.Button(root, text="Pause", command=pause_video)
|
||
|
|
pause_button.place(relx=0.4, rely=0.05, anchor='n', x=20, y=10)
|
||
|
|
|
||
|
|
root.mainloop()
|
||
|
|
|
||
|
|
# Janela para carregar o modelo
|
||
|
|
def abrir_janela_modelo():
|
||
|
|
janela_modelo = tk.Tk()
|
||
|
|
janela_modelo.title("Carregar Modelo")
|
||
|
|
janela_modelo.geometry("300x200")
|
||
|
|
|
||
|
|
label_modelo = tk.Label(janela_modelo, text="Carregar Modelo de IA", font=("Arial", 14))
|
||
|
|
label_modelo.pack(pady=20)
|
||
|
|
|
||
|
|
botao_carregar_modelo = tk.Button(janela_modelo, text="Carregar Modelo", command=carregar_modelo)
|
||
|
|
botao_carregar_modelo.pack(pady=20)
|
||
|
|
|
||
|
|
janela_modelo.mainloop()
|
||
|
|
|
||
|
|
# Janela de configurações
|
||
|
|
def abrir_janela_configuracoes():
|
||
|
|
janela_config = tk.Tk()
|
||
|
|
janela_config.title("Configurações")
|
||
|
|
janela_config.geometry("300x200")
|
||
|
|
|
||
|
|
label_config = tk.Label(janela_config, text="Configurações", font=("Arial", 14))
|
||
|
|
label_config.pack(pady=20)
|
||
|
|
|
||
|
|
# Aqui você pode adicionar elementos de configuração, como opções de caminho de arquivos, etc.
|
||
|
|
janela_config.mainloop()
|
||
|
|
|
||
|
|
def carregar_video():
|
||
|
|
global audio_path
|
||
|
|
video_path = filedialog.askopenfilename(filetypes=[("Video Files", "*.mp4 *.avi *.mkv")])
|
||
|
|
if video_path:
|
||
|
|
reproduzir_video(video_path)
|
||
|
|
placeholder_text.place_forget()
|
||
|
|
|
||
|
|
def reproduzir_video(video_path):
|
||
|
|
global cap, audio_path
|
||
|
|
cap = cv2.VideoCapture(video_path)
|
||
|
|
video = tk.Label(root, width=500, height=400, bg="grey")
|
||
|
|
video.place(x=50, y=100)
|
||
|
|
pygame.mixer.init()
|
||
|
|
video_clip = VideoFileClip(video_path)
|
||
|
|
audio_path = "temp_audio.mp3"
|
||
|
|
video_clip.audio.write_audiofile(audio_path)
|
||
|
|
pygame.mixer.music.load(audio_path)
|
||
|
|
pygame.mixer.music.play(-1)
|
||
|
|
mostrar_frame()
|
||
|
|
|
||
|
|
def mostrar_frame():
|
||
|
|
global is_paused, cap, video
|
||
|
|
if not is_paused and cap is not None:
|
||
|
|
ret, frame = cap.read()
|
||
|
|
if ret:
|
||
|
|
frame_altura, frame_largura = frame.shape[:2]
|
||
|
|
ratio = min(1000 / frame_largura, (500 - 100) / frame_altura)
|
||
|
|
novo_tamanho = (int(frame_largura * ratio), int(frame_altura * ratio))
|
||
|
|
frame_redimensionado = cv2.resize(frame, novo_tamanho)
|
||
|
|
frame_rgb = cv2.cvtColor(frame_redimensionado, cv2.COLOR_BGR2RGB)
|
||
|
|
imagem = Image.fromarray(frame_rgb)
|
||
|
|
imagem_tk = ImageTk.PhotoImage(image=imagem)
|
||
|
|
video.imgtk = imagem_tk
|
||
|
|
video.config(image=imagem_tk, width=imagem_tk.width(), height=imagem_tk.height())
|
||
|
|
video.after(20, mostrar_frame)
|
||
|
|
else:
|
||
|
|
cap.release()
|
||
|
|
|
||
|
|
def play_video():
|
||
|
|
global is_paused
|
||
|
|
is_paused = False
|
||
|
|
mostrar_frame()
|
||
|
|
pygame.mixer.music.unpause()
|
||
|
|
|
||
|
|
def pause_video():
|
||
|
|
global is_paused
|
||
|
|
is_paused = True
|
||
|
|
pygame.mixer.music.pause()
|
||
|
|
|
||
|
|
def sair():
|
||
|
|
global cap, audio_path
|
||
|
|
if cap is not None:
|
||
|
|
cap.release()
|
||
|
|
pygame.mixer.music.stop()
|
||
|
|
pygame.mixer.music.unload()
|
||
|
|
time.sleep(1)
|
||
|
|
if audio_path:
|
||
|
|
import os
|
||
|
|
try:
|
||
|
|
os.remove(audio_path)
|
||
|
|
except PermissionError:
|
||
|
|
print("Erro ao remover o arquivo de áudio.")
|
||
|
|
root.destroy()
|
||
|
|
|
||
|
|
# Janela de login inicial
|
||
|
|
login = tk.Tk()
|
||
|
|
login.title("Login")
|
||
|
|
login.geometry("300x200")
|
||
|
|
label_usuario = tk.Label(login, text="Usuário:")
|
||
|
|
label_usuario.pack(pady=5)
|
||
|
|
userdig = tk.Entry(login)
|
||
|
|
userdig.pack(pady=5)
|
||
|
|
label_senha = tk.Label(login, text="Senha:")
|
||
|
|
label_senha.pack(pady=5)
|
||
|
|
passdig = tk.Entry(login, show="*")
|
||
|
|
passdig.pack(pady=5)
|
||
|
|
botao_login = tk.Button(login, text="Login", command=validar_login)
|
||
|
|
botao_login.pack(pady=20)
|
||
|
|
login.mainloop()
|