Forum

Author Topic: batch processing aerial imagery  (Read 6324 times)

ptr

  • Newbie
  • *
  • Posts: 5
    • View Profile
batch processing aerial imagery
« on: November 08, 2016, 12:19:32 AM »
Dear all,

I am trying to use Photoscan to generate point clouds and ortho from over 1500 aerial images. The size of one image is almost 1GB, hence my plan is to divide the photos into chunks, process each chunk, allign chunks and export point clouds and orthos.

I tried to write a script to do everything, but there are some issues I cannot overcome. Below I attached what I came up so far. The script loads 2 photos only (as a test), aligns photos and creates a point cloud. The problem is that the coordinates are completely off, the whole area is upside down.

I'd appreciate any help.

Code: [Select]
import PhotoScan

app = PhotoScan.Application()
doc = PhotoScan.app.document

# Define: Camera calib file
CalibFile = "D:/cam.xml"

# Define: Orientation file
OrientationFile = "D:/Geolocation_DD_All_UTM.txt"

CoordinateSystem = PhotoScan.CoordinateSystem("EPSG::32611")

chunk = doc.addChunk()
chunk.label = "New_Chunk"
chunk.crs = CoordinateSystem

#create a list of photos to add to the chunk
AerialImageFiles = ["D:/G1505007_001_0001_rgbn.tif","D:/G1505007_001_0002_rgbn.tif"]

#add photos to chunk
chunk.addPhotos(AerialImageFiles)

cam = chunk.cameras[0]#PhotoScan.Camera()
cam.open(AerialImageFiles[0])

sensor = chunk.addSensor()
sensor.label = "MyCamera"
sensor.pixel_height=0.0056
sensor.pixel_width=0.0056
sensor.focal_length = 92
sensor.user_calib = PhotoScan.Calibration()
c = PhotoScan.Calibration()
c.load(CalibFile)
sensor.user_calib = c
sensor.fixed  = True

chunk.loadReference(OrientationFile, format="csv", delimiter=",")

#align
chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, keypoint_limit=80000, tiepoint_limit=80000, preselection=PhotoScan.GenericPreselection)
chunk.alignCameras()

chunk.buildDenseCloud(quality=PhotoScan.MediumQuality)

PK_2509

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: batch processing aerial imagery
« Reply #1 on: November 08, 2016, 12:27:34 PM »
Hi ptr,

I would say you need to set up at least 3 photos to define your coordinate system.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13642
    • View Profile
Re: batch processing aerial imagery
« Reply #2 on: November 08, 2016, 12:32:56 PM »
Hello ptr,

I think that the reason of the issue is related to the low number of images used: two reference points is not sufficient. Actually, I can suggest to test the script on the photos from two overlapping flight lines.

Also I assume that you can remove all lines after chunk.addPhotos() to chunk.loadReference, since PhotoScan automatically creates the calibration groups according to the EXIF data and fills up the information about pixel size and focal length automatically, if the EXIF information is sufficient.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ptr

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: batch processing aerial imagery
« Reply #3 on: November 09, 2016, 01:27:53 AM »
thank both of you!
simple change to 4 photos in two different flightlines worked.

antonex

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: batch processing aerial imagery
« Reply #4 on: December 14, 2016, 08:11:14 PM »
Hi,

I have the same task as ptr, processing over 700 aerial images. Ptr's script works, but somehow it does not load the camera calibration .xml file and the pixel_height and pixel_width. Is there maybe  something still wrong with the script? Or am I doing something wrong.

I use the exact same script as posted here, the .xml file I made by adding the camera calibration details manually in agisoft and then saving them as .xml.


hope someone can help

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13642
    • View Profile
Re: batch processing aerial imagery
« Reply #5 on: December 14, 2016, 08:19:34 PM »
Hello antonex,

Have you tried to load the XML file via Camera Calibration window?

If it also fails, then the resolution of images and values in the calibration file may mismatch.
Best regards,
Alexey Pasumansky,
Agisoft LLC

antonex

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: batch processing aerial imagery
« Reply #6 on: December 14, 2016, 09:13:09 PM »
Hi Alexy,

Thank you for the quick reply.

When I import the .xml file through the Camera Calibration window, there is no problem.
If this script works but not in my case, does it mean my calibration values are not correct?




Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13642
    • View Profile
Re: batch processing aerial imagery
« Reply #7 on: December 14, 2016, 09:19:30 PM »
Hello antonex,

You can try to execute the lines one by one in the Console pane, to see if the calibration is loaded to the PhotoScan.Calibration() class variable, or use print() statements in the original script to output the values from calibration of loaded user_calib.
Best regards,
Alexey Pasumansky,
Agisoft LLC

antonex

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: batch processing aerial imagery
« Reply #8 on: December 14, 2016, 10:18:51 PM »
Hi Alexy,

Thanks again, when I print the "sensor.pixel_height" and "sensor.pixel_height" it gives the correct values. Printing the sensor.user_calib gives a long number that changes each time the script is run: 0x0000000011AE3990.

So it does load the pixel sizes at least. When I go to the Camera Calibration window after I have run the script, it does not show the updated calibration values from the script. Maybe that is the reason I thought the script wasn't working.

Just to be sure, is it possible to print the values of the .xml file in the console? Since they are not defined as variables in the script itself.

Thanks a lot!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13642
    • View Profile
Re: batch processing aerial imagery
« Reply #9 on: December 14, 2016, 11:47:32 PM »
Hello antonex,

sensor.user_calib is a containe of the calibration values, so you need to print sensor.user_calib.f, for example.

Best regards,
Alexey Pasumansky,
Agisoft LLC

antonex

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: batch processing aerial imagery
« Reply #10 on: December 15, 2016, 10:13:45 PM »
Hi Alexy,

I have 2 final questions.

- I printed all the calibration variables and they are all imported into Agisoft, but when I print (sensor.user_calib.width) or (sensor.user_calib.height) it gives the value zero. Is this the wrong command to print them, or I am doing something wrong again?

- I need photo alignment based on "Reference". The script uses preselection=PhotoScan.GenericPreselection). Do i need to change this line to Reference, or is this the function on align the photos on references?

Thanks a lot.


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13642
    • View Profile
Re: batch processing aerial imagery
« Reply #11 on: December 16, 2016, 12:00:51 PM »
Hello antonex,

You need to specify sensor.width and sensor.height manually before assigning user_calib:
Code: [Select]
sensor.height = c.height
sensor.width = c.width
sensor.user_calib = c

preselection = PhotoScan.ReferencePreselection should work as Reference preselection option from GUI.
« Last Edit: December 19, 2016, 08:42:46 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

antonex

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: batch processing aerial imagery
« Reply #12 on: December 19, 2016, 08:17:32 PM »
Hi Alexey,

I have been reading and trying out things, but I could not get the script calibrated. When I run the script and make "Generate Report" its says Focus length and pixel size are unknown. It is a really simple script and I just can't figure out where it goes wrong. I need the camera calibrated because the height of the pointcloud and photo "altitude" is now randomly (I think) generated and not referenced. It is way off.

The script is still the same, i have removed the long file locations. I uploaded the calibration file as well.

Code: [Select]
import PhotoScan

app = PhotoScan.Application()
doc = PhotoScan.app.document

# Define: Camera calib file
CalibFile = "calibration_2.xml"

# Define: Orientation file
OrientationFile = "reference.txt"

CoordinateSystem = PhotoScan.CoordinateSystem("EPSG::28992")

chunk = doc.addChunk()
chunk.label = "New_Chunk"
chunk.crs = CoordinateSystem

#create a list of photos to add to the chunk
AerialImageFiles = ["photos_here.tiff"]

#add photos to chunk
chunk.addPhotos(AerialImageFiles)

cam = chunk.cameras[0]#PhotoScan.Camera()
cam.open(AerialImageFiles[0])

sensor = chunk.addSensor()
sensor.label = "MyCamera"
sensor.pixel_height = 0.006
sensor.pixel_width = 0.006
sensor.focal_length = 100.5
sensor.height = 11310
sensor.width = 17310


sensor.user_calib = PhotoScan.Calibration()
c = PhotoScan.Calibration()
c.load(CalibFile)
sensor.user_calib = c
sensor.fixed  = True

chunk.loadReference(OrientationFile, format="csv", delimiter="\t")

print(sensor.user_calib.fx)
print(sensor.user_calib.fy)
print(sensor.user_calib.cx)
print(sensor.user_calib.cy)
print(sensor.pixel_height)
print(sensor.pixel_width)
print(sensor.focal_length)
print(sensor.fixed)



#align
chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, keypoint_limit=80000, tiepoint_limit=80000, preselection=PhotoScan.ReferencePreselection)
chunk.alignCameras()

chunk.buildDenseCloud(quality=PhotoScan.LowQuality)


The pointcloud is generated, everything works, but the focal length/pixel size has to be loaded for Agisoft to give the correct z cooridnates for entire  point cloud.

Is there something I am missing?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13642
    • View Profile
Re: batch processing aerial imagery
« Reply #13 on: December 19, 2016, 08:44:59 PM »
Hello antonex,

In your latest post I don't see that you assign the sensor to any camera. Like
Code: [Select]
for camera in chunk.cameras:
      camera.sensor = sensor

Also which version of PhotoScan you are using? Latest version of PhotoScan Pro 1.2.6 doesn't have separate fx and fy methods for the calibration.
Best regards,
Alexey Pasumansky,
Agisoft LLC

antonex

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: batch processing aerial imagery
« Reply #14 on: December 20, 2016, 04:55:34 PM »
Hi Alexey,

Thanks for all the help, I updated agisoft and edited the code, the calibration is fixed. It works!

A side question, is there a easy way to load all ".tiff" imagery into agisoft from a folder?

In this discussion, they add .tiff based on changes of x of the file's name.
http://www.agisoft.com/forum/index.php?topic=5706.0

Code: [Select]
startphoto=1700
endphoto=1750

for x in range(startphoto, endphoto + 1):
     chunk.addPhotos(['/Volumes/arc_01/FIELD_DATA/SFM/EOSS/PHOTOS_EOSS_20160330/106D800E/TIFF/DSC_%s.tiff' % x])
     chunk.importMasks(path='/Volumes/arc_01/FIELD_DATA/SFM/EOSS/PHOTOS_EOSS_20160330/106D800E/TIFF/DSC_%s_mask.png' % x,method='file',operation='union',tolerance=10)

The name's doesn't matter in my case, I need all the .tiff loaded disregard of filename. Changing the imagery location to "*.tiff" doesn't seem to work.