Package: pic2world
Pic2WorldPic2Worldis a toolbox for inferringReal World InformationfromPicturesandCamera Intrinsics.
It also offers a set ofGeometryandImage Manipulationtools, that help to deal withHomographiesandPerspectivewhile maintaining theReal Worldcoherence.InstallationYou can install Pic2Worldvia pip, by running the following command:pipinstallpic2worldUsagePic2World includes 4 main modules:pic2world.geometry: Geometry tools for dealing with polygon transformations.pic2world.camera_utils: Tools based onGauss Thin-Lens Equationfor measuring real world distances from pixel measures and camera intrinsics.pic2world.homographies: Tools for dealing with Homographies. Designed to produce visualizations coherent with Real World inferred data.pic2world.interactive: Tools for interactive visualization, based onmatplotlib. Help to define polygons and ask questions to the user. Useful for debugging.Camera UtilsCamera Utils include two main classes,pic2world.camera_utils.cameraandpic2world.camera_utils.ruler.Camerais used to contain all Camera Intrinsics information:frompic2world.camera_utils.cameraimportCamera# Build the Intrinsics of a Canon R6CANON_EOS_R6_CAMERA=Camera(pixel_size_mm=8.18/1000.0,# Pixel size of the camera sensorfocal_length_mm=50,# Focal length of the mounted lenssensor_shape_px=(3648,5472)# (height, width) of the sensor. Can be setted as None. Only used when images are taken from hard angles.)Ruleris 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 knownfrompic2world.camera_utils.rulerimportRuler# Create a Ruler objectruler=Ruler(camera=CANON_EOS_R6_CAMERA)distance_to_img=ruler.distance_to_object_cm(object_length_px=2320,# Length of the object in pixelsreal_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.>>>Distancetoobject->Calculated:118.5608cm[Real:118.0cm]Calculating Real Length of an object when the distance between it and the camera lens is known# Assume the same camera as aboveobject_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 cmangle_degrees=60)# Angle with which the image was taken (0 would mean zenith).# Print the real length in cm.>>>Objectheight->Calculated:89.5742cm[Real90.0cm]HomographiesHomographies module includes functions for changing the perspective of an image, while maintaining the real world coherence.From original image to zenith view. Setting input interactivelyfrompic2world.homographies.homography_utilsimportcorrect_perspectivecorrect_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 wantpad=0.05)# Padding between the limits of the rectangle and the border of the output image.NoteThis library is a work in progress. It is not yet complete, and it is not meant to be used in production yet.