This is the window I am creating a UI using tkinter and I am trying to display 4 multiple video stream in a window. I created a 6 x 4 grid system and I put the first video display in row 1 column Second vid is row 1 column 2 third is row 2 column 1 and fourth row 2 column 2.
Whenever I try to display it using label the video has a space between them.
I tried to set the padx and y to 0 but nothing changes. I want to make the videos has no gap between them.
frame_w = 300
frame_h = 300
frame_rate = 30
delay_between_frames = 1/frame_rate
def segment_a(mask, video_path, label):
mask_img = cv2.imread(mask, 0)
cap = cv2.VideoCapture(video_path)
connected_components = cv2.connectedComponentsWithStats(mask_img, 4, cv2.CV_32S)
spots = get_parking_spots_bboxes(connected_components)
while True:
ret, frame = cap.read()
if not ret:
break
for spot in spots:
x1, y1, w, h = spot
frame = cv2.rectangle(frame, (x1, y1), (x1 + w, y1 + h), (255, 0, 0), 2)
frame_resized = cv2.resize(frame, (frame_w, frame_h))
frame_rgb = cv2.cvtColor(frame_resized, cv2.COLOR_BGR2RGB)
image = Image.fromarray(frame_rgb)
image_tk = ImageTk.PhotoImage(image)
label.config(image=image_tk)
label.image = image_tk
time.sleep(delay_between_frames)
def segment_b(mask, video_path, label):
mask_img = cv2.imread(mask, 0)
cap = cv2.VideoCapture(video_path)
connected_components = cv2.connectedComponentsWithStats(mask_img, 4, cv2.CV_32S)
spots = get_parking_spots_bboxes(connected_components)
while True:
ret, frame = cap.read()
if not ret:
break
for spot in spots:
x1, y1, w, h = spot
frame = cv2.rectangle(frame, (x1, y1), (x1 + w, y1 + h), (255, 0, 0), 2)
frame_resized = cv2.resize(frame, (frame_w, frame_h))
frame_rgb = cv2.cvtColor(frame_resized, cv2.COLOR_BGR2RGB)
image = Image.fromarray(frame_rgb)
image_tk = ImageTk.PhotoImage(image)
label.config(image=image_tk)
label.image = image_tk
time.sleep(delay_between_frames)
def segment_c(mask, video_path, label):
mask_img = cv2.imread(mask, 0)
cap = cv2.VideoCapture(video_path)
connected_components = cv2.connectedComponentsWithStats(mask_img, 4, cv2.CV_32S)
spots = get_parking_spots_bboxes(connected_components)
while True:
ret, frame = cap.read()
if not ret:
break
for spot in spots:
x1, y1, w, h = spot
frame = cv2.rectangle(frame, (x1, y1), (x1 + w, y1 + h), (255, 0, 0), 2)
frame_resized = cv2.resize(frame, (frame_w, frame_h))
frame_rgb = cv2.cvtColor(frame_resized, cv2.COLOR_BGR2RGB)
image = Image.fromarray(frame_rgb)
image_tk = ImageTk.PhotoImage(image)
label.config(image=image_tk)
label.image = image_tk
time.sleep(delay_between_frames)
app = Tk()
app.geometry("800x500")
app.title("Video Stream")
# Widgets
vid_label1 = tk.Label(app, text="Video 1", anchor='center', background='blue' )
vid_label2 = ttk.Label(app, text="Video 2", anchor='center')
vid_label3 = ttk.Label(app, text='Video 3', anchor='center')
vid_label4 = ttk.Label(app, text='Video 4', anchor='center')
label4 = ttk.Label(app, text='INFO', background="orange")
label1 = ttk.Label(app, text='Label', background="lightgray")
#vid_label1.config(width=10, height=10)
# Define grid
app.columnconfigure(0, weight=1)
app.columnconfigure(1, weight=3)
app.columnconfigure(2, weight=3)
app.columnconfigure(3, weight=1)
app.columnconfigure(4, weight=1)
app.columnconfigure(5, weight=1)
app.rowconfigure(0, weight=1)
app.rowconfigure(1, weight=3)
app.rowconfigure(2, weight=3)
app.rowconfigure(3, weight=1)
# Place the widgets
vid_label1.grid(row=1, column=1)
vid_label2.grid(row=1, column=2)
vid_label3.grid(row=2, column=1)
vid_label4.grid(row=2, column=2)
label4.grid(row=1, column=4, sticky='nsew')
label1.grid(row=0, column=0)
# Configuration
# label0.config(width=10, height=10)
# label1.config(width=10, height=10)
# Create threads for video capture
thread1 = threading.Thread(target=segment_a, args=(maskA, video_pathA, vid_label1))
thread2 = threading.Thread(target=segment_b, args=(maskB, video_pathB, vid_label2))
# thread3 = threading.Thread(target=segment_c, args=(maskC, video_pathC, vid_label3))
# Start the threads
thread1.start()
thread2.start()
# thread3.start()
app.mainloop()
cv2.destroyAllWindows()