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

Only stretch image to resize if format is Stretch #352

Merged
merged 7 commits into from
Jan 17, 2025
Merged
Changes from 4 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
8 changes: 6 additions & 2 deletions roboflow/models/object_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,18 @@ def predict( # type: ignore[override]
import cv2
import numpy as np

should_resize = (
"resize" in self.preprocessing.keys() and "Stretch" in self.preprocessing["resize"]["format"]
)

if isinstance(image_path, str):
image = Image.open(image_path).convert("RGB")
dimensions = image.size
original_dimensions = copy.deepcopy(dimensions)

# Here we resize the image to the preprocessing settings
# before sending it over the wire
if "resize" in self.preprocessing.keys():
if should_resize:
if dimensions[0] > int(self.preprocessing["resize"]["width"]) or dimensions[1] > int(
self.preprocessing["resize"]["height"]
):
Expand Down Expand Up @@ -245,7 +249,7 @@ def predict( # type: ignore[override]
if self.format == "json":
resp_json = resp.json()

if resize and original_dimensions is not None:
if should_resize and original_dimensions is not None:
new_preds = []
for p in resp_json["predictions"]:
p["x"] = int(p["x"] * (int(original_dimensions[0]) / int(self.preprocessing["resize"]["width"])))
Expand Down
Loading