Name - : 'Templates'
Name - : 'Templates'
Name - : 'Templates'
import cv2
import numpy as np
import joblib
import os
import mahotas
def bgr_hsv(rgb_img):
hsv_img = cv2.cvtColor(rgb_img, cv2.COLOR_RGB2HSV)
return hsv_img
return final_result
def fd_hu_moments(image):
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
feature = cv2.HuMoments(cv2.moments(image)).flatten()
return feature
def fd_haralick(image):
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
haralick = mahotas.features.haralick(gray).mean(axis=0)
return haralick
def extract_features(image):
# Preprocess the image
preprocessed_image = preprocess_image(image)
# Extract features
fd_hu_moments_features = fd_hu_moments(segmented_image)
fd_haralick_features = fd_haralick(segmented_image)
fd_histogram_features = fd_histogram(segmented_image)
return feature_vector
def format_predictions(predictions):
# Modify this function according to your model's output format
# For example, convert class IDs to class names and probabilities
# You can also limit the number of predictions or perform post-processing
return "Diseased" if predictions == 0 else "Healthy"
@app.route('/')
def index():
model_info = "Used Model: Random Forest"
return render_template('index.html', model_info=model_info)
@app.route('/predict', methods=['POST'])
def predict():
if 'file' not in request.files:
return jsonify({'error': 'No file uploaded'})
file = request.files['file']
if file.filename == '':
return jsonify({'error': 'No file selected'})
try:
# Read the uploaded image
img = cv2.imdecode(np.frombuffer(file.read(), np.uint8), cv2.IMREAD_COLOR)
if img is None:
return jsonify({'error': 'Unable to read the uploaded image'})
except Exception as e:
return jsonify({'error': str(e)})
if __name__ == '__main__':
app.run(debug=True)