Update app.py
Browse files
app.py
CHANGED
|
@@ -198,7 +198,14 @@ def predict_and_crop(image_np, api_key, project_name, model_version, confidence=
|
|
| 198 |
img = Image.fromarray(image_np)
|
| 199 |
rf = Roboflow(api_key=api_key)
|
| 200 |
project = rf.workspace().project(project_name)
|
|
|
|
|
|
|
| 201 |
model = project.version(model_version).model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
corners = model.predict(image_np, confidence=confidence, overlap=overlap).json()
|
| 203 |
predictions = corners["predictions"][0]
|
| 204 |
prediction = {key: int(value) for key, value in predictions.items() if key in ['x', 'y', 'width', 'height']}
|
|
@@ -211,7 +218,8 @@ def predict_and_crop(image_np, api_key, project_name, model_version, confidence=
|
|
| 211 |
h, w, c = cropped_img_np.shape
|
| 212 |
if h > w:
|
| 213 |
cropped_img_np = cv2.rotate(cropped_img_np, cv2.ROTATE_90_CLOCKWISE)
|
| 214 |
-
return cropped_img_np, img
|
|
|
|
| 215 |
|
| 216 |
# Function to resize and insert cropped image
|
| 217 |
def resize_and_insert(cropped_image, output_image_path):
|
|
|
|
| 198 |
img = Image.fromarray(image_np)
|
| 199 |
rf = Roboflow(api_key=api_key)
|
| 200 |
project = rf.workspace().project(project_name)
|
| 201 |
+
print(f"Project: {project}")
|
| 202 |
+
|
| 203 |
model = project.version(model_version).model
|
| 204 |
+
print(f"Model: {model}")
|
| 205 |
+
|
| 206 |
+
if model is None:
|
| 207 |
+
raise ValueError(f"Model version {model_version} not found in project {project_name}.")
|
| 208 |
+
|
| 209 |
corners = model.predict(image_np, confidence=confidence, overlap=overlap).json()
|
| 210 |
predictions = corners["predictions"][0]
|
| 211 |
prediction = {key: int(value) for key, value in predictions.items() if key in ['x', 'y', 'width', 'height']}
|
|
|
|
| 218 |
h, w, c = cropped_img_np.shape
|
| 219 |
if h > w:
|
| 220 |
cropped_img_np = cv2.rotate(cropped_img_np, cv2.ROTATE_90_CLOCKWISE)
|
| 221 |
+
return cropped_img_np, img
|
| 222 |
+
|
| 223 |
|
| 224 |
# Function to resize and insert cropped image
|
| 225 |
def resize_and_insert(cropped_image, output_image_path):
|