Skip to content

Commit

Permalink
Resolution set via env support
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszmichalskii committed Apr 27, 2023
1 parent c243961 commit 358f333
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ in building an autonomous formula. The project is proof of concept of cones dete
the currently developed perception system. The positions of the cones seen through the camera are then
used by the car’s autonomous system to drive.

<!-- CAMERA PERCEPTION -->
## Camera perception

[Cones detection](https://github.com/lukaszmichalskii/camera-perception/blob/master/docs/yolo/autocross.mp4) model in version 2.0 during PWR Racing Team car test on autocross event

<!-- BACKLOG -->
## Backlog

Expand Down
4 changes: 3 additions & 1 deletion src/camera_perception/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class CameraError(Exception):


class Camera:
def __init__(self, video):
def __init__(self, video, resolution):
self.frame_width, self.frame_height = resolution
self.lens = cv2.VideoCapture(video)

def get_frame(self):
Expand All @@ -17,6 +18,7 @@ def get_frame(self):
ret, frame = self.lens.read()
if not ret:
break
frame = cv2.resize(frame, (self.frame_width, self.frame_height))
yield frame

def turn_off(self):
Expand Down
16 changes: 14 additions & 2 deletions src/camera_perception/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from platform import platform

import torch
Expand All @@ -17,6 +18,12 @@ def processing_unit() -> str:
return "CUDA" if torch.cuda.is_available() else "CPU"


def get_resolution(resolution_env):
regex = r"\d+"
resolution = re.findall(regex, resolution_env)
return int(resolution[0]), int(resolution[1])


class Environment:
"""
Class for storing user specific configuration overwritten using environmental variables
Expand All @@ -26,14 +33,19 @@ def __init__(self, env):
self.os = get_current_os()
self.conf = float(env.get("CONFIDENCE", 0.7))
self.processing_unit = processing_unit()
self.resolution = get_resolution(env.get("RESOLUTION", "1280x720"))

@staticmethod
def from_env(env):
return Environment(env)

def to_info_string(self):
return "os: {}, processing unit: {}, detections confidence: {}%".format(
self.os, self.processing_unit, self.conf * 100
return "os: {}, processing unit: {}, detections confidence: {}%, resolution: {}x{}".format(
self.os,
self.processing_unit,
self.conf * 100,
self.resolution[0],
self.resolution[1],
)

def cuda_to_info_string(self):
Expand Down
4 changes: 3 additions & 1 deletion src/camera_perception/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def get_help_epilog():
Environment variables:
CONFIDENCE : Model detection confidence threshold
Default: 0.7
RESOLUTION : Frame or image resolution, for better performance consider smaller resolutions
Default: 1280x720
Usage:
Run system with video:
Expand Down Expand Up @@ -86,7 +88,7 @@ def label():
return 4

font = cv2.FONT_HERSHEY_DUPLEX
camera_lens = Camera(args.video)
camera_lens = Camera(args.video, environment.resolution)
cones_detector = ConesDetector()
try:
for frame in camera_lens.get_frame():
Expand Down

0 comments on commit 358f333

Please sign in to comment.