Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
from langchain_core.prompts import PromptTemplate
from langchain_core.messages import HumanMessage


from tts_utils import speak
from config import TTS_ENGINE, IP_WEBCAM_URL

from ocr_utils import extract_text_from_image

# Load Gemini API key from .env
load_dotenv()
api_key = os.getenv("API_KEY")
Expand Down Expand Up @@ -145,10 +146,18 @@ def listen_for_scan():
scan_triggered = False
status = "Analyzing surroundings..."
speak("Analyzing surroundings")

# ✅ Gemini AI description
desc = process_frame(frame)
speak(desc)

# ✅ OCR text detection
text = extract_text_from_image(frame)
if text.strip():
speak(f"Detected text: {text}")

# Alert on specific signs
lower_desc = desc.lower()
if "stop sign" in desc.lower() or "stop" in desc.lower():
speak("Stop! There's a stop sign.")
elif "red light" in desc.lower():
Expand Down
21 changes: 21 additions & 0 deletions ocr_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytesseract
import cv2
import numpy as np

def extract_text_from_image(image: 'np.ndarray') -> str:
"""
Extract text from a given image using pytesseract OCR.

Args:
image: Input image as a numpy array (OpenCV format)

Returns:
Extracted text as a string
"""
# Convert image to grayscale (OCR works better on gray)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Use pytesseract to extract text
text = pytesseract.image_to_string(gray)

return text
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Existing dependencies
opencv-python
pyttsx3
gTTS
Expand All @@ -10,4 +11,7 @@ playsound
python-dotenv
langchain-google-genai
langchain-core
insightface

# Add InsightFace
insightface
pytesseract