pic2world


Namepic2world JSON
Version 0.4.1 PyPI version JSON
download
home_pagehttps://github.com/Eric-Canas/pic2world
SummaryP2W is a toolbox that implements several utilities for getting real-world information from pictures.
upload_time2022-06-19 19:35:21
maintainer
docs_urlNone
authorEric Canas
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements numpy opencv-python matplotlib setuptools
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pic2World
<b>Pic2World</b> is a toolbox for inferring <b>Real World Information</b> from <b>Pictures</b> and <b>Camera Intrinsics</b>.
It also offers a set of <b>Geometry</b> and <b>Image Manipulation</b> tools, that help to deal with <b>Homographies</b>
and <b>Perspective</b> while maintaining the <b>Real World</b> coherence.

## Installation
You can install Pic2World [via pip](https://pypi.org/project/pic2world/), by running the following command:
```bash
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](https://en.wikipedia.org/wiki/Thin_lens) 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](https://matplotlib.org/). 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:
```python
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


```python
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).
```

```python
# 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

```python
# 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).
```

```python
# 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

```python
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.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Eric-Canas/pic2world",
    "name": "pic2world",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Eric Canas",
    "author_email": "eric@ericcanas.com",
    "download_url": "https://files.pythonhosted.org/packages/34/0e/f4ad3d90fecea856bd7d79861abb1603b4dd65956c06b0c8cbd6d9f84784/pic2world-0.4.1.tar.gz",
    "platform": null,
    "description": "# Pic2World\r\n<b>Pic2World</b> is a toolbox for inferring <b>Real World Information</b> from <b>Pictures</b> and <b>Camera Intrinsics</b>.\r\nIt also offers a set of <b>Geometry</b> and <b>Image Manipulation</b> tools, that help to deal with <b>Homographies</b>\r\nand <b>Perspective</b> while maintaining the <b>Real World</b> coherence.\r\n\r\n## Installation\r\nYou can install Pic2World [via pip](https://pypi.org/project/pic2world/), by running the following command:\r\n```bash\r\npip install pic2world\r\n```\r\n\r\n## Usage\r\nPic2World includes 4 main modules:\r\n1. `pic2world.geometry`: Geometry tools for dealing with polygon transformations.\r\n2. `pic2world.camera_utils`: Tools based on [Gauss Thin-Lens Equation](https://en.wikipedia.org/wiki/Thin_lens) for measuring real world distances from pixel measures and camera intrinsics.\r\n3. `pic2world.homographies`: Tools for dealing with Homographies. Designed to produce visualizations coherent with Real World inferred data.\r\n4. `pic2world.interactive`: Tools for interactive visualization, based on [matplotlib](https://matplotlib.org/). Help to define polygons and ask questions to the user. Useful for debugging.\r\n\r\n### Camera Utils\r\nCamera Utils include two main classes, `pic2world.camera_utils.camera` and `pic2world.camera_utils.ruler`.\r\n\r\n\r\n`Camera` is used to contain all Camera Intrinsics information:\r\n```python\r\nfrom pic2world.camera_utils.camera import Camera\r\n# Build the Intrinsics of a Canon R6 \r\nCANON_EOS_R6_CAMERA = Camera(\r\n    pixel_size_mm=8.18/1000.0, # Pixel size of the camera sensor\r\n    focal_length_mm=50, # Focal length of the mounted lens\r\n    sensor_shape_px=(3648, 5472) # (height, width) of the sensor. Can be setted as None. Only used when images are taken from hard angles.\r\n)\r\n```\r\n\r\n`Ruler` is used to calculate real world distances from pixel measures and camera intrinsics:\r\n\r\n##### Calculating Distance between the lens and the object when the Real Length is known\r\n\r\n\r\n```python\r\nfrom pic2world.camera_utils.ruler import Ruler\r\n# Create a Ruler object\r\nruler = Ruler(camera=CANON_EOS_R6_CAMERA)\r\ndistance_to_img = ruler.distance_to_object_cm(object_length_px=2320, # Length of the object in pixels\r\n                                              real_object_length_cm=3*30.0, # Real Length of 3 DIN-A4 papers.\r\n                                              angle_degrees=60) # Angle with which the image was taken (0 would mean zenith).\r\n```\r\n\r\n```python\r\n# Print the distance in cm.\r\n>>> Distance to object -> Calculated: 118.5608 cm [Real: 118.0 cm]\r\n```\r\n\r\n##### Calculating Real Length of an object when the distance between it and the camera lens is known\r\n\r\n```python\r\n# Assume the same camera as above\r\nobject_height = ruler.object_length_in_cm(object_length_px=2320, # Length of a vertical of the object in pixels,\r\n                                                  distance_to_object_cm=118.0, # Distance between the object and the camera lens in cm\r\n                                                  angle_degrees=60) # Angle with which the image was taken (0 would mean zenith).\r\n```\r\n\r\n```python\r\n# Print the real length in cm.\r\n>>> Object height -> Calculated: 89.5742 cm [Real 90.0 cm]\r\n```\r\n\r\n### Homographies\r\nHomographies module includes functions for changing the perspective of an image, while maintaining the real world coherence.\r\n\r\n##### From original image to zenith view. Setting input interactively\r\n\r\n```python\r\nfrom pic2world.homographies.homography_utils import correct_perspective\r\ncorrect_polygon_perspective(img,\r\n                            origin_polygon=None, # We are not providing an input polygon because we want the user to define it.\r\n                            interactive=True, # Ask the user to define the polygon.\r\n                            angle_degrees=60.0, # Angle with which the image was originaly taken.\r\n                            output_shape=(600, 300), # Output shape we want\r\n                            pad= 0.05) # Padding between the limits of the rectangle and the border of the output image.\r\n```\r\n\r\n## Note\r\n\r\nThis library is a work in progress. It is not yet complete, and it is not meant to be used in production yet.\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "P2W is a toolbox that implements several utilities for getting real-world information from pictures.",
    "version": "0.4.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "eba400070782e9c7f1c3e59a83046b73",
                "sha256": "518c69e650c56495181b0488115e5982467cfe87205817988245b423afc15a69"
            },
            "downloads": -1,
            "filename": "pic2world-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "eba400070782e9c7f1c3e59a83046b73",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3550,
            "upload_time": "2022-06-19T19:35:21",
            "upload_time_iso_8601": "2022-06-19T19:35:21.917614Z",
            "url": "https://files.pythonhosted.org/packages/34/0e/f4ad3d90fecea856bd7d79861abb1603b4dd65956c06b0c8cbd6d9f84784/pic2world-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-06-19 19:35:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Eric-Canas",
    "github_project": "pic2world",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.22.4"
                ]
            ]
        },
        {
            "name": "opencv-python",
            "specs": [
                [
                    ">=",
                    "4.6.0.66"
                ]
            ]
        },
        {
            "name": "matplotlib",
            "specs": [
                [
                    ">=",
                    "3.5.2"
                ]
            ]
        },
        {
            "name": "setuptools",
            "specs": [
                [
                    ">=",
                    "61.2.0"
                ]
            ]
        }
    ],
    "lcname": "pic2world"
}
        
Elapsed time: 0.31347s