Commit 032543f9 authored by khymas's avatar khymas

Started integrating opencv

parent 7d0e37de
#Imports
from videostream import *
import tkinter as tk
from tkinter import *
......@@ -8,9 +9,9 @@ class Application(Frame):
super().__init__()
self.toolbarExists = False
self.master.geometry(str(self.master.winfo_screenwidth()) + "x" + str(0)+"+0+0")
self.icons = [tk.PhotoImage(file="/home/kieran/Documents/Code/Pycroscope/assets/icons/snapshot.png"), \
tk.PhotoImage(file="/home/kieran/Documents/Code/Pycroscope/assets/icons/record.png") \
]
self.icons = [tk.PhotoImage(file="./assets/icons/snapshot.png"), \
tk.PhotoImage(file="./assets/icons/record.png") \
]
self.initApp()
def __version__(self):
......@@ -27,7 +28,7 @@ class Application(Frame):
self.master.config(menu=menubar)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="New session", command=self.onNew)
filemenu.add_command(label="New session", command=lambda arg=0 : self.initVideoFeed(arg))
filemenu.add_command(label="Exit Pycroscope", command=self.onExit)
menubar.add_cascade(label="File", menu=filemenu)
......@@ -54,7 +55,7 @@ class Application(Frame):
toolbar = Toplevel(self.master, bd=1, relief=RAISED)
toolbar.geometry("+" + str(self.master.winfo_screenwidth()) + "+" + str(self.master.winfo_screenheight() // 3))
#load icons
#load icons
pair1 = Frame(toolbar)
snapshotButton = Button(pair1, relief=FLAT, image=self.icons[0], command=self.onSnapshot)
snapshotButton.pack(side=LEFT, padx=1, pady=1)
......@@ -87,6 +88,14 @@ class Application(Frame):
toolbar.protocol("WM_DELETE_WINDOW", lambda arg=toolbar: self.onClosing(arg))
def initVideoFeed(self, video_src):
try:
self.vid = VideoStream(video_src)
self.canvas = tk.Canvas(self.master, width=self.vid.width, height=self.vid.height)
self.canvas.pack()
except ValueError:
return
#Menubar options
#File
def onNew(self):
......@@ -99,16 +108,11 @@ class Application(Frame):
def onPreferences(self):
print("Preferences!")
#Tools
#Help
def onAbout(self):
about = Toplevel(self.master)
about.title("Pycroscope: About")
#Toolbar options
def onSnapshot(self):
print("Snapshot!")
......
#Imports
import cv2
import imutils
#Classes
class VideoStream():
def __init__(self, video_src=0):
self.vid = cv2.VideoCapture(video_src)
if not self.vid.isOpened():
print('[-] Error: Couldn\'t open video stream at source: ', video_src)
raise ValueError()
self.width = self.vid.get(cv2.CAP_PROP_FRAME_WIDTH)
self.height = self.vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
def __del__(self):
if self.vid.isOpened():
self.vid.release()
def get_frame(self):
if self.vid.isOpened():
ret, frame = self.vid.read()
if ret:
return (ret, cv2.cvtColor(frame, cv2.COLOR_BGR2RBG))
else:
return (ret, None)
else:
return (ret, None)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment