Update app.py
Browse files
app.py
CHANGED
|
@@ -21,9 +21,9 @@ jobs = {} # jobs[job_id] = {"progress": int, "result": {...}}
|
|
| 21 |
#########################################
|
| 22 |
|
| 23 |
# --- Roboflow Box Detection Model ---
|
| 24 |
-
API_KEY = "wLjPoPYaLmrqCIOFA0RH"
|
| 25 |
PROJECT_ID = "base-model-box-r4suo-8lkk1-6dbqh" # Your Roboflow project ID
|
| 26 |
-
VERSION_NUMBER = "2"
|
| 27 |
|
| 28 |
try:
|
| 29 |
rf = roboflow.Roboflow(api_key=API_KEY)
|
|
@@ -152,21 +152,24 @@ def process_image(job_id, image_path, object_type, multiplier):
|
|
| 152 |
# Use a fresh copy for marker detection.
|
| 153 |
aruco_image = image.copy()
|
| 154 |
gray = cv2.cvtColor(aruco_image, cv2.COLOR_BGR2GRAY)
|
| 155 |
-
#
|
|
|
|
|
|
|
| 156 |
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
|
| 157 |
aruco_params = cv2.aruco.DetectorParameters_create()
|
| 158 |
# Tweak parameters for small markers.
|
| 159 |
aruco_params.adaptiveThreshWinSizeMin = 3
|
| 160 |
aruco_params.adaptiveThreshWinSizeMax = 23
|
| 161 |
aruco_params.adaptiveThreshWinSizeStep = 10
|
| 162 |
-
|
|
|
|
| 163 |
aruco_params.cornerRefinementMethod = cv2.aruco.CORNER_REFINE_SUBPIX
|
| 164 |
|
| 165 |
corners, ids, rejected = cv2.aruco.detectMarkers(gray, aruco_dict, parameters=aruco_params)
|
| 166 |
print("DEBUG: Detected candidate IDs:", ids)
|
| 167 |
conversion_factor = None
|
| 168 |
if ids is not None and len(ids) > 0:
|
| 169 |
-
# Look for marker with ID 42
|
| 170 |
selected_index = None
|
| 171 |
for i, marker_id in enumerate(ids):
|
| 172 |
if marker_id[0] == 42:
|
|
|
|
| 21 |
#########################################
|
| 22 |
|
| 23 |
# --- Roboflow Box Detection Model ---
|
| 24 |
+
API_KEY = "wLjPoPYaLmrqCIOFA0RH" # Your Roboflow API key
|
| 25 |
PROJECT_ID = "base-model-box-r4suo-8lkk1-6dbqh" # Your Roboflow project ID
|
| 26 |
+
VERSION_NUMBER = "2" # Your trained model version number
|
| 27 |
|
| 28 |
try:
|
| 29 |
rf = roboflow.Roboflow(api_key=API_KEY)
|
|
|
|
| 152 |
# Use a fresh copy for marker detection.
|
| 153 |
aruco_image = image.copy()
|
| 154 |
gray = cv2.cvtColor(aruco_image, cv2.COLOR_BGR2GRAY)
|
| 155 |
+
# Increase contrast using histogram equalization.
|
| 156 |
+
gray = cv2.equalizeHist(gray)
|
| 157 |
+
# Use DICT_6X6_250; ensure your printed marker is generated with this dictionary and has ID 42.
|
| 158 |
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
|
| 159 |
aruco_params = cv2.aruco.DetectorParameters_create()
|
| 160 |
# Tweak parameters for small markers.
|
| 161 |
aruco_params.adaptiveThreshWinSizeMin = 3
|
| 162 |
aruco_params.adaptiveThreshWinSizeMax = 23
|
| 163 |
aruco_params.adaptiveThreshWinSizeStep = 10
|
| 164 |
+
# Lower the minimum marker perimeter rate to help detect small markers.
|
| 165 |
+
aruco_params.minMarkerPerimeterRate = 0.02
|
| 166 |
aruco_params.cornerRefinementMethod = cv2.aruco.CORNER_REFINE_SUBPIX
|
| 167 |
|
| 168 |
corners, ids, rejected = cv2.aruco.detectMarkers(gray, aruco_dict, parameters=aruco_params)
|
| 169 |
print("DEBUG: Detected candidate IDs:", ids)
|
| 170 |
conversion_factor = None
|
| 171 |
if ids is not None and len(ids) > 0:
|
| 172 |
+
# Look for marker with ID 42.
|
| 173 |
selected_index = None
|
| 174 |
for i, marker_id in enumerate(ids):
|
| 175 |
if marker_id[0] == 42:
|