Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
|
4 |
+
# Load the pre-trained object detection model
|
5 |
+
model = cv2.CascadeClassifier('path/to/haarcascade.xml')
|
6 |
+
|
7 |
+
# Function to perform object recognition
|
8 |
+
def detect_objects(image):
|
9 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
10 |
+
objects = model.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5)
|
11 |
+
for (x, y, w, h) in objects:
|
12 |
+
cv2.rectangle(image, (x, y), (x + w, y + h), (255, 0, 0), 2)
|
13 |
+
return image
|
14 |
+
|
15 |
+
# Streamlit app
|
16 |
+
st.title('Object Recognition')
|
17 |
+
uploaded_file = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png'])
|
18 |
+
|
19 |
+
if uploaded_file is not None:
|
20 |
+
# Read the uploaded image
|
21 |
+
image = cv2.imdecode(np.fromstring(uploaded_file.read(), np.uint8), 1)
|
22 |
+
|
23 |
+
# Perform object recognition
|
24 |
+
result = detect_objects(image)
|
25 |
+
|
26 |
+
# Display the result
|
27 |
+
st.image(result, channels='BGR')
|