Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Paoline

Pages: [1]
1
General / Re: Shapes changed on different projection
« on: September 06, 2023, 11:47:42 AM »
I have the same issue on Metashape Pro 2.0.2 (it was working fine on 1.8.4).

If I create a shape (polygon) on one orthomosaic, and then another shape on a second orthomosaic, the first shape changes.
The shape's geometry changes as well as the shapes projection matrix :

Code: [Select]
chunk.shapes.projection.matrix
Out[7]: 2023-09-06 10:32:33
2023-09-06 10:32:33 Matrix([[1.0, 0.0, 0.0, -4.190819334493266],
2023-09-06 10:32:33        [0.0, 0.0, 1.0, 15.660437452109326],
2023-09-06 10:32:33        [0.0, -1.0, 0.0, 2.7672848891498756],
2023-09-06 10:32:33        [0.0, 0.0, 0.0, 1.0]])

chunk.shapes[0].geometry
Out[8]: 2023-09-06 10:32:36 <Geometry 'Polygon ((-11.2238 -1.36733, -10.7282 -2.45776, -8.94382 -2.60645, -3.04561 -2.35863, 17.6229 0.565698, 17.5733 1.35874, -11.2238 -1.36733))'>

chunk.shapes.projection.matrix
Out[9]: 2023-09-06 10:32:47
2023-09-06 10:32:47 Matrix([[1.0, 0.0, 0.0, -4.190819334493266],
2023-09-06 10:32:47        [0.0, 1.0, 0.0, -2.7672848891498756],
2023-09-06 10:32:47        [0.0, 0.0, 1.0, 15.660437452109326],
2023-09-06 10:32:47        [0.0, 0.0, 0.0, 1.0]])

chunk.shapes[0].geometry
Out[10]: 2023-09-06 10:32:51 <Geometry 'Polygon ((-11.2238 0, -10.7282 0, -8.94382 0, -3.04561 0, 17.6229 0, 17.5733 0, -11.2238 0))'>

Is this a bug or is there something I'm missing ?

2
Thanks Alexey, that works perfectly !

3
Python and Java API / number valid/total matches between pairs of images
« on: November 28, 2022, 02:35:42 PM »
Hi,

I'm trying to acces the number of total and valid matches between pairs of images with the python API.
After looking through the forum I tried two solutions but neither worked :

> My first code returns the same number for total and valid matches (the total number of matches is the same as in the GUI with --> View Matches)
Code: [Select]
import Metashape
import numpy as np
doc = Metashape.app.document
chunk=doc.chunk

point_cloud = chunk.point_cloud
point_proj = point_cloud.projections
points = point_cloud.points

projection_matches = list()

for camera in chunk.cameras:
photo_proj = point_proj[camera] #get individual projection
total_projections = set()
for proj in photo_proj:
total_projections.add(proj.track_id)
projection_matches.append(total_projections)

i=0
camera=chunk.cameras[i]
list_cameras = [ chunk.cameras.index(photo) for photo in chunk.cameras if photo != camera ]
for j in list_cameras:
  projection_match = projection_matches[i] & projection_matches[j] # Get projections intersections for cameras i and j
 
  total = len(projection_match)
  valid=0
  for p_index in projection_match:
    if points[p_index].valid : valid += 1
   
  if total >0 :  print(camera.label, chunk.cameras[j].label, total, valid)
 


> The second version (is way slower and) returns the right number of total matches but not the same number of valid matches as in the GUI
Code: [Select]
import Metashape
import numpy as np
doc = Metashape.app.document
chunk=doc.chunk

point_cloud = chunk.point_cloud
point_proj = point_cloud.projections
points = point_cloud.points
npoints = len(points)

projection_matches = list() #here projections for total matches will be stored
photo_matches = dict() #here points for valid matches will be stored

for camera in chunk.cameras:
photo_proj = point_proj[camera]
total_projections = set()
for proj in photo_proj:
total_projections.add(proj.track_id)
projection_matches.append(total_projections)

for camera in chunk.cameras:
  i=0
  total_points = set()
  point_index = 0
  proj = point_proj[camera]
  for cur_point in proj:
    track_id = cur_point.track_id
    i+=1
    while point_index < npoints and points[point_index].track_id < track_id:
      point_index += 1
      if point_index < npoints and points[point_index].track_id == track_id:
        if point_cloud.points[point_index].valid:
          total_points.add(point_index)
        photo_matches[camera] = total_points

MatchesKeys = []
for keys in photo_matches.keys():
  MatchesKeys.append(keys)

i=0
camera=chunk.cameras[i]
list_cameras = [ chunk.cameras.index(photo) for photo in chunk.cameras if photo != camera ]
for j in list_cameras:
  projection_match = projection_matches[i] & projection_matches[j] # Get projections intersections for cameras i and j
  point_match = photo_matches[MatchesKeys[i]] & photo_matches[MatchesKeys[j]] # Get points intersections for cameras
 
  total = len(projection_match)
  valid = len(point_match)
  if total >0 :  print(camera.label, chunk.cameras[j].label, total, valid)

Does anyone knows a way to obtain the wanted results?

Pages: [1]