Compare commits

..

7 Commits

Author SHA1 Message Date
Blake Blackshear
68bfa6010d skip frames in the capture thread instead 2020-04-19 10:07:27 -05:00
Blake Blackshear
a810c56811 expose frame time at each step of processing 2020-04-19 07:49:23 -05:00
Blake Blackshear
5333b8ae1b ensure the previous frame is deleted when the new one is stored 2020-04-10 07:05:07 -04:00
Blake Blackshear
2bc57d271c move ffmpeg capture to a separate thread and use a queue 2020-03-14 15:32:51 -05:00
Blake Blackshear
8507bbbb31 make object processor resilient to plasma failures 2020-03-13 16:35:58 -05:00
Blake Blackshear
b6fcb88e5c remove sharedarray references 2020-03-13 15:50:27 -05:00
Blake Blackshear
d3cd4afa65 handle various scenarios with external process failures 2020-03-09 21:12:19 -05:00
2 changed files with 5 additions and 21 deletions

View File

@@ -7,7 +7,7 @@ RUN apt -qq update && apt -qq install --no-install-recommends -y \
software-properties-common \
# apt-transport-https ca-certificates \
build-essential \
gnupg wget unzip tzdata \
gnupg wget unzip \
# libcap-dev \
&& add-apt-repository ppa:deadsnakes/ppa -y \
&& apt -qq install --no-install-recommends -y \

View File

@@ -63,7 +63,7 @@ DEBUG = (CONFIG.get('debug', '0') == '1')
def start_plasma_store():
plasma_cmd = ['plasma_store', '-m', '400000000', '-s', '/tmp/plasma']
plasma_process = sp.Popen(plasma_cmd, stdout=sp.DEVNULL, stderr=sp.DEVNULL)
plasma_process = sp.Popen(plasma_cmd, stdout=sp.DEVNULL)
time.sleep(1)
rc = plasma_process.poll()
if rc is not None:
@@ -84,8 +84,6 @@ class CameraWatchdog(threading.Thread):
while True:
# wait a bit before checking
time.sleep(10)
now = datetime.datetime.now().timestamp()
# check the plasma process
rc = self.plasma_process.poll()
@@ -94,9 +92,8 @@ class CameraWatchdog(threading.Thread):
self.plasma_process = start_plasma_store()
# check the detection process
detection_start = self.tflite_process.detection_start.value
if (detection_start > 0.0 and
now - detection_start > 10):
if (self.tflite_process.detection_start.value > 0.0 and
datetime.datetime.now().timestamp() - self.tflite_process.detection_start.value > 10):
print("Detection appears to be stuck. Restarting detection process")
self.tflite_process.start_or_restart()
elif not self.tflite_process.detect_process.is_alive():
@@ -129,17 +126,6 @@ class CameraWatchdog(threading.Thread):
camera_capture.start()
camera_process['ffmpeg_process'] = ffmpeg_process
camera_process['capture_thread'] = camera_capture
elif now - camera_process['capture_thread'].current_frame > 5:
print(f"No frames received from {name} in 5 seconds. Exiting ffmpeg...")
ffmpeg_process = camera_process['ffmpeg_process']
ffmpeg_process.terminate()
try:
print("Waiting for ffmpeg to exit gracefully...")
ffmpeg_process.communicate(timeout=30)
except sp.TimeoutExpired:
print("FFmpeg didnt exit. Force killing...")
ffmpeg_process.kill()
ffmpeg_process.communicate()
def main():
# connect to mqtt and setup last will
@@ -342,9 +328,7 @@ def main():
if frame is None:
frame = np.zeros((height,int(height*16/9),3), np.uint8)
width = int(height*frame.shape[1]/frame.shape[0])
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_LINEAR)
frame = cv2.resize(frame, dsize=(int(height*16/9), height), interpolation=cv2.INTER_LINEAR)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
ret, jpg = cv2.imencode('.jpg', frame)