Skip to content

Commit

Permalink
video released now? jaybe, jaybe not
Browse files Browse the repository at this point in the history
  • Loading branch information
SkaisteMotiejunaite committed Dec 27, 2024
1 parent 67c0cad commit efdba20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 19 additions & 5 deletions App/pages/general_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from Algorithms.Objects.colour_detection import ColourRecognizer
from Algorithms.Objects.object_detection import ObjectRecognizer


class GeneralDemoPage(QWidget):
def __init__(self, title: str, description: str, algorithm: str):
super().__init__()
Expand Down Expand Up @@ -61,14 +62,24 @@ def __init__(self, title: str, description: str, algorithm: str):
print("Error: Could not open video stream.")
sys.exit()

self.failed_frames = 0 # Counter for consecutive failed frames
self.timer = self.startTimer(20)

def timerEvent(self, event):
ret, frame = self.cap.read()
if not ret:
print("Failed to grab frame.")
self.failed_frames += 1
print(f"Failed to grab frame {self.failed_frames} times.")

# Close the stream if the threshold is reached
if self.failed_frames > 10:
print("Too many failed frames. Stopping the stream.")
self.close() # Trigger close event
return

# Reset failed frames counter on successful frame capture
self.failed_frames = 0

if self.algorithm == "colour":
processed_frame = self.recognizer.detect_and_draw(frame)
elif self.algorithm == "object":
Expand All @@ -85,10 +96,13 @@ def timerEvent(self, event):

def closeEvent(self, event):
# Release the video capture and stop the algorithm
self.cap.release()
if hasattr(self, 'cap') and self.cap.isOpened():
self.cap.release()

print("Video stream and resources have been released.")

# If the recognizer uses any other background tasks or threads, stop them here
# For example, if there are timers or other resources, clean them up
# Stop the timer
self.killTimer(self.timer)

# Accept the close event (closes the window)
# Accept the close event
event.accept()
4 changes: 2 additions & 2 deletions App/pages/home_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ def open_facial_expression_page(self):
self.facial_expression_page.show()

def open_object_detection_page(self):
self.object_detection_page=GeneralDemoPage("Object Detection","dummy description")
self.object_detection_page=GeneralDemoPage("Object Detection","dummy description","object")
self.object_detection_page.show()

def open_colour_detection_page(self):
self.colour_detection_page=GeneralDemoPage("Colour Detection","dummy description")
self.colour_detection_page=GeneralDemoPage("Colour Detection","dummy description","colour")
self.colour_detection_page.show()

def open_lidar_page(self):
Expand Down

0 comments on commit efdba20

Please sign in to comment.