A computer vision-based photo measurement back-end application/API that automatically detects and measures objects in photographs. Built with Python, FastAPI, and OpenCV, this tool provides precise measurements through camera calibration and contour detection.

Example2 (with homography applied):

Log example:

Features
* Automatic Object Detection: Uses computer vision to identify objects in photos
* Precise Measurements: Calculates object dimensions (sides, area) in centimeters (tested/adjusted for rectangular objects)
* Camera Calibration: Supports calibration for accurate measurements via reference object that has known dimensions
* RESTful API: FastAPI-based web service for easy integration
* Cross-Platform: Works on Windows, macOS, Linux, and Android
* Real-time Logging: Built-in logging system with optional GUI viewer
* Batch Processing: Support for processing multiple photos in sequence
How it works?
Depending of api method called this application processes either single next photo from working folder (defined in .ini file) or all photos from that folder. It tracks already processed photos and processes only new ones. Measurements are returned via API with optional debug images. Application requires one reference photo which is background without object (also defined in .ini file). Camera must be in fixed position for best results. It is up to you to create and place these files. For photo capture I developed installable android app that can be integrated with this back-end:
https://github.com/F4CIO/DroidEye
Technology Stack
* Backend: Python 3.x, FastAPI, Uvicorn
* Computer Vision: OpenCV, scikit-image, scipy
* Image Processing: NumPy
* GUI Framework: Kivy (for Android builds)
* Build System: Buildozer (for Android packaging)
Requirements
* Python 3.x
* Camera access
* Sufficient lighting for photo capture
* Calibration object with known dimensions
Installation
Prerequisites:
Install Python dependencies:
pip install -r requirements.txt
Quick Start:
1. Clone the repository:
git clone <repository-url>
cd f4cio_photo_measure
2. Install dependencies:
pip install -r requirements.txt
3. Run the application:
python main.py
The server will start on port 5000 (configurable via f4cio_photo_measure.ini).
Android Build
To build an Android APK:
1. Install Buildozer:
pip install buildozer
2. Initialize buildozer (if not already done):
buildozer init
3. Build the APK:
buildozer android debug
The APK will be generated in the bin/ directory.
Configuration
Create or modify f4cio_photo_measure.ini to customize settings:
[Settings]
Port = 5000
PhotosWithObjectsFolderPath = ./photos/
# Add other configuration options as needed
API Documentation
Endpoints:
1. Measure Object:
GET /measure?job_id={job_id}
Takes a new photo and measures the detected object.
Response:
{
"is_success": true,
"message": "OK",
"job_id": "job_123",
"sides_in_cm": [10.5, 8.2],
"area_in_cm": 86.1,
"debug_file_path": "/path/to/debug.jpg",
"debug_file_binary_base64": "base64_encoded_image"
}
2. Measure Next Photo:
GET /measure_next?job_id={job_id}
Measures the next photo in the sequence without taking a new one.
3. Measure All Photos:
GET /measure_all?job_id={job_id}
Process all available photos for the given job.
4. Calibrate Camera:
GET /calibrate?job_id={job_id}&width={width}&height={height}
Calibrates the camera using an object with known dimensions.
Parameters:
- width: Known width in cm
- height: Known height in cm
5. Calibrate Next:
GET /calibrate_next?job_id={job_id}
Continues calibration with the next calibration object.
Usage Examples
Python Client:
import requests
# Take photo and measure
response = requests.get("http://localhost:5000/measure", params={"job_id": "test_job"})
data = response.json()
if data["is_success"]:
print(f"Object sides: {data['sides_in_cm']} cm")
print(f"Object area: {data['area_in_cm']} cm²")
else:
print(f"Error: {data['message']}")
cURL:
# Measure object
curl "http://localhost:5000/measure?job_id=test_job"
# Calibrate camera
curl "http://localhost:5000/calibrate?job_id=cal_job&width=10&height=5"
LOGS
Check the following log files for debugging:
* f4cio_photo_measure.log - Main application logs
LICENSE
[Add your license information here]
---
Note: This application requires proper camera calibration for accurate measurements. Ensure calibration objects have known dimensions and are photographed under consistent lighting conditions.
GitHub
You can download source code from my GitHub page. Feel free to contribute there by committing your improvements for this project.
Other Projects
See my
other projects.
Comments