Skip to content

Latest commit

 

History

History
134 lines (110 loc) · 3.22 KB

README_EN.md

File metadata and controls

134 lines (110 loc) · 3.22 KB

Satellite_Image_Object_Detection

Author: UR的出不克

Project Overview

This is a web application system for satellite image object detection based on YOLOv5 and Flask. The system can detect and identify specific targets in satellite images, including oil tanks, vessels, bridges, and aircraft.

Features

  • Web interface for image upload and detection
  • API interface support
  • Real-time display of detection results and confidence levels
  • Multiple object detection support
  • Detection categories:
    • Oil tanks (oilcan)
    • Vessels (vessel)
    • Bridges (bridge)
    • Aircraft (plane)

Requirements

  • Python 3.7+
  • PyTorch 1.7.0+
  • Flask
  • OpenCV
  • Other dependencies listed in requirements.txt

Installation

  1. Clone the repository
git clone [repository_url]
cd yolo-flask-master
  1. Download YOLOv5
git clone https://github.com/ultralytics/yolov5.git
cd yolov5
pip install -r requirements.txt
cd ..
  1. Install project dependencies
pip install -r requirements.txt
  1. Prepare model file
  • Place the trained model file best.pt in the yolov5 directory
  1. Create main.py Create main.py file in the yolov5 directory with the following content:
import torch
from models.experimental import attempt_load
from utils.general import non_max_suppression
from utils.datasets import letterbox
import cv2
import numpy as np

def detect(weights, source, device):
    # Load model
    model = attempt_load(weights, device=device)
    
    # Read image
    img0 = cv2.imread(source)
    img = letterbox(img0, 640, stride=32)[0]
    img = img.transpose((2, 0, 1))[::-1]
    img = np.ascontiguousarray(img)
    img = torch.from_numpy(img).to(device)
    img = img.float()
    img /= 255.0
    if img.ndimension() == 3:
        img = img.unsqueeze(0)
    
    # Inference
    pred = model(img, augment=False)[0]
    pred = non_max_suppression(pred, 0.25, 0.45)
    
    # Process results
    det = pred[0]
    if len(det):
        det[:, :4] = scale_coords(img.shape[2:], det[:, :4], img0.shape).round()
        
    return det

def scale_coords(img1_shape, coords, img0_shape):
    gain = min(img1_shape[0] / img0_shape[0], img1_shape[1] / img0_shape[1])
    pad = (img1_shape[1] - img0_shape[1] * gain) / 2, (img1_shape[0] - img0_shape[0] * gain) / 2
    
    coords[:, [0, 2]] -= pad[0]
    coords[:, [1, 3]] -= pad[1]
    coords[:, :4] /= gain
    
    coords[:, 0].clamp_(0, img0_shape[1])
    coords[:, 1].clamp_(0, img0_shape[0])
    coords[:, 2].clamp_(0, img0_shape[1])
    coords[:, 3].clamp_(0, img0_shape[0])
    
    return coords
  1. Run the application
python app.py

Usage Guide

  1. Web Interface:

    • Visit http://localhost:5000
    • Click the upload button to select an image
    • Click the "Object Detection" button to perform detection
    • View detection results and confidence levels
  2. API Usage:

    • API endpoint: http://localhost:5000/api
    • Request method: POST
    • Request format: JSON
    • Parameters:
      {
          "img_base64": "image base64 encoded string"
      }

Technical Architecture

  • Backend: Flask
  • Deep Learning Framework: YOLOv5 + PyTorch
  • Frontend: Bootstrap
  • Image Processing: OpenCV

Contact

Author: UR的出不克

License

MIT License