Update app.py
Browse files
app.py
CHANGED
@@ -52,19 +52,26 @@ project = rf.workspace().project("sku-110k")
|
|
52 |
model = project.version(2).model
|
53 |
|
54 |
|
55 |
-
def
|
56 |
if isinstance(image, np.ndarray):
|
57 |
image = Image.fromarray(image)
|
|
|
|
|
|
|
|
|
58 |
buffered = io.BytesIO()
|
59 |
-
image.save(buffered, format="
|
60 |
-
return
|
|
|
|
|
|
|
|
|
61 |
|
62 |
def roboflow(image, confidence, overlap, stroke_width=1, labels=False):
|
63 |
'''
|
64 |
Send the image to Roboflow API for inference.
|
65 |
Returns JSON and image with bounding boxes drawn on to it.
|
66 |
'''
|
67 |
-
|
68 |
json_url = f"https://detect.roboflow.com/sku-110k/2?api_key=gHiUgOSq9GqTnRy5mErk&confidence={confidence}&overlap={overlap}&format=json"
|
69 |
image_url = f"https://detect.roboflow.com/sku-110k/2?api_key=gHiUgOSq9GqTnRy5mErk&confidence={confidence}&overlap={overlap}&format=image&labels={str(labels).lower()}&stroke={stroke_width}"
|
70 |
|
@@ -93,6 +100,7 @@ def roboflow(image, confidence, overlap, stroke_width=1, labels=False):
|
|
93 |
}
|
94 |
|
95 |
|
|
|
96 |
# Image Splitting and Merging Functionality
|
97 |
def split_image(image, tile_size=640, overlap=160):
|
98 |
img_width, img_height = image.size
|
|
|
52 |
model = project.version(2).model
|
53 |
|
54 |
|
55 |
+
def resize_image(image, max_size=1500):
|
56 |
if isinstance(image, np.ndarray):
|
57 |
image = Image.fromarray(image)
|
58 |
+
if max(image.size) > max_size:
|
59 |
+
ratio = max_size / float(max(image.size))
|
60 |
+
new_size = tuple([int(x * ratio) for x in image.size])
|
61 |
+
image = image.resize(new_size, Image.LANCZOS)
|
62 |
buffered = io.BytesIO()
|
63 |
+
image.save(buffered, format="JPEG")
|
64 |
+
return buffered.getvalue()
|
65 |
+
|
66 |
+
def encode_image(image):
|
67 |
+
image_data = resize_image(image)
|
68 |
+
return base64.b64encode(image_data).decode("utf-8")
|
69 |
|
70 |
def roboflow(image, confidence, overlap, stroke_width=1, labels=False):
|
71 |
'''
|
72 |
Send the image to Roboflow API for inference.
|
73 |
Returns JSON and image with bounding boxes drawn on to it.
|
74 |
'''
|
|
|
75 |
json_url = f"https://detect.roboflow.com/sku-110k/2?api_key=gHiUgOSq9GqTnRy5mErk&confidence={confidence}&overlap={overlap}&format=json"
|
76 |
image_url = f"https://detect.roboflow.com/sku-110k/2?api_key=gHiUgOSq9GqTnRy5mErk&confidence={confidence}&overlap={overlap}&format=image&labels={str(labels).lower()}&stroke={stroke_width}"
|
77 |
|
|
|
100 |
}
|
101 |
|
102 |
|
103 |
+
|
104 |
# Image Splitting and Merging Functionality
|
105 |
def split_image(image, tile_size=640, overlap=160):
|
106 |
img_width, img_height = image.size
|