Forum

Author Topic: extract image/pixel coordinates for every point of the sparse cloud  (Read 7984 times)

marinosvlachos

  • Newbie
  • *
  • Posts: 13
    • View Profile
Hello i was going through the forum and i discovered the this particular topic (can I get a list of the cameras tied to each point in the sparse cloud?). My question is as follows: Can i extract with the use of a script, a txt with the sparse cloud 3D coordinates, all the images that every single point of the sparse cloud is shown in and the image/ pixel coordinates of the points in those images? Thank you in advance.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Hello marinosvlachos,

Would the following format be fine for you:
image label, tie point id, x-coord, y-coord?
Best regards,
Alexey Pasumansky,
Agisoft LLC

marinosvlachos

  • Newbie
  • *
  • Posts: 13
    • View Profile
Hello Alexey and thank you for the reply. Sorry for the late response.  I think yes that will be fine.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Hello marinosvlachos,

Please check if the following scrips gives you the desired output:

Code: [Select]
#compatibility Metashape Pro 1.5.2

import Metashape, time

def var0():
t0 = time.time()
chunk = Metashape.app.document.chunk
if not chunk:
return None
point_cloud = chunk.point_cloud
points = point_cloud.points
npoints = len(points)
projections = chunk.point_cloud.projections
max_count = 0

path = Metashape.app.getSaveFileName("Specify export file name:", filter=" *.txt")
if not path:
print("Incorrect path, script aborted.")
return None
file = open(path, "wt")

print("\nScript started ...")
point_ids = [-1] * len(point_cloud.tracks)

for point_id in range(0, npoints):
point_ids[points[point_id].track_id] = point_id

for camera in chunk.cameras:
if not camera.type == Metashape.Camera.Type.Regular: #skipping camera track keyframes
continue
if not camera.transform: #skipping NA cameras
continue

for proj in projections[camera]:
track_id = proj.track_id
point_id = point_ids[track_id]
if point_id < 0:
continue
if not points[point_id].valid:
continue

line = "{:s},{:d},{:.2f},{:.2f}\n".format(camera.label, point_id, proj.coord.x, proj.coord.y)
file.write(line)
file.flush()

file.close()
t2 = time.time()
t2 -= t0
t2 = float(t2)

print("Script finished in " + "{:.2f}".format(t2) + " seconds.")
return True


####
var0()
Best regards,
Alexey Pasumansky,
Agisoft LLC

marinosvlachos

  • Newbie
  • *
  • Posts: 13
    • View Profile
Hello Alexey. Thank you for providing me with a script. Unfortunately an error appears when i run it.

 line 29, in var0
if not camera.type == Metashape.Camera.Type.Regular: #skipping camera track keyframes
 AttributeError: 'Metashape.Camera' object has no attribute 'type'
44 Error: 'Metashape.Camera' object has no attribute 'type'

Any suggestions? I need to mention that i am using metashape 1.5.0 build.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Hello marinosvlachos,

I suggest to update to the version 1.5.3 (build 8469) unless you have any significant reasons to stay on the older version.

For the version 1.5.0 you can remove camera.type check, as it is related to skipping the animation track cameras, which were not accessible in the older version.
Best regards,
Alexey Pasumansky,
Agisoft LLC

marinosvlachos

  • Newbie
  • *
  • Posts: 13
    • View Profile
Thank you Alexey. Just another question. The script you provided to export the image label, tie point id, x-coord, y-coord in a file, how can i modify it in order to have the following format? image label, tie point id, x-coord, y-coord,X, Y, Z (the last 3 are the 3D coordinates of course). In the 1.5.0 version preferably.

Thank you in advance

Marinos
« Last Edit: October 02, 2019, 05:22:57 PM by marinosvlachos »

marinosvlachos

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: extract image/pixel coordinates for every point of the sparse cloud
« Reply #7 on: October 02, 2019, 05:25:22 PM »
Hello Alexey i am coming back to this topic again after a few months since i was not able to resolve it. How can i modify the script you provided above in order to have the following format? image label, tie point id, x-coord, y-coord,X, Y, Z (the last 3 are the 3D coordinates of course). In the 1.5.0 version preferably. Is there a way? it will be very helpful for my research

Thank you in advance

Marinos

marinosvlachos

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: extract image/pixel coordinates for every point of the sparse cloud
« Reply #8 on: October 25, 2023, 01:59:00 PM »
Hello Alexey. Im coming back to this old topic since now I am using the latest version of metashape. I am trying to run the script provided by you in order to get every pixel coordinate of each point of the sparse cloud but in version 2.0.3 I get this error: 'NoneType' object has no attribute 'points'. What can I do about that?

Thank you in advance

SFL_Beda

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: extract image/pixel coordinates for every point of the sparse cloud
« Reply #9 on: November 13, 2023, 12:12:27 PM »
they did some breaking name changes in version 2.0:
Code: [Select]
...
• Renamed Chunk.point_cloud attribute to tie_points
• Renamed Chunk.dense_cloud attribute to point_cloud
...

So now you try to access the dense cloud which probably doesn't exist in your project (hence the NoneType) and which doesn't give you access to it's points anyway.

You will have to replace point_cloud with tie_points and maybe some other things as well.