-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTkinter_Webcam.py
More file actions
50 lines (42 loc) · 1.27 KB
/
Tkinter_Webcam.py
File metadata and controls
50 lines (42 loc) · 1.27 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
#!/usr/bin/env python
# coding: utf-8
import tkinter as tk
import cv2
from PIL import Image, ImageTk
root=tk.Tk()
# Set the size of the window
root.geometry("780x600")
# Set the window background color
root.configure(bg="#a8dba8")
def start_webcam():
ret, frame= cap.read()
if flip_var.get():
frame=cv2.flip(frame,1)
if gray_var.get():
frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
cv2image=cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
img=Image.fromarray(cv2image)
imgtk=ImageTk.PhotoImage(image=img)
lmain.imgTk=imgtk
lmain.configure(image=imgtk)
lmain.after(10,start_webcam)
root.title=("Webcam Viewer")
cap=cv2.VideoCapture(0)
flip_var=tk.BooleanVar()
gray_var=tk.BooleanVar()
flip_var.set(True)
gray_var.set(False)
flip_checkbox= tk.Checkbutton(root,text='Flip',variable=flip_var,bg="#a8dba8")
flip_checkbox.pack()
gray_checkbox = tk.Checkbutton(root , text='GrayScale',variable=gray_var,bg="#a8dba8")
gray_checkbox.pack()
lmain = tk.Label(root)
lmain.pack()
start_button = tk.Button(root ,text='Start Webcam',command = start_webcam,bg="#57BE85")
start_button.pack()
def stop_webcam():
cap.release()
root.destroy()
stop_button = tk.Button(root ,text='Stop Webcam',command = stop_webcam,bg="#3b8686")
stop_button.pack()
root.mainloop()