Forum

Author Topic: Adding Ground Control Points through Python API  (Read 9578 times)

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Adding Ground Control Points through Python API
« on: March 27, 2017, 09:53:21 AM »
Is it possible to add Ground Control Points through the Python API? I have tried doing the same through the GUI, but cannot figure out how to do the same through the API. Is there any documentation for the same?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #1 on: March 27, 2017, 10:55:28 AM »
Hello varadg,

Which information do you have for GCPs? XYZ geographic coordinates, 2D projections on individual images, anything else?
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #2 on: March 29, 2017, 09:44:14 AM »
Hi Alexey. We have ~5-8 LED markers in our survey area which we can identify easily in the images. For each of these, we have  global coordinates (latitude, longitude, altitude ASL).

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #3 on: March 29, 2017, 10:51:30 AM »
Hello varadg,

So what is suggested workflow you wish to be automated? PhotoScan doesn't support custom target detection, so if the markers that you are using are not supported for the automatic detection, PhotoScan wouldn't be able to identify them on the photos.
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #4 on: March 29, 2017, 11:30:26 AM »
Sorry, I should have been more clear. We can preprocess the images and identify the markers ourselves. So, I can pinpoint that some pixel location (X, Y) in image Z has geographical coordinates (Lat, Long, Alt). Having stored this information in a CSV file, does the API support importing this information and using it in processing?

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #5 on: March 30, 2017, 01:23:19 PM »
Hi Alexey. Any updates on this?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #6 on: March 30, 2017, 01:25:47 PM »
Hello varadg,

You can assign marker projections on the photos via Python API and also the marker 3D coordinates (to the Reference pane).
Would you be providing the list of the projections for each marker on every photo it is visible on?
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #7 on: March 30, 2017, 01:34:43 PM »
Yes, we will map the pixel location of the marker to the corresponding LLA coordinates in every picture that it is visible.

How will I need to provide this information for Agisoft to process it correctly?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #8 on: March 30, 2017, 01:51:29 PM »
Hello varadg,

Assuming that you have the following input file:
Code: [Select]
point 1,IMG_0001.JPG,100,200
point 1,IMG_0015.JPG,345,400
point 2,IMG_0023.JPG,786,211

You can load the projections using the following code:
Code: [Select]
import PhotoScan

def getMarker(chunk, label):
for marker in chunk.markers:
if marker.label == label:
return marker
return None

def getCamera(chunk, label):
for camera in chunk.cameras:
if camera.label == label:
return camera
return None

chunk = PhotoScan.app.document.chunk

path = "D:/input.txt"
with open(path, "rt") as input:
content = input.readlines()

for line in content:
m_label, c_label, x_proj, y_proj = line.split(",")

marker = chunk.getMarker(chunk, m_label)
if not marker:
marker = chunk.addMarker()
marker.label = m_label

camera = chunk.getCamera(chunk, c_label)
if not camera:
print(c_label + " camera not found in project")
continue

marker.projections[camera] = (float(x_proj), float(y_proj))

Best regards,
Alexey Pasumansky,
Agisoft LLC

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #9 on: October 14, 2019, 07:52:49 AM »
Thanks Alexey for this response (several years ago now..). With this workflow, would I need to provide the reference data for *every* image that a GCP is visible in? Or is it OK to provide the reference data for just a few (~5) images containing each GCP?

Thanks in advance for your input!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #10 on: October 15, 2019, 01:14:58 PM »
Hello dyoung,

5-6 projections would be enough, so you do not need to create them on every image, although, using all the available projections should improve the accuracy.
Best regards,
Alexey Pasumansky,
Agisoft LLC

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Adding Ground Control Points through Python API
« Reply #11 on: October 16, 2019, 02:40:35 AM »
OK, thanks!