Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Car Background Removal API

A FastAPI application that detects vehicles in images, crops them, and removes the background using AI models.

Features

  • Vehicle detection using YOLO11
  • Automatic cropping to vehicle bounds
  • Background removal using rembg
  • RESTful API endpoint

Installation

  1. Clone or download this project

  2. Install Python dependencies

    pip install -r requirements.txt
  3. Run the application

    uvicorn app:app --reload

    Or with specific host and port:

    uvicorn app:app --host 0.0.0.0 --port 8000 --reload

Usage

Once the server is running, you can:

  1. Visit the interactive API docs: http://localhost:8000/docs
  2. Make POST requests to /car-remove-background/ with an image file

Example using curl:

curl -X POST "http://localhost:8000/car-remove-background/" \
     -H "accept: application/json" \
     -H "Content-Type: multipart/form-data" \
     -F "file=@your_car_image.jpg" \
     --output result.png

Example using Python requests:

import requests

url = "http://localhost:8000/car-remove-background/"
with open("car_image.jpg", "rb") as f:
    files = {"file": f}
    response = requests.post(url, files=files)

with open("result.png", "wb") as f:
    f.write(response.content)

Docker

Build a CPU-only image and run the API on port 8000.

# Build
docker build -t car-bg-api:latest .

# Run
docker run --rm -p 8000:8000 \
  -e OMP_NUM_THREADS=8 \
  car-bg-api:latest

Notes:

  • If yolo11x.pt exists in the project root, it will be included in the image and used directly.
  • If the weight is missing, Ultralytics will auto-download it at first request.
  • On low-memory hosts, you can lower the number of threads via OMP_NUM_THREADS.

Notes

  • The YOLO model will be automatically downloaded on first run (if not bundled)
  • Supported image formats: JPG, PNG, etc.
  • The API returns a PNG image with transparent background
  • Vehicles (cars, motorcycles, buses, trucks) are detected and processed

About

Vehicle detection, automatic cropping, and background removal API built with FastAPI, YOLO11, and rembg.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages