Forum

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

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Add photos to the chunk
« Reply #15 on: November 17, 2017, 01:59:47 PM »
Hello magic,

I have updated the second part of the script - now it splits the cameras to the groups inside the single (active) chunk:
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:

empty = True
new_group = chunk.addCameraGroup()
finish = start + interval
new_group.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(chunk.cameras):
time = float(camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", "."))
time = time // 1 + (time  - time // 1) * 100 / 60

if start <= time < start + interval:
camera.group = new_group
empty = False

start += interval

if empty:
chunk.remove(new_group)
if start > limits[-1]:
break

print("script finished")
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Add photos to the chunk
« Reply #16 on: November 17, 2017, 03:41:47 PM »
it works well
thx Alexey

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Add photos to the chunk
« Reply #17 on: November 22, 2017, 12:36:30 PM »
Hello Alexey

Again some question to You , today i would like to disable several photos in my camera , iv got some script but with it i can only disabled or enabled all of my photos cant figured out how to do this, check my code
 to enable all of cameras:its works
Code: [Select]
import PhotoScan
doc = PhotoScan.app.document
chunk = doc.chunk

for camera in chunk.cameras:
if camera.enabled == False:
camera.enabled = True

print('cam dis')

and if i want to disabled every 5th camera in my cameras iv been tried those script:
Code: [Select]
import PhotoScan
doc = PhotoScan.app.document
chunk = doc.chunk
x = 0

for camera in chunk.cameras:
if camera.enabled == True:
camera.selected = False
x += 5
print('every 5th image is disabled ')

 and i have no error but no action as well ...
could you help with it pls


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Add photos to the chunk
« Reply #18 on: November 22, 2017, 01:06:52 PM »
Hello magic,

I can suggest the following:

Code: [Select]
import PhotoScan

chunk = PhotoScan.app.document.chunk
step = 5

for i in range(len(chunk.cameras)):
    camera = chunk.cameras[i]
    if not (i + 1) % step:
        camera.enabled = False
    else:
        camera.enabled = True
print("Every {:d} camera disabled.".format(step))
« Last Edit: November 22, 2017, 02:59:04 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Add photos to the chunk
« Reply #19 on: November 22, 2017, 02:36:20 PM »
Hi Alexey

Seems good but dsnt work, its something like no action inside , return print but any cameras picked in our list

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Add photos to the chunk
« Reply #20 on: November 22, 2017, 02:51:48 PM »
we have one action in Alexey this script going to disabled only one camera the last camera in cameras

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Add photos to the chunk
« Reply #21 on: November 22, 2017, 02:59:33 PM »
Hello magic,

I have forgotten the camera assignment:
Code: [Select]
    camera = chunk.cameras[i]See the updated script in the post above.
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Add photos to the chunk
« Reply #22 on: November 22, 2017, 03:31:48 PM »
Works great Alexey
Thx a lot :-)

NougierEva

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Add photos to the chunk
« Reply #23 on: November 23, 2017, 06:46:09 PM »
Hi,

I try also to add photos to my chunk but it doesn't work.
The error it's "Empty file list".
But in my folder there are many pictures and their extension is .jpg
So I don't understand what's wrong with my script.
I put my script in attached file.
So, If you have some times, can you help me to fixe my problem.
Thanks,
Eva Ingenior Student

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Add photos to the chunk
« Reply #24 on: November 23, 2017, 07:11:23 PM »
Hello Eva,

Actually in your script the part with the photo_list populating code is missing. It should be in between lines 40 and 41, similar to the example in this thread:
Code: [Select]
# Préciser le dossier contenant les images
path_photos = PhotoScan.app.getExistingDirectory("Specifier le chemin d'accès contenant les images: ")
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)
Best regards,
Alexey Pasumansky,
Agisoft LLC

NougierEva

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Add photos to the chunk
« Reply #25 on: November 24, 2017, 10:13:41 AM »
Thanks a lot, now it works.
I have another question to improve my script. Indeed, I would like to specify by the person who uses the script the coordinate system. In my script, it works, a window appears and asks to precise the coordinate system. Nevertheless, there is no coordinate system to be choosen except to search in a file in the computer. But how to access to all the coordinate system as like as the window when we go to the chunk and reference settings.

I hope it's clear, it's not always easy to explain in english the problem.
I put again in attached file my script reviewed.

Thanks again for your wonderful help,
Have a nice day,
Eva

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Add photos to the chunk
« Reply #26 on: November 24, 2017, 11:45:50 AM »
Hello Eva,

When you are using
Code: [Select]
crs = PhotoScan.app.getCoordinateSystem("Select Coordinate System", doc.chunk.crs)the compact coordinate system selection dialog appears with the recently used systems (the default system will be current coordinate system of the chunk (doc.chunk.crs), but clicking on "More..." option you will be able to open the common coordinate selection dialog, where you can find the required system from the list. Only clicking on Load button will suggest to locate the PRJ file in the file browser.
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Add photos to the chunk
« Reply #27 on: November 24, 2017, 12:45:40 PM »
Hi Alexey

Have another problem
Now i want to select enabled cameras (all in my chunk without disabled) and iv tried this

 
Code: [Select]
####
import PhotoScan
chunk = PhotoScan.app.document.chunk
for f in os.listdir(chunk.cameras):
   if re.match(camera.enabled = True, f):
       print f
######


import PhotoScan
chunk = PhotoScan.app/document.chunk
list_of_files = os.listdir(os.getcwd(chunk.cameras))
for each_file in list_of_files:
    if each_file.startswith(camera.enabled == True):
        print (each_file)

####
import PhotoScan
chunk = PhotoScan.app.document.chunk
chunk = doc.chunk
for i in os.listdirrange(len(chunk.cameras)):
    if os.path.isfile(os.path.join(path,i)) and camera.enabled == True in i:
        files.append(i)


No one of code above works , any suggestion Alexey ??

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Add photos to the chunk
« Reply #28 on: November 24, 2017, 12:50:43 PM »
Hello magic,

If you need to select the camera instances that are already added to the active chunk, you do not need to look for some files in the folders:

Code: [Select]
chunk = PhotoScan.app.document.chunk
for camera in chunk.cameras:
    if camera.enabled:
        camera.selected = True
    else:
        camera.selected = False
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Add photos to the chunk
« Reply #29 on: November 24, 2017, 12:57:29 PM »
Iv tried it before with small keyboard mistake ^^
works great my friend
thx a lot :-)