Forum

Author Topic: Measure size of objects  (Read 5825 times)

Raj Calisa

  • Newbie
  • *
  • Posts: 15
    • View Profile
Measure size of objects
« on: March 23, 2021, 09:09:26 AM »
Hi all,


I am new to metashape and I am using the Python API to automate creation of model from drone footage. I also detect features in the photos as polygons and map them to the mesh/point cloud as shapes. These then appear in the model when viewing or I can export it.

I wanted to know what the units are of the 3D coordinates of the shapes. Typically I convert a 2D pixel on the photo to a 3D point as follows:
    T = chunk.transform.matrix
    vertices_3d = list()
    for x, y in poly:
        ray_origin = camera.unproject(Metashape.Vector([x, y, 0]))
        ray_target = camera.unproject(Metashape.Vector([x, y, 1]))
        pt = surface.pickPoint(ray_origin, ray_target)
        if pt is not None:
            vertex = chunk.crs.project(T.mulp(pt))
            vertices_3d.append(vertex)


Ideally I want to measure the lengths of the sides of the polygons by ignoring the Z coordinate. Firstly I want to understand the units for these coordinates. Is it possible to specify something in the creation process where the units can be in metres?

Thanks.

Raj

Paulo

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Measure size of objects
« Reply #1 on: March 23, 2021, 02:48:40 PM »
Hi Raj,

the units are defined in the CRS definition you are using. Normally it is meters but you can check with following :
Code: [Select]
chunk.crs.wkt2[chunk.crs.wkt2.find('LENGTHUNIT'):-1]
Out[16]: 2021-03-23 05:47:35 'LENGTHUNIT["metre",1,ID["EPSG",9001]]'

In case LENGTHUNIT is not present in wkt2 then you would be using geographic CS and would need to transform your coordinates into some Projected CS to be able to get easy length measurements...
« Last Edit: March 23, 2021, 02:56:57 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Raj Calisa

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Measure size of objects
« Reply #2 on: March 23, 2021, 11:23:16 PM »
Hi Paul,

Thanks for your reply. I use photos captured from a drone and it has GPS coordinates. Hence the crs I am using is as follows:
Code: [Select]
Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] on win32
chunk.crs.wkt2
Out[2]: 'GEODCRS["WGS 84",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,ID["EPSG",7030]],ID["EPSG",6326]],PRIMEM["Greenwich",0,ID["EPSG",8901]],CS[ellipsoidal,2],ANGLEUNIT["degree",0.01745329251994328,ID["EPSG",9102]],ID["EPSG",4326]]'

The above I assume is geographic CS.
When you say I need to convert to a projected CS can you point me to how it is done? Are you referring to
Code: [Select]
Metashape.CoordinateSystem.transform()
function? In which case what should be a typical coordinate system to transform to?


Regards,


Raj

Paulo

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Measure size of objects
« Reply #3 on: March 23, 2021, 11:53:08 PM »
Hi Raj,

It depends in what area of the world you are operating. Typically UTM is an universal projected coordinate system that is used widely and divides the world into sixty 6 degree wide longitude zones.

For example in central Europe you could define (or areas between longitude 6 deg E and 12 deg E north of Equator):
Code: [Select]
target_crs = Metashape.CoordinateSystem("EPSG::32632") # WGS84/UTM32 N
and just replace chunk.crs with target_crs and voila all your 3d vertices will be in UTM zone 32 N CRS
« Last Edit: March 24, 2021, 12:31:48 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor