Upload a photo. Identify the plastic. Know the risk.
Plastic Trace AI is a local web application that analyzes the given photos of plastic objects to identify their polymer type and generate a full toxicity, chemical safety, and environmental impact report. It offers a cost effective alternative to expensive laboratory testing by enabling accessible public level analysis and screening
- Prerequisites
Make sure you have Python 3.9+ and Tesseract OCR installed.
Install Tesseract:
- Windows: Download from https://github.com/UB-Mannheim/tesseract/wiki and install it
- Mac:
brew install tesseract - Linux:
sudo apt install tesseract-ocr
- Install Python dependencies
pip install -r requirements.txt- Run the app
python app.py- Open in browser
http://localhost:5000
- 📸 Upload a photo of any plastic object
- 🔍 Automatically scans for the recycling triangle number (1–7) printed on the item
- 📊 Shows the top 3 plastic type matches with percentages that sum to exactly 100%
- 👁️ Analyzes surface transparency, glossiness, smoothness, rigidity of the plastic type
- ☣️ Toxicity meters: Overall, BPA Risk, Environmental Impact
- 🧪 Chemical profile: polymer family, additives, heat resistance, phthalates risk
- ♻️ Recyclability Rating: Whether the plastic is widely recyclable, recyclable in some areas, or difficult to recycle
- 🍽️ Food & Reuse Safety: Clear verdict on whether the plastic is safe for food contact and repeated use
- 🏭 Manufacturer Estimation: Guesses the likely manufacturer based on plastic type and object shape from a built-in database of 30+ entries
➡️ Frontend
- Vanilla HTML / CSS / JavaScript — zero frameworks, single-file template
- Jinja2 — Flask's built-in templating engine for rendering the page
- Google Fonts — Inter (body) + JetBrains Mono (monospace labels)
- Inline SVG icons — no icon libraries needed
- Dark theme UI — custom CSS variables, animated toxicity meters, drag-and-drop uploader
➡️ Backend
- Python 3.9+
- Flask — lightweight web server handling the
/page route and/analyzePOST endpoint - Pillow (PIL) — image decoding and resizing before analysis
- OpenCV (
opencv-python-headless)** — computer vision pipeline for texture feature extraction - NumPy — numerical operations for brightness, variance, and score calculations
- pytesseract + Tesseract OCR — reads the recycling number printed on plastic items
➡️ Detection Logic (detector.py)
The core analysis runs in three stages:
🗝 Stage 1 — OCR Scan Tesseract scans the full image and focused bottom-center crops (where recycling symbols typically appear) looking for a digit between 1 and 7. If found, confidence is set to ~88%.
🗝 Stage 2 — Visual Texture Fingerprinting Five image features are extracted and compared against a hand-tuned visual profile for each of the 7 plastic types:
--------------------------------------------------------------------------
| Feature | How it's measured |
--------------------------------------------------------------------------
| Transparency | Mean brightness x uniformity (low std = clear/glassy) |
| Glossiness | Laplacian variance — sharp edges = reflective surface |
| Smoothness | Inverse of local texture difference vs Gaussian blur |
| Rigidity | Straight line count via Hough transform |
| Color Variance | Mean channel standard deviation across RGB |
--------------------------------------------------------------------------
Each plastic type has a reference fingerprint. The image features are scored against all 7 types, normalised to sum to 100%, and the best match is returned as the detected type.
🗝 Stage 3 — Manufacturer Lookup The detected plastic code and estimated shape are used to look up a likely manufacturer from a database of 30+ entries mapping (plastic_code, shape) to (name, country, products, confidence).
🌐 Data
- All toxicity, chemical, and safety data is stored in a built-in Python dictionary (
PLASTICS_DB) based on publicly available scientific standards for plastic types 1–7. - Manufacturer data is a curated lookup table — estimates only, not definitive identification.
plastic-trace-py/
├── app.py # Flask server — routes and API endpoint
├── detector.py # Core detection engine (OCR + vision + DB lookup)
├── requirements.txt # Python dependencies
├── README.md # This file
└── templates/
└── index.html # Full frontend (HTML + CSS + JS in one file)
Results are based on OCR text recognition and visual texture heuristics — not laboratory testing. Detection accuracy depends on image quality and whether the recycling symbol is visible. For critical safety decisions, consult certified testing facilities.