parent
ca7879d36c
commit
0a47ffd19d
15
app.py
15
app.py
|
|
@ -2,6 +2,7 @@ from flask import Flask, render_template, request, redirect, url_for, send_from_
|
||||||
import io
|
import io
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import cv2
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import uuid
|
import uuid
|
||||||
|
|
@ -27,6 +28,8 @@ app = Flask(__name__,
|
||||||
app.secret_key = os.environ.get('FLASK_SECRET', 'change-me')
|
app.secret_key = os.environ.get('FLASK_SECRET', 'change-me')
|
||||||
UPLOAD_FOLDER = os.path.join(BASE_DIR, 'uploads')
|
UPLOAD_FOLDER = os.path.join(BASE_DIR, 'uploads')
|
||||||
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
||||||
|
UPLOAD_RESIZE_FOLDER = os.path.join(UPLOAD_FOLDER, 'resize')
|
||||||
|
os.makedirs(UPLOAD_RESIZE_FOLDER, exist_ok=True)
|
||||||
|
|
||||||
# Inisialisasi sistem pakar dan knowledge base
|
# Inisialisasi sistem pakar dan knowledge base
|
||||||
expert_system = ForwardChaining()
|
expert_system = ForwardChaining()
|
||||||
|
|
@ -421,6 +424,16 @@ def predict():
|
||||||
|
|
||||||
# Preprocess and extract
|
# Preprocess and extract
|
||||||
img_rgb, gray_processed = preprocess_pipeline(filepath)
|
img_rgb, gray_processed = preprocess_pipeline(filepath)
|
||||||
|
_, img_resized, _ = preprocess_image(filepath)
|
||||||
|
|
||||||
|
resized_filename = filename
|
||||||
|
resized_filepath = os.path.join(UPLOAD_RESIZE_FOLDER, resized_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
|
||||||
features = extractor.extract_all_features(img_rgb, gray_processed)
|
features = extractor.extract_all_features(img_rgb, gray_processed)
|
||||||
features_scaled = scaler.transform([features])
|
features_scaled = scaler.transform([features])
|
||||||
|
|
||||||
|
|
@ -513,6 +526,8 @@ def predict():
|
||||||
'confidence': confidence,
|
'confidence': confidence,
|
||||||
'features_table': features_table,
|
'features_table': features_table,
|
||||||
'filepath': filepath,
|
'filepath': filepath,
|
||||||
|
'resized_filename': resized_filename if resized_filepath else None,
|
||||||
|
'resized_filepath': resized_filepath,
|
||||||
'source': 'image_processing',
|
'source': 'image_processing',
|
||||||
'db_id': existing_db_id
|
'db_id': existing_db_id
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ def validate_cattle_image(image_path, confidence_threshold=0.75):
|
||||||
|
|
||||||
def preprocess_image(
|
def preprocess_image(
|
||||||
image_path,
|
image_path,
|
||||||
target_size=(256, 256),
|
target_size=(128, 128),
|
||||||
apply_threshold=False,
|
apply_threshold=False,
|
||||||
thresh_method='otsu',
|
thresh_method='otsu',
|
||||||
thresh_val=127,
|
thresh_val=127,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue