File size: 1,121 Bytes
44f0770
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe70c63
44f0770
fe70c63
44f0770
 
 
fe70c63
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import streamlit as st
import cv2
import numpy as np  
from ultralytics import YOLO
from PIL import Image
import tempfile

# Directly set the path for the model
MODEL_PATH = 'best.pt'

# Initialize YOLO model with custom trained weights
model = YOLO(MODEL_PATH)

def detect_rhino_image(image):
    image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
    results = model(image)[0]
    for box in results.boxes.data.tolist():
        x1, y1, x2, y2, score, class_id = box
        if score > 0.5:
            cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 4)
            cv2.putText(image, results.names[int(class_id)].upper(), (int(x1), int(y1 - 10)), cv2.FONT_HERSHEY_SIMPLEX, 1.3, (0, 255, 0), 3, cv2.LINE_AA)
    return image

st.title('Rhinoceros Detection App')

st.write("Upload an image for rhino detection.")

file = st.file_uploader("Choose a file...", type=["jpg", "jpeg", "png"])
if file is not None:
    if file.type.split('/')[0] == 'image':
        image = Image.open(file)
        st.image(detect_rhino_image(image), caption='Processed Image', use_column_width=True)