Skip to main content

P2W is a toolbox that implements several utilities for getting real-world information from pictures.

Project description

Pic2World

Pic2World is a toolbox for inferring Real World Information from Pictures and Camera Intrinsics. It also offers a set of Geometry and Image Manipulation tools, that help to deal with Homographies and Perspective while maintaining the Real World coherence.

Installation

You can install Pic2World via pip, by running the following command:

pip install pic2world

Usage

Pic2World includes 4 main modules:

  1. pic2world.geometry: Geometry tools for dealing with polygon transformations.
  2. pic2world.camera_utils: Tools based on Gauss Thin-Lens Equation for measuring real world distances from pixel measures and camera intrinsics.
  3. pic2world.homographies: Tools for dealing with Homographies. Designed to produce visualizations coherent with Real World inferred data.
  4. pic2world.interactive: Tools for interactive visualization, based on matplotlib. Help to define polygons and ask questions to the user. Useful for debugging.

Camera Utils

Camera Utils include two main classes, pic2world.camera_utils.camera and pic2world.camera_utils.ruler.

Camera is used to contain all Camera Intrinsics information:

from pic2world.camera_utils.camera import Camera
# Build the Intrinsics of a Canon R6 
CANON_EOS_R6_CAMERA = Camera(
    pixel_size_mm=8.18/1000.0, # Pixel size of the camera sensor
    focal_length_mm=50, # Focal length of the mounted lens
    sensor_shape_px=(3648, 5472) # (height, width) of the sensor. Can be setted as None. Only used when images are taken from hard angles.
)

Ruler is used to calculate real world distances from pixel measures and camera intrinsics:

Calculating Distance between the lens and the object when the Real Length is known
from pic2world.camera_utils.ruler import Ruler
# Create a Ruler object
ruler = Ruler(camera=CANON_EOS_R6_CAMERA)
distance_to_img = ruler.distance_to_object_cm(object_length_px=2320, # Length of the object in pixels
                                              real_object_length_cm=3*30.0, # Real Length of 3 DIN-A4 papers.
                                              angle_degrees=60) # Angle with which the image was taken (0 would mean zenith).
# Print the distance in cm.
>>> Distance to object -> Calculated: 118.5608 cm [Real: 118.0 cm]
Calculating Real Length of an object when the distance between it and the camera lens is known
# Assume the same camera as above
object_height = ruler.object_length_in_cm(object_length_px=2320, # Length of a vertical of the object in pixels,
                                                  distance_to_object_cm=118.0, # Distance between the object and the camera lens in cm
                                                  angle_degrees=60) # Angle with which the image was taken (0 would mean zenith).
# Print the real length in cm.
>>> Object height -> Calculated: 89.5742 cm [Real 90.0 cm]

Homographies

Homographies module includes functions for changing the perspective of an image, while maintaining the real world coherence.

From original image to zenith view. Setting input interactively
from pic2world.homographies.homography_utils import correct_perspective
correct_polygon_perspective(img,
                            origin_polygon=None, # We are not providing an input polygon because we want the user to define it.
                            interactive=True, # Ask the user to define the polygon.
                            angle_degrees=60.0, # Angle with which the image was originaly taken.
                            output_shape=(600, 300), # Output shape we want
                            pad= 0.05) # Padding between the limits of the rectangle and the border of the output image.

Note

This library is a work in progress. It is not yet complete, and it is not meant to be used in production yet.

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

pic2world-0.4.1.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file pic2world-0.4.1.tar.gz.

File metadata

  • Download URL: pic2world-0.4.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for pic2world-0.4.1.tar.gz
Algorithm Hash digest
SHA256 518c69e650c56495181b0488115e5982467cfe87205817988245b423afc15a69
MD5 eba400070782e9c7f1c3e59a83046b73
BLAKE2b-256 340ef4ad3d90fecea856bd7d79861abb1603b4dd65956c06b0c8cbd6d9f84784

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