megustaSzy commited on
Commit
9f2b822
·
verified ·
1 Parent(s): 289aeb2

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -4
main.py CHANGED
@@ -124,8 +124,9 @@ def preprocess_image(img, target_size=(240,240)):
124
  s = 800/max(h0,w0); img = cv2.resize(img,(int(w0*s),int(h0*s)))
125
  rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
126
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
 
127
  h, w = gray.shape
128
- circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 100,
129
  param1=50, param2=30,
130
  minRadius=int(h*0.1), maxRadius=int(h*0.5))
131
  if circles is not None:
@@ -177,10 +178,10 @@ def predict(file: UploadFile = File(..., description="File gambar mata (retina/k
177
  if img is None:
178
  raise HTTPException(400, "File tidak dapat dibaca sebagai gambar.")
179
 
180
- # -- Mencegah RAM Lagging jika foto beresolusi terlampau raksasa --
181
  h_init, w_init = img.shape[:2]
182
- if max(h_init, w_init) > 1200:
183
- scale = 1200 / max(h_init, w_init)
184
  img = cv2.resize(img, (int(w_init * scale), int(h_init * scale)))
185
 
186
  # -- OOD Check -------------------------------------------------------
 
124
  s = 800/max(h0,w0); img = cv2.resize(img,(int(w0*s),int(h0*s)))
125
  rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
126
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
127
+ gray_bl = cv2.GaussianBlur(gray, (7, 7), 0)
128
  h, w = gray.shape
129
+ circles = cv2.HoughCircles(gray_bl, cv2.HOUGH_GRADIENT, 1.2, 100,
130
  param1=50, param2=30,
131
  minRadius=int(h*0.1), maxRadius=int(h*0.5))
132
  if circles is not None:
 
178
  if img is None:
179
  raise HTTPException(400, "File tidak dapat dibaca sebagai gambar.")
180
 
181
+ # -- Mencegah RAM Lagging dan Timeout dari HoughCircles --
182
  h_init, w_init = img.shape[:2]
183
+ if max(h_init, w_init) > 800:
184
+ scale = 800 / max(h_init, w_init)
185
  img = cv2.resize(img, (int(w_init * scale), int(h_init * scale)))
186
 
187
  # -- OOD Check -------------------------------------------------------