Skip to content

Commit

Permalink
Move api_url from config.json to .env
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong1120 committed May 7, 2024
1 parent 95ffcdc commit b39616c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/Model-Server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ def create_tables():

if __name__ == '__main__':
# Run the Flask application on all available IPs at port 5000
app.run(host='0.0.0.0', port=5000)
app.run(Thread = True, host='0.0.0.0', port=5000)
9 changes: 7 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import time
import gc
from typing import NoReturn, Dict
import os
from dotenv import load_dotenv

from src.stream_capture import StreamCapture
from src.line_notifier import LineNotifier
from src.monitor_logger import LoggerConfig
from src.live_stream_detection import LiveStreamDetector
from src.danger_detector import DangerDetector

def main(logger, video_url: str, api_url: str = 'http://localhost:5000', model_key: str = 'yolov8x', label: str = None, image_name: str = 'prediction_visual.png', line_token: str = None, output_path: str = None) -> NoReturn:
def main(logger, video_url: str, model_key: str = 'yolov8x', label: str = None, image_name: str = 'prediction_visual.png', line_token: str = None, output_path: str = None) -> NoReturn:
"""
Main execution function that detects hazards, sends notifications, logs warnings, and optionally saves output images.
Expand All @@ -24,6 +26,9 @@ def main(logger, video_url: str, api_url: str = 'http://localhost:5000', model_k
image_name (str, optional): The file name of the image to send with notifications. Defaults to 'demo_data/{label}/prediction_visual.png'.
output_path (str, optional): The file path where output images should be saved. If not specified, images are not saved.
"""
# Load environment variables
load_dotenv()
api_url = os.getenv('API_URL', 'http://localhost:5000')

steaming_capture = StreamCapture(stream_url = video_url)

Expand Down Expand Up @@ -55,7 +60,7 @@ def main(logger, video_url: str, api_url: str = 'http://localhost:5000', model_k
if output_path:
# Here you could modify or extend the output filename based on timestamp or other criteria
output_file = output_path.format(timestamp=timestamp)
live_stream_detector.save_frame(frame, output_file)
live_stream_detector.save_frame(frame)

# Check for warnings and send notifications if necessary
warnings = danger_detector.detect_danger(datas)
Expand Down
6 changes: 3 additions & 3 deletions src/live_stream_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ def save_frame(self, frame: cv2.Mat) -> None:
# Define the complete output path including the filename
output_path = output_dir / self.output_filename

# Check if the file exists and remove it if it does
if output_path.exists():
output_path.unlink()
# # Check if the file exists and remove it if it does
# if output_path.exists():
# output_path.unlink()

# Save the image to the specified path
cv2.imwrite(str(output_path), frame)
Expand Down
14 changes: 7 additions & 7 deletions src/stream_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def capture_frames(self) -> Generator[Tuple[cv2.Mat, float], None, None]:
continue

current_time = datetime.datetime.now()
if (current_time - last_process_time).total_seconds() >= 5:
if (current_time - last_process_time).total_seconds() >= 15:
last_process_time = current_time
timestamp = current_time.timestamp()

yield frame, timestamp

# Skip frames if necessary
for _ in range(5): # Skip 5 frames
self.cap.grab()
# # Skip frames if necessary
# for _ in range(5): # Skip 5 frames
# self.cap.grab()

if cv2.waitKey(1) & 0xFF == ord('q'):
break
Expand Down Expand Up @@ -169,9 +169,9 @@ def capture_youtube_frames(self) -> Generator[Tuple[cv2.Mat, float], None, None]
timestamp = current_time.timestamp()
yield frame, timestamp

# Skip frames if necessary to manage frame rate
for _ in range(5): # Skip 5 frames
self.cap.grab()
# # Skip frames if necessary to manage frame rate
# for _ in range(5): # Skip 5 frames
# self.cap.grab()

if cv2.waitKey(1) & 0xFF == ord('q'):
break
Expand Down

0 comments on commit b39616c

Please sign in to comment.