Format
This commit is contained in:
parent
000692a7af
commit
556a90da3c
|
@ -57,3 +57,7 @@ ipykernel = "^6.25.2"
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
# More than the default (88) of `black` to make comments less of a headache
|
||||||
|
line-length = 120
|
||||||
|
|
|
@ -50,11 +50,13 @@ def main():
|
||||||
help="The scale to run the detection at, default is 0.25",
|
help="The scale to run the detection at, default is 0.25",
|
||||||
)
|
)
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
'--view-scale',
|
"--view-scale",
|
||||||
# Set it to the env VIEW_SCALE if it isn't blank, otherwise set it to 0.75
|
# Set it to the env VIEW_SCALE if it isn't blank, otherwise set it to 0.75
|
||||||
default=os.environ['VIEW_SCALE'] if 'VIEW_SCALE' in os.environ and os.environ['VIEW_SCALE'] != '' else 0.75, # noqa: E501
|
default=os.environ["VIEW_SCALE"]
|
||||||
type=float,
|
if "VIEW_SCALE" in os.environ and os.environ["VIEW_SCALE"] != ""
|
||||||
help="The scale to view the detection at, default is 0.75",
|
else 0.75, # noqa: E501
|
||||||
|
type=float,
|
||||||
|
help="The scale to view the detection at, default is 0.75",
|
||||||
)
|
)
|
||||||
|
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
|
@ -188,7 +190,9 @@ def main():
|
||||||
# If it isn't, print a warning
|
# If it isn't, print a warning
|
||||||
for obj in args.detect_object:
|
for obj in args.detect_object:
|
||||||
if obj not in object_names:
|
if obj not in object_names:
|
||||||
print(f"Warning: {obj} is not in the list of objects the model can detect!")
|
print(
|
||||||
|
f"Warning: {obj} is not in the list of objects the model can detect!"
|
||||||
|
)
|
||||||
|
|
||||||
for box in r.boxes:
|
for box in r.boxes:
|
||||||
# Get the name of the object
|
# Get the name of the object
|
||||||
|
@ -205,13 +209,14 @@ def main():
|
||||||
# print("---")
|
# print("---")
|
||||||
|
|
||||||
# Now do stuff (if conf > 0.5)
|
# Now do stuff (if conf > 0.5)
|
||||||
if conf < args.confidence_threshold or (class_id not in args.detect_object and args.detect_object != []):
|
if conf < args.confidence_threshold or (
|
||||||
|
class_id not in args.detect_object and args.detect_object != []
|
||||||
|
):
|
||||||
# If the confidence is too low
|
# If the confidence is too low
|
||||||
# or if the object is not in the list of objects to detect and the list of objects to detect is not empty
|
# or if the object is not in the list of objects to detect and the list of objects to detect is not empty
|
||||||
# then skip this iteration
|
# then skip this iteration
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
# Add the object to the list of objects to plot
|
# Add the object to the list of objects to plot
|
||||||
plot_boxes.append(
|
plot_boxes.append(
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
def plot_label(
|
def plot_label(
|
||||||
# list of dicts with each dict containing a label, x1, y1, x2, y2
|
# list of dicts with each dict containing a label, x1, y1, x2, y2
|
||||||
boxes: list = None,
|
boxes: list = None,
|
||||||
# opencv image
|
# opencv image
|
||||||
full_frame: np.ndarray = None,
|
full_frame: np.ndarray = None,
|
||||||
# run_scale is the scale of the image that was used to run the model
|
# run_scale is the scale of the image that was used to run the model
|
||||||
# So the coordinates will be scaled up to the view frame size
|
# So the coordinates will be scaled up to the view frame size
|
||||||
run_scale: float = None,
|
run_scale: float = None,
|
||||||
# view_scale is the scale of the image, in relation to the full frame
|
# view_scale is the scale of the image, in relation to the full frame
|
||||||
# So the coordinates will be scaled appropriately when coming from run_frame
|
# So the coordinates will be scaled appropriately when coming from run_frame
|
||||||
view_scale: float = None,
|
view_scale: float = None,
|
||||||
font: int = cv2.FONT_HERSHEY_SIMPLEX,
|
font: int = cv2.FONT_HERSHEY_SIMPLEX,
|
||||||
):
|
):
|
||||||
view_frame = cv2.resize(full_frame, (0, 0), fx=view_scale, fy=view_scale)
|
view_frame = cv2.resize(full_frame, (0, 0), fx=view_scale, fy=view_scale)
|
||||||
for thing in boxes:
|
for thing in boxes:
|
||||||
|
@ -19,9 +21,15 @@ def plot_label(
|
||||||
# Image
|
# Image
|
||||||
view_frame,
|
view_frame,
|
||||||
# Start point
|
# Start point
|
||||||
(int(thing["x1"] * (run_scale/view_scale)), int(thing["y1"] * (run_scale/view_scale))),
|
(
|
||||||
|
int(thing["x1"] * (run_scale / view_scale)),
|
||||||
|
int(thing["y1"] * (run_scale / view_scale)),
|
||||||
|
),
|
||||||
# End point
|
# End point
|
||||||
(int(thing["x2"] * (run_scale/view_scale)), int(thing["y2"] * (run_scale/view_scale))),
|
(
|
||||||
|
int(thing["x2"] * (run_scale / view_scale)),
|
||||||
|
int(thing["y2"] * (run_scale / view_scale)),
|
||||||
|
),
|
||||||
# Color
|
# Color
|
||||||
(0, 255, 0),
|
(0, 255, 0),
|
||||||
# Thickness
|
# Thickness
|
||||||
|
@ -33,7 +41,10 @@ def plot_label(
|
||||||
# Text
|
# Text
|
||||||
thing["label"],
|
thing["label"],
|
||||||
# Origin
|
# Origin
|
||||||
(int(thing["x1"] * (run_scale/view_scale)), int(thing["y1"] * (run_scale/view_scale))),
|
(
|
||||||
|
int(thing["x1"] * (run_scale / view_scale)),
|
||||||
|
int(thing["y1"] * (run_scale / view_scale)),
|
||||||
|
),
|
||||||
# Font
|
# Font
|
||||||
font,
|
font,
|
||||||
# Font Scale
|
# Font Scale
|
||||||
|
@ -41,6 +52,6 @@ def plot_label(
|
||||||
# Color
|
# Color
|
||||||
(0, 255, 0),
|
(0, 255, 0),
|
||||||
# Thickness
|
# Thickness
|
||||||
1
|
1,
|
||||||
)
|
)
|
||||||
return view_frame
|
return view_frame
|
Loading…
Reference in New Issue