Community Forum

Author Topic: Add photos to the chunk  (Read 1746 times)

magic

  • Newbie
  • *
  • Posts: 35
    • View Profile
Add photos to the chunk
« on: November 13, 2017, 04:31:56 PM »
hello
I'm trying to add whole folder to the Photoscan , i have 1k5 fotos and i dont know how to do it , i would like to load them all from my directory f:/photos and create several chunks (sort my fotos automatically by the time every 5min new repository(how we can do it with python script) or chunk or camera doesnt matter - I have 30minutes work inside thats mean i want 6 folders, each 5min works inside ), i would like to use python to go with my path direct to my repository and get fotos wivouth using a mouse,
will show u my code


to use date and time need to use exif -->>  camera.photo.meta['Exif/DateTimeOriginal']

import os, PhotoScan
doc = PhotoScan.app.document
chunk = doc.addChunk()
chunk.label = "New Chunk initial"

# Ajout de photos -add photos 1st chunk
path_photos = PhotoScan.app.getExistingDirectory("main folder:")
image_list = os.listdir(path_photos)
photo_list = list()
« Last Edit: November 16, 2017, 02:53:22 PM by magic »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 7813
    • View Profile
Re: Add fotos to the chunk
« Reply #1 on: November 13, 2017, 05:16:45 PM »
Hello magic,

I could suggest something like the following:
Code: [Select]
import os, PhotoScan

doc = PhotoScan.app.document
chunk = doc.addChunk()

path_photos = PhotoScan.app.getExistingDirectory("Dosier images avec Exif:")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
if photo.lower() in ["jpg", "jpeg", "tif", "tiff"]:
photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list)
This script should add the images from the user-defined folder to the new chunk (supported types are defined in the script body).
Best regards,
Alexey Pasumansky,
AgiSoft LLC

magic

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Add fotos to the chunk
« Reply #2 on: November 13, 2017, 06:09:49 PM »
still cant load those photos , now iv got this :


2017-11-13 15:50:43 AddPhotos
2017-11-13 15:50:43 Finished processing in 0 sec (exit code 0)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-48-74982a19c57e> in <module>()
     10         if photo.lower() in ["jpg", "jpeg", "tif", "tiff"]:
     11                 photo_list.append("/".join([path_photos, photo]))
---> 12 chunk.addPhotos(photo_list)
     13

RuntimeError: Empty file list



Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 7813
    • View Profile
Re: Add fotos to the chunk
« Reply #3 on: November 13, 2017, 06:10:57 PM »
Hello magic,

What's in path_photos variable and image_list?
Best regards,
Alexey Pasumansky,
AgiSoft LLC

magic

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Add fotos to the chunk
« Reply #4 on: November 13, 2017, 06:43:46 PM »
thats the code

: import os, PhotoScan

doc = PhotoScan.app.document
chunk = doc.addChunk()

path_photos = PhotoScan.app.getExistingDirectory("F:\temp\photo")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
   if photo.lower() in ["jpg", "jpeg", "tif", "tiff"]:
      photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 7813
    • View Profile
Re: Add fotos to the chunk
« Reply #5 on: November 13, 2017, 07:21:26 PM »
Oh, I think I've got a mistake in the code, there should be:
Code: [Select]
if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
Best regards,
Alexey Pasumansky,
AgiSoft LLC

magic

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Add fotos to the chunk
« Reply #6 on: November 14, 2017, 11:20:28 AM »
Hi Alexey

Thx its works now with that code i can load the photos and they go to Chunk and cameras folder all of them, did i can divide them and get them into this chunk but to several cameras (not into one) , i would like to import them and sort it by time

     etc...
Code: [Select]
import os, PhotoScan
doc = PhotoScan.app.document
chunk = doc.addChunk()
chunk.label = "New Chunk initial"

# Ajout de photos -add photos 1st chunk
path_photos = PhotoScan.app.getExistingDirectory("main folder:")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list)
print("- Photos ajoutées")


time_table = list()  ###traitement par temps avec exif-DateTimeOriginal
for camera in chunk.cameras:
time = camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", ".")
time = float(time)
time = time // 1 + (time  - time // 1) * 100 / 60
time_table.append(time)

time_table.sort()
limits = (time_table[0], time_table[-1])
interval = 10 / 60. ##### divisoin par X minutes choisis
start = limits[0]
while True:     #####condition traitement par temps si vrais
##### ajoute des photos trier par l'heure + creation chunk pour chaque morceux
new_chunk = chunk.copy()
finish = start + interval
new_chunk.label = "{:d}:{:d} - {:d}:{:d}".format(int(start // 1), int((start - start // 1) * 60),
int(finish // 1), int((finish - finish // 1) * 60))
for camera in list(new_chunk.cameras): ######for avec d temps exif
time = float(camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", "."))


break

print("script finished")
« Last Edit: November 16, 2017, 02:55:37 PM by magic »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 7813
    • View Profile
Re: Add fotos to the chunk
« Reply #7 on: November 14, 2017, 02:34:04 PM »
Hello magic,

Can you post the contents of camera.photo.meta - at least those tags that should be used to split the cameras. Also specify, if you need to have several camera groups in the same chunk or several chunks?
Best regards,
Alexey Pasumansky,
AgiSoft LLC

magic

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Add fotos to the chunk
« Reply #8 on: November 14, 2017, 04:15:02 PM »
Hi Alexey

In meta iv got something like this
Code: [Select]
camera.photo.meta
Out[62]: 2017-11-14 13:42:02 {'Exif/DateTime': '2017:10:20 08:02:47', 'Exif/DateTimeOriginal': '2017:10:20 08:02:47', 'Exif/ExposureTime': '0.00625', 'Exif/FNumber': '0', 'Exif/FocalLength': '0', 'Exif/FocalLengthIn35mmFilm': '0', 'Exif/ISOSpeedRatings': '10000', 'Exif/Make': 'SONY', 'Exif/Model': 'ILCE-5100', 'Exif/Orientation': '1', 'Exif/Software': 'ILCE-5100 v3.10', 'File/ImageHeight': '4000', 'File/ImageWidth': '6000', 'System/FileModifyDate': '2017:10:20 08:02:46', 'System/FileSize': '7897088'}

And will be nice to split it into several chunks


Thx a lot Alexey but my python skills are very bad


thats my code for now :

Code: [Select]
import os, PhotoScan

doc = PhotoScan.app.document
chunk = doc.addChunk()
chunk.label = "New Chunk"




# Ajout de photos -add photos 1st chunk
path_photos = PhotoScan.app.getExistingDirectory("main folder:")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list)
print("- Photos ajoutées")




chunk = doc.addChunk()
chunk.label = "New Chunk 1"

# Ajout de photos - add photos 2nd chunk
path_photos = PhotoScan.app.getExistingDirectory("main folder:")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list)
print("- Photos ajoutées")

print(">>> Script terminé <<<")

magic

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Add fotos to the chunk
« Reply #9 on: November 15, 2017, 12:49:24 PM »
Hello Alexey

Any suggestion how to do it ?? I'm stuck can't figured out how i can do this
« Last Edit: November 15, 2017, 03:43:52 PM by magic »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 7813
    • View Profile
Re: Add fotos to the chunk
« Reply #10 on: November 15, 2017, 06:31:57 PM »
Hello magic,

I can suggest something as following:


Code: [Select]
doc = PhotoScan.app.document
chunk = doc.addChunk()
chunk.label = "New Chunk"

# Ajout de photos -add photos 1st chunk
path_photos = PhotoScan.app.getExistingDirectory("main folder:")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list)
print("- Photos ajoutées")


time_table = list()
for camera in chunk.cameras:
time = camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", ".")
time = float(time)
time = time // 1 + (time  - time // 1) * 100 / 60
time_table.append(time)

time_table.sort()
limits = (time_table[0], time_table[-1])
interval = 5 / 60. #five minute interval
start = limits[0]

while True:

new_chunk = chunk.copy()
finish = start + interval
new_chunk.label = "{:d}:{:d} - {:d}:{:d}".format(int(start // 1), int((start - start // 1) * 60),
int(finish // 1), int((finish - finish // 1) * 60))#####
for camera in list(new_chunk.cameras):
time = float(camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", "."))
time = time // 1 + (time  - time // 1) * 100 / 60

if time < start:
new_chunk.remove(camera)
elif time >= start + interval:
new_chunk.remove(camera)

start += interval
if not len(new_chunk.cameras):
doc.remove(new_chunk)
if start > limits[-1]:
break

print("script finished")

Best regards,
Alexey Pasumansky,
AgiSoft LLC

magic

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Add photos to the chunk
« Reply #11 on: November 16, 2017, 12:07:31 PM »
Hello Alexey

Thx a lot man U are the best its works !!!!!

magic

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Add photos to the chunk
« Reply #12 on: November 17, 2017, 11:48:16 AM »
Hello Alexey

Its me again , iv been tried to modify this code to get same result but now with the cameras

Code: [Select]
import os, PhotoScan
doc = PhotoScan.app.document
chunk = doc.addChunk()
chunk.label = "New Chunk initial"

# Ajout de photos -add photos 1st chunk
path_photos = PhotoScan.app.getExistingDirectory("main folder:")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list)
print("- Photos ajoutées")


time_table = list()  ###traitement par temps avec exif-DateTimeOriginal
for camera in chunk.cameras:
time = camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", ".")
time = float(time)
time = time // 1 + (time  - time // 1) * 100 / 60
time_table.append(time)

time_table.sort()
limits = (time_table[0], time_table[-1])
interval = 10 / 60. ##### divisoin par X minutes choisis
start = limits[0]

while True:     #####condition traitement par temps si vrais
##### ajoute des photos trier par l'heure + creation chunk pour chaque morceux
new_cameras = cameras.copy()
finish = start + interval
new_camera.label = "{:d}:{:d} - {:d}:{:d}".format(int(start // 1), int((start - start // 1) * 60),
int(finish // 1), int((finish - finish // 1) * 60))
for camera in list(new_cameras.cameras): ######for avec d temps exif
time = float(camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", "."))
time = time // 1 + (time  - time // 1) * 100 / 60

if time < start: ####
new_cameras.remove(camera)
elif time >= start + interval:
new_cameras.remove(camera)

start += interval
if not len(new_cameras.cameras):
doc.remove(new_cameras)
if start > limits[-1]:
break

print("script finished")

what i have to modify overhere Alexey??

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 7813
    • View Profile
Re: Add photos to the chunk
« Reply #13 on: November 17, 2017, 12:01:37 PM »
Hello magic,

Do you mean creation of the camera groups in the Workspace pane?
Best regards,
Alexey Pasumansky,
AgiSoft LLC

magic

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Add photos to the chunk
« Reply #14 on: November 17, 2017, 12:17:46 PM »
like with code before benn loading photos by time to new chunks
chunk1
chunk2
chunk3
etc...
Code: [Select]
import os, PhotoScan
doc = PhotoScan.app.document
chunk = doc.addChunk()
chunk.label = "New Chunk initial"

# Ajout de photos -add photos 1st chunk
path_photos = PhotoScan.app.getExistingDirectory("main folder:")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list)
print("- Photos ajoutées")


time_table = list()  ###traitement par temps avec exif-DateTimeOriginal
for camera in chunk.cameras:
time = camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", ".")
time = float(time)
time = time // 1 + (time  - time // 1) * 100 / 60
time_table.append(time)

time_table.sort()
limits = (time_table[0], time_table[-1])
interval = 10 / 60. ##### divisoin par X minutes choisis
start = limits[0]

while True:     #####condition traitement par temps si vrais action
##### ajoute des photos trier par l'heure + creation chunk pour chaque morceux
new_chunk = chunk.copy()
finish = start + interval
new_chunk.label = "{:d}:{:d} - {:d}:{:d}".format(int(start // 1), int((start - start // 1) * 60),
int(finish // 1), int((finish - finish // 1) * 60))
for camera in list(new_chunk.cameras): ######for avec d temps exif
time = float(camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", "."))
time = time // 1 + (time  - time // 1) * 100 / 60

if time < start:
new_chunk.remove(camera)
elif time >= start + interval:
new_chunk.remove(camera)

start += interval
if not len(new_chunk.cameras):
doc.remove(new_chunk)
if start > limits[-1]:
break

print("script finished")


and iv tried now to do same but to load it to new cameras or groupe
something like :
chunk
     -cameras1
     -cameras2
     -cameras3
 etc