-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebcam.py
46 lines (34 loc) · 1.33 KB
/
webcam.py
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
# Edited on 6/13/23 by Patrick Madonna
#Original Creator - matthewkayne
"""Webcam"""
from tkinter import Label
from PIL import Image, ImageTk
import cv2
class Box:
"""Box"""
def __init__(self, window, width=450, height=450):
self.window = window
self.width = width
self.height = height
self.label = Label(self.window, width=self.width, height=self.height,bg = '#D2B48C')
self.cap = cv2.VideoCapture(0)
self.label.place(x= 250, y = 300)
def get_box_info(self):
"""Gets Box Information """
print(f"Window: {self.window}")
print(f"Width: {self.width}")
print(f"Height: {self.height}")
def show_frames(self): # Define function to show frame
"""Show Frames"""
# Get the latest frame and convert into Image
cv2image = cv2.cvtColor(self.cap.read()[1], cv2.COLOR_BGR2RGB)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img) # Convert image to PhotoImage
self.label.imgtk = imgtk
self.label.configure(image=imgtk)
# Repeat after an interval to capture continiously
self.label.after(20, self.show_frames)
def take_pic(self): # this will return a picture
ret, frame = self.cap.read()
cv2.imwrite('Pictures\\feed.png',frame)
#self.cap.release()