Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
livindra 2026-05-05 05:34:24 +07:00
parent a8afe46c90
commit 5c56ed9426
1 changed files with 12 additions and 0 deletions

12
app.py
View File

@ -30,6 +30,8 @@ UPLOAD_FOLDER = os.path.join(BASE_DIR, 'uploads')
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
UPLOAD_RESIZE_FOLDER = os.path.join(UPLOAD_FOLDER, 'resize')
os.makedirs(UPLOAD_RESIZE_FOLDER, exist_ok=True)
UPLOAD_THRESHOLD_FOLDER = os.path.join(UPLOAD_FOLDER, 'threshold')
os.makedirs(UPLOAD_THRESHOLD_FOLDER, exist_ok=True)
# Inisialisasi sistem pakar dan knowledge base
expert_system = ForwardChaining()
@ -428,12 +430,20 @@ def predict():
resized_filename = filename
resized_filepath = os.path.join(UPLOAD_RESIZE_FOLDER, resized_filename)
threshold_filename = filename
threshold_filepath = os.path.join(UPLOAD_THRESHOLD_FOLDER, threshold_filename)
try:
cv2.imwrite(resized_filepath, img_resized)
print(f"[PREDICT] ✓ Resized image saved: {resized_filepath}")
except Exception as save_err:
print(f"[PREDICT] ⚠️ Gagal menyimpan resized image: {save_err}")
resized_filepath = None
try:
cv2.imwrite(threshold_filepath, gray_processed)
print(f"[PREDICT] ✓ Threshold image saved: {threshold_filepath}")
except Exception as save_err:
print(f"[PREDICT] ⚠️ Gagal menyimpan threshold image: {save_err}")
threshold_filepath = None
features = extractor.extract_all_features(img_rgb, gray_processed)
features_scaled = scaler.transform([features])
@ -528,6 +538,8 @@ def predict():
'filepath': filepath,
'resized_filename': resized_filename if resized_filepath else None,
'resized_filepath': resized_filepath,
'threshold_filename': threshold_filename if threshold_filepath else None,
'threshold_filepath': threshold_filepath,
'source': 'image_processing',
'db_id': existing_db_id
}