Skip to content

Commit

Permalink
add changes from black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
sjay05 committed Mar 24, 2024
1 parent 3995ef3 commit 4debc8a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 13 additions & 4 deletions blue_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@
CONTOUR_MINIMUM = 0.8

parser = argparse.ArgumentParser(description="AEAC 2024 Auto-landing script")
parser.add_argument("--method", help="Method for selecting landing pads", choices=['contour', 'yolo'], default="contour")
parser.add_argument(
"--method",
help="Method for selecting landing pads",
choices=["contour", "yolo"],
default="contour",
)
args = parser.parse_args()


def current_milli_time() -> int:
"""
Returns the current time in milliseconds.
Expand Down Expand Up @@ -132,7 +138,7 @@ def main() -> int:
last_time = current_milli_time()
last_image_time = current_milli_time()

if args.method == 'yolo':
if args.method == "yolo":
yolo_model = yolo_decision.DetectLandingPad("cpu", 0.5, "models/best-2n.pt")

while True:
Expand Down Expand Up @@ -161,13 +167,15 @@ def main() -> int:
found_coordindates = False
x, y, w, h = 0, 0, 0, 0

if args.method == 'contour':
if args.method == "contour":
# Finding contours in original image
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
threshold = 180
im_bw = cv2.threshold(gray_image, threshold, 255, cv2.THRESH_BINARY)[1]
im_dilation = cv2.dilate(im_bw, kernel, iterations=1)
contours, hierarchy = cv2.findContours(im_dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours, hierarchy = cv2.findContours(
im_dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE
)
if len(contours) == 0:
continue

Expand Down Expand Up @@ -241,6 +249,7 @@ def main() -> int:

return 0


if __name__ == "__main__":
result_main = main()
if result_main < 0:
Expand Down
5 changes: 3 additions & 2 deletions yolo_decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ultralytics
import numpy as np


class Detection:
"""
A detected object in image space.
Expand Down Expand Up @@ -57,9 +58,10 @@ def __str__(self) -> str:
"""
return f"cls: {self.label}, conf: {self.confidence}, bounds: {self.x_1} {self.y_1} {self.x_2} {self.y_2}"


class DetectLandingPad:
"""
Contains 2023 YOLOv8 model for prediction.
Contains 2023 YOLOv8 model for prediction.
"""

def __init__(self, device: "str | int", conf: int, model_path: str) -> None:
Expand Down Expand Up @@ -115,4 +117,3 @@ def find_best_pad(self, detections: list[Detection]) -> "Detection | None":

best_landing_pad = min(detections, key=lambda pad: pad.confidence)
return best_landing_pad

0 comments on commit 4debc8a

Please sign in to comment.