Skip to main content

Code for estimating the direction of the sun from a single outdoor image.

Project description

Suncompass

This repository contains code for estimating the direction of the sun from a single outdoor image. Suncompass

Repository Contents

  1. pretrained_resnet.py: Defines a regression model based on a pre-trained ResNet model and includes functions for training and loading the model.
  2. 3_224_224_resnet.pth: A pre-trained ResNet model for estimating the direction of the sun from a single outdoor image.
  3. suncompass.py: Class for interacting with the pre-trained ResNet model.
  4. demo.py: Demonstrates how to use the pre-trained ResNet model to estimate the direction of the sun from a single outdoor image.

Requirements

  • Python 3.7+
  • PyTorch
  • torchvision
  • pandas
  • numpy
  • matplotlib
  • tqdm
  • click
  • PIL
  • tensorboard
  • suncalc

Installation

  1. Clone the repository:

    git clone https://github.com/hugohadfield/suncompass.git
    cd suncompass
    
  2. Install the package:

    pip install .
    

Usage

add_sun_vector.py

This script calculates the sun vector in the ENU frame and the relative frame based on heading.

Example usage:

python add_sun_vector.py

extract_motion.py

This script extracts motion parameters such as speed, heading, and curvature from a given dataset.

Example usage:

python extract_motion.py

pretrained_resnet.py

This script defines and trains a regression model based on a pre-trained ResNet model.

Example usage:

python pretrained_resnet.py

run_model_on_images.py

This script runs the trained ResNet model on a set of images and saves the results to a CSV file.

Example usage:

python run_model_on_images.py --model_name 3_224_224_resnet.pth --image_dir /path/to/images --gt_csv /path/to/ground_truth.csv

Function Details

add_sun_vector.py

  • calculate_sun_vector_ENU(time: datetime, lat_degs: float, long_degs: float) -> np.ndarray: Calculates the sun vector in the ENU frame.
  • calculate_sun_vector_relative(time_unixus: int, lat_degs: float, long_degs: float, heading_rads_from_east: Union[float, np.complex128]) -> np.ndarray: Calculates the sun vector in the relative frame.
  • calculate_relative_azimuth_angle(time_unixus: int, lat_degs: float, long_degs: float, heading_rads_from_east: float) -> float: Calculates the azimuth angle of the sun vector in the relative frame.

extract_motion.py

  • haversine(lat1, lon1, lat2, lon2) -> float: Calculates the great circle distance between two points on the Earth.
  • calculate_bearing_clockwise_from_north(lat1, lon1, lat2, lon2) -> float: Calculates the bearing between two points.
  • calculate_heading_anticlockwise_from_east(lat1, lon1, lat2, lon2) -> float: Calculates the heading anti-clockwise from east.
  • extract_motion(data: pd.DataFrame) -> pd.DataFrame: Extracts speed, heading, and curvature from the given data.

pretrained_resnet.py

  • ResNetRegression: Defines a regression model based on a pre-trained ResNet model.
  • train_network(device, n_epochs: int = 10, image_size: Tuple[int, int] = (128, 128)): Trains the network for a set number of epochs.

run_model_on_images.py

  • run_model_on_images(model_name: Path, image_dir: Path, image_size: Tuple[int, int, int] = (1, 100, 100)): Runs the model on the images and saves the results to a CSV file.
  • plot_results_csv(gt_csv: Optional[str] = None): Plots the results from the CSV file.

License

This project is licensed under the MIT License - see the licence.txt file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

suncompass-0.0.1.tar.gz (43.5 MB view details)

Uploaded Source

Built Distribution

suncompass-0.0.1-py3-none-any.whl (43.5 MB view details)

Uploaded Python 3

File details

Details for the file suncompass-0.0.1.tar.gz.

File metadata

  • Download URL: suncompass-0.0.1.tar.gz
  • Upload date:
  • Size: 43.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for suncompass-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d6a302bc0fc3bdb2f27116e7b8ed1af73523f9fd09a8f3041f48a9964ed55ca2
MD5 c3f4f1a46c57771a12695e9c5c5645d2
BLAKE2b-256 2389e0b0b8aecf603aba1af3de1da64f641532b6f6114a578daef7dd07e2d1bd

See more details on using hashes here.

File details

Details for the file suncompass-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: suncompass-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 43.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for suncompass-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f2b8dc8dd4f526212b7f874ff84fce9aa856db84c955b49cbe0304d5733ee4a
MD5 586c4533a306b0006d3427c59bd03c3e
BLAKE2b-256 0964235a6266b61ee66d1fa3c8094916231314e6f970cfc396bc0eb9fff5ba71

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page