-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterface.py
More file actions
95 lines (70 loc) · 3.7 KB
/
Copy pathinterface.py
File metadata and controls
95 lines (70 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# interface.py
import tkinter as tk
from tkinter import filedialog, messagebox, simpledialog
from PIL import Image, ImageTk
import subprocess
from Detector import Detector
class Interface:
def __init__(self, master, detector):
self.master = master
self.master.title("Object Detection Using TensorFlow")
self.master.geometry("600x400")
self.detector = detector # Pass the detector object
# Load background image (handle potential errors)
try:
bg_image = Image.open("chatbot-bcg.jpg") # Assuming background image filename is "bcg.jpg"
self.background_photo = ImageTk.PhotoImage(bg_image)
self.bg_label = tk.Label(master, image=self.background_photo)
self.bg_label.place(x=0, y=0, relwidth=1, relheight=1)
except FileNotFoundError:
messagebox.showerror("Error", "Background image 'bcg.jpg' not found. Using default background.")
# Consider using a default background image here (optional)
# Heading Label
heading_label = tk.Label(master, text="Object Detection", font=("Helvetica", 20, "bold"), bg="white")
heading_label.place(relx=0.5, rely=0.05, anchor=tk.CENTER)
# Image Processing Section
image_frame = tk.Frame(master, bg="white", bd=5)
image_frame.place(relx=0.5, rely=0.35, anchor=tk.CENTER)
image_button = self.create_button(image_frame, "Process Image", self.process_image, 0, 0)
video_button = self.create_button(image_frame, "Process Video", self.process_video, 0, 1)
rtsp_button = self.create_button(image_frame, "Process RTSP Stream", self.process_rtsp, 0, 2)
drtspStream_button = self.create_button(image_frame, "Choose channel", self.rtsp_stream, 0, 3)
def create_button(self, frame, text, command, row, column):
button = tk.Button(frame, text=text, font=("Helvetica", 12), command=command)
button.grid(row=row, column=column, padx=10, pady=10)
return button
def process_image(self):
file_path = filedialog.askopenfilename(filetypes=[("Image Files", "*.jpg;*.jpeg;*.png")])
if file_path:
self.detector.predictImage(file_path)
def process_video(self):
file_path = filedialog.askopenfilename(filetypes=[("Video Files", "*.mp4;*.avi")])
if file_path:
self.detector.predictVideoSource(file_path)
def process_rtsp(self):
channel = simpledialog.askstring("RTSP Stream URL Processing ", "Enter channel no.:")
if channel:
self.detector.predictRTSPStream(channel)
def rtsp_stream(self):
channel = simpledialog.askstring("RTSP Stream URL", "Enter channel no.:")
if channel:
subprocess.run(["python", "RTSP_cam.py", "--channel", channel])
def show_output(self, output_file_path):
try:
output_image = Image.open(output_file_path)
output_image = output_image.resize((300, 200), resample=Image.ANTIALIAS)
output_photo = ImageTk.PhotoImage(output_image)
output_label = tk.Label(self.master, image=output_photo)
output_label.image = output_photo
output_label.pack(pady=10)
except FileNotFoundError:
messagebox.showerror("Error", "Output file not found.")
def main():
modelURL = "http://download.tensorflow.org/models/object_detection/tf2/20200711/centernet_resnet101_v1_fpn_512x512_coco17_tpu-8.tar.gz"
classFile = "coco.names"
root = tk.Tk()
detector = Detector(modelURL, classFile)
gui = Interface(root, detector)
root.mainloop()
if __name__ == "__main__":
main()