|
|
import streamlit as st |
|
|
import cv2 |
|
|
from PIL import Image |
|
|
import time |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
def analyze_image(image): |
|
|
|
|
|
|
|
|
|
|
|
return ["chair on the left", "table in the center", "cat on the right"] |
|
|
|
|
|
def main(): |
|
|
st.title("Object Recognition Assistant for the Visually Impaired") |
|
|
|
|
|
|
|
|
cap = cv2.VideoCapture(0) |
|
|
|
|
|
FRAME_WINDOW = st.image([]) |
|
|
last_time = time.time() |
|
|
|
|
|
while True: |
|
|
ret, frame = cap.read() |
|
|
if not ret: |
|
|
continue |
|
|
|
|
|
|
|
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
|
|
img = Image.fromarray(frame) |
|
|
|
|
|
|
|
|
FRAME_WINDOW.image(img) |
|
|
|
|
|
|
|
|
if time.time() - last_time > 10: |
|
|
last_time = time.time() |
|
|
|
|
|
|
|
|
descriptions = analyze_image(img) |
|
|
|
|
|
|
|
|
st.write("Detected objects:") |
|
|
for desc in descriptions: |
|
|
st.write("- " + desc) |
|
|
|
|
|
time.sleep(0.1) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|