Manvikk commited on
Commit
bde4855
·
verified ·
1 Parent(s): 72a7eea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -14,16 +14,16 @@ app = Flask(__name__)
14
  app.secret_key = 'your_secret_key' # Replace with a secure secret key
15
 
16
  # Global dictionary to hold job progress and results
17
- jobs = {} # jobs[job_id] = {"progress": int, "result": {}}
18
 
19
  #########################################
20
  # 1. Initialize the Models
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)
@@ -146,16 +146,16 @@ def process_image(job_id, image_path, object_type, multiplier):
146
  jobs[job_id]['progress'] = 60
147
 
148
  # --- ArUco Marker Detection for Measurement ---
149
- # We assume the printed marker is 5cm x 5cm.
150
  marker_real_width_cm = 5.0
151
  try:
152
  # Use a fresh copy for marker detection.
153
  aruco_image = image.copy()
154
  gray = cv2.cvtColor(aruco_image, cv2.COLOR_BGR2GRAY)
155
- # Use the DICT_6X6_250 dictionary.
156
  aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
157
  aruco_params = cv2.aruco.DetectorParameters_create()
158
- # Adjust parameters to help detect small markers.
159
  aruco_params.adaptiveThreshWinSizeMin = 3
160
  aruco_params.adaptiveThreshWinSizeMax = 23
161
  aruco_params.adaptiveThreshWinSizeStep = 10
@@ -166,7 +166,7 @@ def process_image(job_id, image_path, object_type, multiplier):
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:
@@ -176,7 +176,6 @@ def process_image(job_id, image_path, object_type, multiplier):
176
  print("DEBUG: Marker with ID 42 not found among detected markers.")
177
  else:
178
  marker_corners = corners[selected_index].reshape((4, 2))
179
- # Draw only the selected marker
180
  cv2.aruco.drawDetectedMarkers(image, [corners[selected_index]], [ids[selected_index]])
181
  side_lengths = []
182
  for i in range(4):
@@ -580,4 +579,3 @@ def result():
580
 
581
  if __name__ == '__main__':
582
  app.run(host="0.0.0.0", port=7860, threaded=True)
583
-
 
14
  app.secret_key = 'your_secret_key' # Replace with a secure secret key
15
 
16
  # Global dictionary to hold job progress and results
17
+ jobs = {} # jobs[job_id] = {"progress": int, "result": {...}}
18
 
19
  #########################################
20
  # 1. Initialize the Models
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)
 
146
  jobs[job_id]['progress'] = 60
147
 
148
  # --- ArUco Marker Detection for Measurement ---
149
+ # We assume the printed marker is 5 cm x 5 cm.
150
  marker_real_width_cm = 5.0
151
  try:
152
  # Use a fresh copy for marker detection.
153
  aruco_image = image.copy()
154
  gray = cv2.cvtColor(aruco_image, cv2.COLOR_BGR2GRAY)
155
+ # Use DICT_6X6_250; your printed marker should be generated with this dictionary.
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
 
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:
 
176
  print("DEBUG: Marker with ID 42 not found among detected markers.")
177
  else:
178
  marker_corners = corners[selected_index].reshape((4, 2))
 
179
  cv2.aruco.drawDetectedMarkers(image, [corners[selected_index]], [ids[selected_index]])
180
  side_lengths = []
181
  for i in range(4):
 
579
 
580
  if __name__ == '__main__':
581
  app.run(host="0.0.0.0", port=7860, threaded=True)