-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
116 lines (88 loc) · 5.31 KB
/
app.py
File metadata and controls
116 lines (88 loc) · 5.31 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Imports
import tkinter as tk
from tkinter import ttk
from frames import VideoFrame, ControlsFrame, SetupFrame
# Above: import Frame classes from frames folder
from controller import Controller
import PyCapture2
#Set DPI awareness (needed for some newer screens)
try:
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
except:
pass
#Class for Root of application
class DS_GUI(tk.Tk): #create a class of type Tk class
def __init__(self, *args, **kwargs): #initialise the class
super().__init__(*args, **kwargs) #call the constructor of the Tk
#class to inherit properties
self.controller = None
screen_width = self.winfo_screenwidth() #get the width of the screen
screen_height = self.winfo_screenheight() #get the height of the screen
#Configurations of the Root
self.title("Digital Shearography - Project 55")
# Above: title of application
self.geometry("{}x{}+0+0".format(screen_width, screen_height))
# Above: Set the size of the window to fullscreen by default
self.columnconfigure(0, weight=1) #configure weights of the columns and rows
self.rowconfigure(0, weight=1)
#Main Container to Hold the Class Frames (video, control and setup)
main_container = ttk.Frame(self)
main_container.grid(row=0, column=0)
main_container.columnconfigure(0, weight=2)
main_container.columnconfigure(1, weight=1)
# Above: column 0 of main_container is given 2 times the space
# of row 1
main_container.rowconfigure(0, weight=1)
main_container.rowconfigure(1, weight=7)
# Above: row 0 of main_container is given 7 times the space
# of row 1
# Frames inside main container
# 1. ControlsFrame
self.controls_frame = ControlsFrame(main_container, controller)
self.controls_frame.grid(row=0, column=0, columnspan=2, pady=(10), sticky="NSEW")
# 2. VideoFrame
self.video_frame = VideoFrame(main_container, screen_width, screen_height, c, 33)
# Above: pass in parent frame, screen height & width, camera object and delay between refreshing video frames
self.video_frame.grid(row=1, column=0, pady=(30), padx=(30), sticky="NSEW")
self.video_frame.display_video()
# 3. SetupFrame
self.setup_frame = SetupFrame(main_container, controller)
self.setup_frame.grid(row=1, column=1, pady=(30), padx=(30), sticky="NSEW")
def set_controller(self, controller): #pass in Controller class as the controller
self.controller = controller
# Below: create instances of the frame classes
# so that they can be accessed in the controller
controller.set_video_frame(self.video_frame)
controller.set_controls_frame(self.controls_frame)
controller.set_setup_frame(self.setup_frame)
###################################################################################################################
###################################################################################################################
######################### CAMERA SETUP #########################
bus = PyCapture2.BusManager() # identify the Globally Unique Identifier (GUID) of the camera
num_cams = bus.getNumOfCameras() # determine the number of cameras connected to the PC
print('Number of cameras detected:', num_cams) # print the number of cameras detected
if not num_cams: # if no cameras are detected exit the application
print('Insufficient number of cameras. Exiting...')
exit()
# Select camera on 0th index
c = PyCapture2.Camera() # Assign Camera object to C
uid = bus.getCameraFromIndex(0) # select camera on 0th index
c.connect(uid) # connect camera object to physical camera
# Disable On-board Image Processing
c.setProperty(type = PyCapture2.PROPERTY_TYPE.AUTO_EXPOSURE, onOff = False) #Disable Auto Exposure
print('Starting image capture...')
c.startCapture() # start capturing data from the camera to the image buffers
###################################################################################################################
###################################################################################################################
controller = Controller() # create object controller of the Controller() class
app = DS_GUI() # create a DS_GUI object
app.set_controller(controller) # use the DS_GUI.set_controller() methods to assign the controller
app.mainloop() # call DS_GUI inherited method, mainloop() to run the application
try: # try:
c.stopCapture() # stop capturing data from the camera to the image buffers
print("stopping capture")
c.disconnect() # disconnect the camera object from the physical camera
print("camera disconnected")
except: # except:
exit() # close application