Forum

Author Topic: Problems Import photos into chunks from script  (Read 13452 times)

tforward2

  • Newbie
  • *
  • Posts: 17
    • View Profile
Problems Import photos into chunks from script
« on: November 18, 2014, 01:32:58 AM »
From the GUI if I go:

>Add Chunk > Add Photos > Select Photos > and Import.

Photos come in fine "Chunk 1 (12 Cameras) [R]" and the blue point in the view window shows up where the points reside.
If I run align photos it works fine and I can see the points in the view window.

I'm trying to to this very step from a script, it does not work.

The cameras come in however they now say "Chunk 1 (12 Cameras)" without the [R] what does this mean?
Also in the view window the blue points are missing, and only appear if I goto:

Ground Control > Import EXIF

If I then perform Align Photos on these it runs through it all but with no real result. Log file below.

What I'm I missing?

projection is WGS84

Code: [Select]
import PhotoScan
import glob

app = PhotoScan.Application()
doc = PhotoScan.app.document
hint = r"Select the JSON file that holds the chunk, images"

# create chunk


# SET COORDINATE SYSTEM
print("---Settings coordinate system...")
# init coordinate system object
CoordinateSystem = PhotoScan.CoordinateSystem()
if not(CoordinateSystem.init("EPSG::4326")):
   app.messageBox("Coordinate system EPSG code not recognized!")
# define coordinate system in chunk

chunk = PhotoScan.Chunk()
chunk.label = "New_Chunk"
doc.chunks.add(chunk)
chunk.crs = CoordinateSystem
chunk.projection = CoordinateSystem

AerialImageFiles = glob.glob(r"G:\Seagate\2014-09-23_4\New folder\*.jpg")

# LOAD CAMERA CALIBRATION
print("---Loading camera calibration...")
# we need to open first image to define image size
cam = PhotoScan.Camera()
cam.open(AerialImageFiles[0])
# Load sensor calib
user_calib = PhotoScan.Calibration()
# build sensor object
sensor = PhotoScan.Sensor()
sensor.label = "MyCamera"
sensor.width = cam.width
sensor.height = cam.height
sensor.fixed = False
sensor.user_calib = user_calib
chunk.sensors.add(sensor)

# LOAD AERIAL IMAGES
print("---Loading images...")
# load each image
for FileName in AerialImageFiles:
   #print("File: " + FileName)
   cam = PhotoScan.Camera()
   if not(cam.open(FileName)):
      app.messageBox("Loading of image failed: " + FileName)
   cam.label = cam.path.rsplit("/", 1)[1]
   cam.sensor = sensor
   chunk.cameras.add(cam)

# LOAD CAMERA ORIENTATIONS
print("---Loading initial photo orientations...")
PhotoScan.app.update()

Quote
---Settings coordinate system...
---Loading camera calibration...
---Loading images...
---Loading initial photo orientations...

Finished adding chunks.
Detecting points...
photo 1: 18391 points
photo 2: 18434 points
photo 3: 18144 points
photo 4: 17929 points
photo 5: 17945 points
photo 6: 18034 points
photo 7: 17942 points
photo 8: 18558 points
photo 9: 18618 points
photo 10: 19493 points
photo 11: 19844 points
photo 12: 20671 points
points detected in 17.863 sec
Selecting pairs...
56192 matches found in 0.781 sec
60 of 66 pairs selected in 0.024 sec
Matching points...
351726 matches found in 7.54 sec
setting point indices... 46083 done in 0.004 sec
removed 1288 multiple projections
removed 3 points
generated 46080 tie points, 3.27598 average projections
finished matching in 26.236 sec
Estimating scene structure...
group size: 12 photos
finished sfm in 0.807 seconds
Finished processing in 27.055 sec (exit code 1)
>>>

tforward2

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Problems Import photos into chunks from script
« Reply #1 on: November 18, 2014, 10:47:22 PM »
I figured it out:

Within the GUI when you Select > Add Photos

It does a couple things in the background.

1 - It builds Camera Orientation information from the EXIF data which is what you see on the Ground Control Tab.
2 - It builds Camera Calibration information from the EXIF data which is what you see on the Tools > Camera Calibration window
3 - And adds the actual images to the chunk.

When you try to "Add photos" via python you have to provide it was both the Camera Orientation and Camera Calibration files first. If you don't it won't work as you expect it to.

If this information could be added to the API that would be great!

kBarra

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Problems Import photos into chunks from script
« Reply #2 on: December 03, 2014, 12:37:42 AM »
Is this a bug?

Surely the API has not regressed so that I have to build the sensor and calibration data to add an image in a chunk. Where before only the image path was needed as long as the meta data was with the image.


tforward, would you mind going into more detail about how you got around this problem?

tforward2

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Problems Import photos into chunks from script
« Reply #3 on: December 30, 2014, 09:37:03 PM »
Note this is for the PhotoScan 1.0.4 build 1847 (64 bit). Have not tested it with hte new API so may no longer work.

Code: [Select]
if json_path != "":
print ("\nImport JSON chunk dictionary...")
print (json_path)
with open(json_path, 'r') as fp:
chunk_dict = json.load(fp)
else:
print ("Skipped importing JSON file.")

align_photos = app.getString(label="Align Photos: yes/no", value="yes")

def json_filepath_generator():
for key, values in chunk_dict.items():
yield key, values

def load_chunks_from_json():
chuck_gen = json_filepath_generator()
app.messageBox("Note: Adding chunks takes time... please be patient.")
print ("\nStart adding chunks...\n")
try:
while True:
chuck_list = next(chuck_gen)
cam = PhotoScan.Camera()

#Open One Path to get info from
cam.open(chuck_list[1][0])
# Load sensor calib
user_calib = PhotoScan.Calibration()
if not(user_calib.load(camera_calibration_file)):
app.messageBox("Loading of calibration file failed!")
sys.exit(1)
# build sensor object
sensor = PhotoScan.Sensor()
sensor.label = "Nikon D800E"
sensor.width = cam.width
sensor.height = cam.height
sensor.fixed = False
sensor.user_calib = user_calib
#New chunk
new_chunk = PhotoScan.Chunk()
new_chunk.crs = crs
new_chunk.projection = crs

new_chunk.label = "Chunk_{}".format(chuck_list[0])
print ("Adding chunk: " + str(new_chunk.label))
new_chunk.sensors.add(sensor)
doc.chunks.add(new_chunk)
for path in chuck_list[1]:
cam = PhotoScan.Camera()
if not(cam.open(path)):
app.messageBox("Loading of image failed: " + path)
cam.label = os.path.basename(path)
cam.sensor = sensor
new_chunk.cameras.add(cam)
new_chunk.enabled = True
new_chunk.ground_control.projection = crs
new_chunk.ground_control.crs = crs
new_chunk.ground_control.loadExif()
new_chunk.ground_control.apply()
print ("Chunk_{} added...".format(chuck_list[0]))
app.update()

#End of item in the Generator.
except StopIteration:
save_project()

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Problems Import photos into chunks from script
« Reply #4 on: December 30, 2014, 09:58:25 PM »
In the version 1.1.0 it is possible to use chunk.addPhotos(photo_list) method, where photo_list is a list containting paths to the images.
Best regards,
Alexey Pasumansky,
Agisoft LLC