Skip to content

Commit

Permalink
Speed up and reduce tread cpu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pageauc committed Sep 16, 2023
1 parent 240d324 commit 789bc10
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions strmpilibcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, size=(320, 240), vflip=False, hflip=False):
transform=Transform(vflip=vflip,
hflip=hflip)))
self.picam2.start()
time.sleep(2)
time.sleep(2) # allow time for camera to warm up

# initialize variables
self.thread = None # Initialize Thread variable
Expand All @@ -54,17 +54,17 @@ def update(self):
# if the thread indicator variable is set,
# release camera resources and stop the thread
if self.stopped:
self.picam2.stop()
if self.thread is not None:
self.thread.join()
return
time.sleep(0.01) # short delay
self.frame = self.picam2.capture_array()
time.sleep(0.001) # Slow loop down a little


def read(self):
'''return the frame array data'''
self.frame = self.picam2.capture_array("main")
return self.frame

def stop(self):
'''indicate that the thread should be stopped'''
self.stopped = True
self.picam2.stop() # stop picamera2 libcamera
time.sleep(2) # allow camera time to released
self.stopped = True

0 comments on commit 789bc10

Please sign in to comment.