Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imx500_object_detection_demo - bbox-order #1149

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/imx500/imx500_object_detection_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def parse_detections(metadata: dict):
"""Parse the output tensor into a number of detected objects, scaled to the ISP out."""
global last_detections
bbox_normalization = intrinsics.bbox_normalization
bbox_order = intrinsics.bbox_order
threshold = args.threshold
iou = args.iou
max_detections = args.max_detections
Expand All @@ -44,6 +45,8 @@ def parse_detections(metadata: dict):
if bbox_normalization:
boxes = boxes / input_h

if bbox_order == "xy":
boxes = boxes[:, [1, 0, 3, 2]]
boxes = np.array_split(boxes, 4, axis=1)
boxes = zip(*boxes)

Expand Down Expand Up @@ -113,6 +116,8 @@ def get_args():
default="/usr/share/imx500-models/imx500_network_ssd_mobilenetv2_fpnlite_320x320_pp.rpk")
parser.add_argument("--fps", type=int, help="Frames per second")
parser.add_argument("--bbox-normalization", action=argparse.BooleanOptionalAction, help="Normalize bbox")
parser.add_argument("--bbox-order", choices=["yx", "xy"], default="yx",
help="Set bbox order yx -> (y0, x0, y1, x1) xy -> (x0, y0, x1, y1)")
parser.add_argument("--threshold", type=float, default=0.55, help="Detection threshold")
parser.add_argument("--iou", type=float, default=0.65, help="Set iou threshold")
parser.add_argument("--max-detections", type=int, default=10, help="Set max detections")
Expand Down
13 changes: 13 additions & 0 deletions picamera2/devices/imx500/imx500.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, val=None):
"type": "object",
"properties": {
"bbox_normalization": {"type": "boolean"},
"bbox_order": {"type": "string", "enum": ["xy", "yx"]},
"softmax": {"type": "boolean"},
"post_processing": {"type": "string"},
},
Expand Down Expand Up @@ -181,6 +182,18 @@ def bbox_normalization(self, val: Optional[bool]):
if self.__intrinsics_has_key('cpu') and len(self.__intrinsics['cpu']) == 0:
self.__intrinsics.pop('cpu')

@property
def bbox_order(self) -> Optional[str]:
return self.__get_cpu('bbox_order')

@bbox_order.setter
def bbox_order(self, val: str):
if val not in ["xy", "yx"]:
raise ValueError("bbox_order must be either 'xy' or 'yx'")
self.__set_cpu({'bbox_order': val})
if self.__intrinsics_has_key('cpu') and len(self.__intrinsics['cpu']) == 0:
self.__intrinsics.pop('cpu')

@property
def softmax(self) -> Optional[bool]:
return self.__get_cpu('softmax')
Expand Down
Loading