Skip to content

Commit

Permalink
Added resize before display and video record. Removed useless READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanSamelson committed Mar 11, 2022
1 parent 90c86e2 commit cec542b
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 31 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ The APTITUDE toolbox can be run on CPU. However, it is highly recommended to use
<details>
<summary>Using Docker (recommended)</summary>

If you want to infer result with the provided models or with your own model, we recommend to download the last Docker image (link available soon) or build it yourself. To do so, enter the following command. The build process should last ~15 minutes.
If you want to infer result with the provided models or with your own model, we recommend to pull the latest Docker image available on [Dockerhub](https://hub.docker.com/repository/docker/jonathansamelson/aptitude-toolbox).

You can also build it yourself. To do so, enter the following command. The build process should last ~15 minutes.

```
git clone https://github.com/Trusted-AI-Labs/APTITUDE_Toolbox/
Expand Down Expand Up @@ -118,8 +120,10 @@ The toolbox comes with two "client" scripts that can be used to produce an annot
| -fi |--frame_interval | Interval between two detections + tracking. | 1
| -gt |--ground_truth_path | Path to ground truth file in MOT format. It will be displayed in white. |
| -hl |--headless | Whether the video is shown while being processed. | False
| -ds |--display_size | Dimension of the video shown as it is processed: width,height. |
| -rp |--record_path | Path of the output video file. |
| -rf |--record_fps | FPS of the output video file. | 10
| -rs |--record_size | Dimension of the recorded video: width,height. Each image is resized just before being written. |
| -mp |--mot_path | Path to the result of tracking in MOT format.
| -a | --async | For video files only. Whether the video reading is asynchronous. | False

Expand Down Expand Up @@ -176,7 +180,9 @@ The APTITUDE toolbox comes from the APTITUDE project (**A**pprentissage **P**rof

Refer to the following repositories for more information on individual algorithms. Part of the code present in this repository was adapted from those repositories, see individual source files for details.

YOLO & Tiny-YOLO inference: [OpenCV Documentation - DNN module](https://docs.opencv.org/4.5.3/d0/db7/tutorial_js_table_of_contents_dnn.html)
YOLO & Tiny-YOLO (v2-4) inference: [OpenCV Documentation - DNN module](https://docs.opencv.org/4.5.3/d0/db7/tutorial_js_table_of_contents_dnn.html)

YOLOv5 inference: [Ultralytics - YOLOv5](https://github.com/ultralytics/yolov5)

SORT: [abewley - SORT](https://github.com/abewley/sort)

Expand Down
21 changes: 16 additions & 5 deletions clients/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
logging.getLogger("fvcore.common.checkpoint").setLevel(logging.WARNING) # Detectron2 logger
logging.getLogger("utils.general").setLevel(logging.WARNING) # yolov5 logger

def dims(s):
try:
w, h = map(int, s.split(','))
return w, h
except:
raise argparse.ArgumentTypeError("Dimensions must be expressed as widht,height without quotes or parantheses")

ap = argparse.ArgumentParser()
ap.add_argument("-d", "--detector", required=True,
help="path to detector config (json file)")
Expand All @@ -26,11 +33,15 @@
ap.add_argument("-gt", "--ground_truth_path", type=str, default=None,
help="path to ground truth file in MOT format.")
ap.add_argument("-hl", "--headless", action='store_true',
help="whether the video is shown as it processed")
help="whether the video is shown as it is processed")
ap.add_argument("-ds", "--display_size", type=dims, default=None,
help="dimension of the video shown as it is processed: width,height")
ap.add_argument("-rp", "--record_path", type=str, default=None,
help="path of the output video file")
ap.add_argument("-rf", "--record_fps", type=int, default=10,
help="fps of the output video file")
ap.add_argument("-rs", "--record_size", type=dims, default=None,
help="dimension of the recorded video: width,height. each image is resized just before being written")
ap.add_argument("-mp", "--mot_path", type=str, default=None,
help="path to the result of tracking in MOT format")
ap.add_argument("-a", "--async", action='store_true',
Expand All @@ -49,10 +60,10 @@

if os.path.isdir(args["path"]):
tci.main(args["detector"], args["tracker"], args["classes"],
args["path"], args["frame_interval"], args["record_path"], args["record_fps"],
args["mot_path"], args["headless"], args["ground_truth_path"],)
args["path"], args["frame_interval"], args["record_path"], args["record_fps"], args["record_size"],
args["mot_path"], args["headless"], args["display_size"], args["ground_truth_path"],)

else:
tcv.main(args["detector"], args["tracker"], args["classes"],
args["path"], args["frame_interval"], args["record_path"], args["record_fps"],
args["mot_path"], args["headless"], args["async"], args["ground_truth_path"])
args["path"], args["frame_interval"], args["record_path"], args["record_fps"], args["record_size"],
args["mot_path"], args["headless"], args["display_size"], args["async"], args["ground_truth_path"])
20 changes: 15 additions & 5 deletions clients/tracker_client_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
thickness = 2


def main(cfg_detect, cfg_track, cfg_classes, folder_path, frame_interval, record_path, record_fps,
mot_path, headless, gt_path):
def main(cfg_detect, cfg_track, cfg_classes, folder_path, frame_interval, record_path, record_fps, record_size,
mot_path, headless, display_size, gt_path):

log = logging.getLogger("aptitude-toolbox")

Expand Down Expand Up @@ -75,7 +75,9 @@ def main(cfg_detect, cfg_track, cfg_classes, folder_path, frame_interval, record
frame_test = ih.get_cv2_img_from_str(os.path.join(folder_path, file_list[0]))
H, W, _ = frame_test.shape
if record:
output_video = cv2.VideoWriter(record_path, cv2.VideoWriter_fourcc(*'mp4v'), record_fps, (W, H))
if record_size is None:
record_size = (H, W)
output_video = cv2.VideoWriter(record_path, cv2.VideoWriter_fourcc(*'mp4v'), record_fps, record_size)
log.debug("VideoWriter opened successfully.")

if gt_path is not None and not os.path.isdir(gt_path):
Expand Down Expand Up @@ -185,10 +187,18 @@ def main(cfg_detect, cfg_track, cfg_classes, folder_path, frame_interval, record
log.debug("Results bounding boxes added to the image.")

if not headless:
cv2.imshow("Result", frame)
frame_display = frame
if display_size is not None:
frame_display = cv2.resize(frame_display, display_size)
log.debug("Frame resized for display")
cv2.imshow("Result", frame_display)
log.debug("Frame displayed.")
if record:
output_video.write(frame)
frame_record = frame
if record_size is not None:
frame_record = cv2.resize(frame_record, record_size)
log.debug("Frame resized for record")
output_video.write(frame_record)
log.debug("Frame written to VideoWriter.")

counter += 1
Expand Down
21 changes: 15 additions & 6 deletions clients/tracker_client_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
thickness = 2


def main(cfg_detect, cfg_track, cfg_classes, video_path, frame_interval, record_path, record_fps,
mot_path, headless, async_flag, gt_path):
def main(cfg_detect, cfg_track, cfg_classes, video_path, frame_interval, record_path, record_fps, record_size,
mot_path, headless, display_size, async_flag, gt_path):

log = logging.getLogger("aptitude-toolbox")

Expand Down Expand Up @@ -84,7 +84,9 @@ def main(cfg_detect, cfg_track, cfg_classes, video_path, frame_interval, record_
record = record_path is not None
H, W, _ = frame.shape
if record:
output_video = cv2.VideoWriter(record_path, cv2.VideoWriter_fourcc(*'mp4v'), record_fps, (W, H))
if record_size is None:
record_size = (H, W)
output_video = cv2.VideoWriter(record_path, cv2.VideoWriter_fourcc(*'mp4v'), record_fps, record_size)
log.debug("VideoWriter opened successfully.")

start_time = default_timer()
Expand Down Expand Up @@ -169,12 +171,19 @@ def main(cfg_detect, cfg_track, cfg_classes, video_path, frame_interval, record_
log.debug("Results bounding boxes added to the image.")

if not headless:
cv2.imshow("Result", frame)
frame_display = frame
if display_size is not None:
frame_display = cv2.resize(frame_display, display_size)
log.debug("Frame resized for display")
cv2.imshow("Result", frame_display)
log.debug("Frame displayed.")
if record:
output_video.write(frame)
frame_record = frame
if record_size is not None:
frame_record = cv2.resize(frame_record, record_size)
log.debug("Frame resized for record")
output_video.write(frame_record)
log.debug("Frame written to VideoWriter.")

pbar.update(1)
counter += 1

Expand Down
2 changes: 0 additions & 2 deletions pytb/detection/bboxes/bboxes_2d_detector/README.md

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions pytb/detection/bboxes/bboxes_2d_detector/detectron2/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions pytb/detection/bboxes/bboxes_2d_detector/yolo/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions pytb/tracking/bboxes/bboxes_2d_tracker/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions pytb/tracking/bboxes/bboxes_2d_tracker/mbtracker/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion pytb/utils/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def pre_process(preprocess_parameters: dict, image: np.ndarray, prev_roi: np.ndarray = None,
detection: Detection = None) \
-> Tuple[np.ndarray, Union[np.ndarray, None]]:
-> Tuple[np.ndarray, Union[np.ndarray, None], Union[np.ndarray, None], Union[Detection, None]]:
if "roi" in preprocess_parameters:
roi = prev_roi
if prev_roi is None:
Expand Down

0 comments on commit cec542b

Please sign in to comment.