Forum

Author Topic: Export number projection of markers  (Read 2972 times)

PhotogrammetryUser

  • Newbie
  • *
  • Posts: 6
    • View Profile
Export number projection of markers
« on: August 21, 2019, 05:16:30 PM »
Hello the community, I'm discovering the API of Photoscan and I'm searching, how can I get the number of projections for each marker in my chunks? (is it possible ?) Thanks for your help  :D

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Export number projection of markers
« Reply #1 on: August 21, 2019, 07:58:29 PM »
Hello,

You can use the following simple code to output the marker label and corresponding number of projections in the active chunk of the currently opened document:
Code: [Select]
for marker in Metashape.app.document.chunk.markers:
    print(marker.label, len(marker.projections.keys()))
Best regards,
Alexey Pasumansky,
Agisoft LLC

PhotogrammetryUser

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export number projection of markers
« Reply #2 on: August 22, 2019, 10:55:58 AM »
Hey Alexey! Great that's what I was looking for ! Thanks a lot ! And I have a last question, I search in the forum but I don't find my response in meter : I want to export the "error (m)" of each of my marker in each images, is it possible? I found the script for the "error pixel" only!

Thanks for your help !
« Last Edit: August 22, 2019, 10:58:42 AM by PhotogrammetryUser »

PhotogrammetryUser

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export number projection of markers
« Reply #3 on: August 22, 2019, 11:42:41 AM »
You can find here my part of code :
Some informations :

tab_test is a table in which I stocked some markers that I want to get their errors in meters in each camera.


Code: [Select]
for marker in chunk.markers:
                print(marker.label)
               
                if marker.label in tab_test:
                    for camera in marker.projections.keys():
                       
                        print(camera)
                   
                        if not camera.transform:
                            continue

                        total = (0, 0)
                        est = chunk.transform.matrix.mulp(marker.position)
                        ref = marker.reference.location
                        print("EST :",est)
                        print("REF :",ref)
                        error = (est - ref).norm()  # The .norm() method gives the total error. Removing it gives X/Y/Z error
                        print("ERROR :",error)
                        total = (total[0] + error**2, total[1] + 1)
                        print("TOTAL :",total)
                        value_err_m = math.sqrt(total[0] / total [1])
                        print("VALEUR ERREUR METRE :",value_err_m)
                else:
                    pass

With this code, for each marker, I get the same erreur meter in each camera

Thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Export number projection of markers
« Reply #4 on: August 22, 2019, 12:43:38 PM »
Hello!

In case your project is georeferenced in geographic/projected coordinate system you need to define "ref" variable as:
ref = chunk.crs.unproject(marker.reference.location)
Thus both est and ref values would be in geocentric coordinate system and you can calculate the error as a norm of the connecting vector.

The error calculated in such way, however, is not connected to the cameras - it is just difference between 3D locations of the measured point location and estimated by Metashape.
Best regards,
Alexey Pasumansky,
Agisoft LLC

PhotogrammetryUser

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export number projection of markers
« Reply #5 on: August 22, 2019, 01:04:45 PM »
" -->  it is just difference between 3D locations of the measured point location and estimated by Metashape <--"

So I just can get 1 value of error (m)  by target for all chunk, but I can't get 1 value of error (m) by target by image, that's it ? 

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Export number projection of markers
« Reply #6 on: August 22, 2019, 01:45:38 PM »
Hello PhotogrammetryUser,

Can you please specify, what you consider to be an error in meters for the marker per image?

For example, you can intersect the ray coming through the camera center and corresponding marker projection with the available surface (DEM, mesh, dense cloud) and calculate the difference between this intersecting point with 3D marker location.
Best regards,
Alexey Pasumansky,
Agisoft LLC

PhotogrammetryUser

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export number projection of markers
« Reply #7 on: August 22, 2019, 02:43:37 PM »
Yes no problem !
For example, with this code, I can get the "error px" for each marker in each image.

Code: [Select]
for camera in marker.projections.keys():
                   
                    if not camera.transform:
                        continue
                   

                    proj = marker.projections[camera].coord
                    print("proj :",proj)
                   
                    reproj = camera.project(marker.position)
                    error = (proj - reproj).norm()
                    total = (total[0] + error**2, total[1] + 1)
                    value_err_px = math.sqrt(total[0] / total [1])


And I'm looking for to get the error but in (m). In the GUI of Photoscan, it's where you have the list of markers, you have differents columns (Markers, X(m), Y(m), 2(m), Accuracy(m), Error(m), Projections, Error(pix)"

Let me know if you understand me :)

           
                   

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Export number projection of markers
« Reply #8 on: August 22, 2019, 03:08:54 PM »
See on page 71 of Metashape Pro manual:

Quote
Error (m) - residual error per coordinate or in 3D space. That is distance between the input (source)and estimated positions of the marker.
Error  (pix)  -  root  mean  square  reprojection  error  for  the  marker  calculated  over  all  photos  where marker is visible.

Error in meters is a distance between measured and estimated location of the marker. The 3D point location cannot be estimated based on the single projection, since it is the ray and not the point.
Best regards,
Alexey Pasumansky,
Agisoft LLC

PhotogrammetryUser

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export number projection of markers
« Reply #9 on: August 22, 2019, 05:24:55 PM »
Yes indeed I was wrong in what I wanted to do: I can only have one residue in m per point for a whole chunk but several residues px of a point. What joins what you say to me indeed! So I finished what I was trying to do :) Thanks Alexey for your help an your experience !