Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - magic

Pages: 1 2 [3] 4
31
Python and Java API / Re: Export Undistort cameras to new folder
« on: December 08, 2017, 07:20:48 PM »
I figured it out :-)

Code: [Select]
import PhotoScan
import os, sys
os.mkdir("F:\\Ps\\res_photo\\undisorted_done")
os.mkdir("F:\\Ps\\res_photo\\undisorted_done\\HD") #creation new directory 1st-undisorted_done, 2nd HD
my_dir = ("F:\\Ps\\res_photo\\undisorted_done\\HD")
chunk = doc.chunk #active chunk

for camera in chunk.cameras:
     #camera = chunk.cameras[0]
    currentCameraImage = camera.photo.image()
    calibration = camera.sensor.calibration
    undistortedCameraImage = currentCameraImage.undistort(calibration, True, True)
    undistortedFullImageName = os.path.split(camera.photo.path)[-1]
    undistortedImageName = os.path.splitext(undistortedFullImageName)[0]
    save_img = os.path.join(my_dir,os.path.basename(undistortedImageName) + '_.jpg')
    undistortedCameraImage.save(save_img)

thats works

32
Python and Java API / Export Undistort cameras to new folder
« on: December 08, 2017, 04:12:36 PM »
Hi Alexey

Iv been trying to export and undistort my cameras to new folder with some python script , i found few old scripts but they dont work , Iv tried to modify them without any results positive, that my code
 
Code: [Select]
import PhotoScan
import os, sys
os.mkdir("F:\\Ps\\res_photo\\undisorted_done")
os.mkdir("F:\\Ps\\res_photo\\undisorted_done\\HD") #creation new directory 1st-undisorted_done, 2nd HD
my_dir = ("F:\\Ps\\res_photo\\undisorted_done")
chunk = doc.chunk #active chunk
camera = chunk.cameras[0]
image = camera.photo.image()
calib = camera.sensor.calibration
undist = image.undistort(calib,True, True)
save_img = os.path.join(my_dir)
undist.save(save_img) #path should be defined
Have an error
   Out[32]: 2017-12-08 15:04:43 False

How we can modify it Alexey ? I want to Undisort (without calibration) my cameras and safe them into new folders 'undisorted_done' and 'HD' how we can do this with python script , what i have to modify??

33
Python and Java API / Re: Add photos to the chunk
« on: November 28, 2017, 04:37:31 PM »
I will try it Alexey thx

34
Python and Java API / Re: Add photos to the chunk
« on: November 28, 2017, 03:34:40 PM »
Hello Alexey

iv added 3 scripts
its looks like this:
Custom(and my 3 scripts)
                                          -test
                                          -test1
                                          -selection desactiver

when i choose 1st one send print to console but window stay off, no reaction at click
and 2 others nothing happens in console and window stay off to

but when i restart my photoscan all 3 windows are open, and i cant do any action before i close them

35
General / Re: Custom batch process in menu on startup
« on: November 28, 2017, 02:15:15 PM »
Hello

Anybody can help me maybe here, i have a problem with Custom button , iv added it to  C:Users/......./script and my button vbeen created in my photoscan menu, but i cant open it when i go to >> Custom>>(myscript)Selectioner desactiver , there is no callback from ... nothing happens,  my python skill are low maybe someone will help :

there is my code
Code: [Select]
import os
import PhotoScan
from tkinter import*

def selec():
    doc = PhotoScan.app.document
    chunk = doc.chunk

def center_window(width=500, height=400):
    # hoteur et largeur notre fenetre
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()

    # calcule positionement notre fenetre sur ecran
    x = (screen_width/2) - (width/2)
    y = (screen_height/2) - (height/2)
    root.geometry('%dx%d+%d+%d' % (width, height, x, y))





root = Tk()
center_window(500, 400)
root.title('selection images')

###### premiere boutton - selection les images activer
def callback():
    chunk = PhotoScan.app.document.chunk
    for camera in chunk.cameras:
        if camera.enabled:
            camera.selected = True
        else:
            camera.selected = False

but = Button(root,bg='yellow',width =20, height =2, bd =2, relief =SOLID, text='selection active', command=callback)

but.pack()

######## partie liaison avec photoscan
PhotoScan.app.addMenuItem("Custom/Selection desactiver", selec)
root.mainloop()

iv tried few combination and cant get positive results im stuck with it since friday, if someone of u know why that dsnt work i will glad 4 a answer.
And would like to ask u why this custom window starting together with photoscan, if i will add 10 scripts (custom windows) I will have to closed them all before i will be able to use photoscan 

   

36
Python and Java API / Re: Add photos to the chunk
« on: November 28, 2017, 11:12:19 AM »
Hi Alexey

still can't figure out how to make it works, iv been tried few combinations and the script starting with my photoscan but once windows closed cant open it anymore, and it is normal did iv added 4 custom windows and they are opened with photoscan on start all ???
and im using 1.3.4 pro version photoscan

here is my code:
Code: [Select]
import PhotoScan
from tkinter import*

root = Tk()
center_window(500, 400)
root.title('selection images')

def center_window(width=300, height=200):
    # hoteur et largeur notre fenetre
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()

    # calcule positionement notre fenetre sur ecran
    x = (screen_width/2) - (width/2)
    y = (screen_height/2) - (height/2)
    root.geometry('%dx%d+%d+%d' % (width, height, x, y))

def myfunk():
    doc = PhotoScan.app.document
    chunk = doc.chunk

    def callback():
        chunk = PhotoScan.app.document.chunk
        for camera in chunk.cameras:
            if camera.enabled:
                camera.selected = True
            else:
                camera.selected = False

but = Button(root,bg='yellow',width =20, height =2, bd =2, relief =SOLID, text='selection active', command=callback)

but.pack()
root.mainloop()

PhotoScan.app.addMenuItem("Custom/Give me a name", myfunk)



Any help please Alexey ? I event tried put all my script in to the class and nothing, have not enough skills with python hope so one day that will changed ^-^ .

37
Python and Java API / Re: Add photos to the chunk
« on: November 24, 2017, 06:19:56 PM »
re Hi Alexey

One more question 4 today
Now iv added a custom button with some action to my menu and my window works my button do my action , but i cant open my window once closed from my custom menu, when i restart ps my Custom menu is on place then i go to "Selection desactiver" and ---Nothing happens--- , when i add my script manually, will add second "selection desactiver" but its dsnt work ,  tell Alexey what is wrong with my code pls
Code: [Select]
import os
import PhotoScan
from tkinter import*


def center_window(width=300, height=200):
    # hoteur et largeur notre fenetre
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()

    # calcule positionement notre fenetre sur ecran
    x = (screen_width/2) - (width/2)
    y = (screen_height/2) - (height/2)
    root.geometry('%dx%d+%d+%d' % (width, height, x, y))




####
root = Tk()
center_window(500, 400)
root.title('selection images')


def callback():
    chunk = PhotoScan.app.document.chunk
    for camera in chunk.cameras:
        if camera.enabled:
            camera.selected = True
        else:
            camera.selected = False

but = Button(root, text='selection active', command=callback)

but.pack()


def selec():
    doc = PhotoScan.app.document
    chunk = doc.chunk
PhotoScan.app.addMenuItem("Custom/Selection desactiver", selec)
root.mainloop()


And have a nice weekend Alexey
Any ideas why thats dsnt work ??

38
Python and Java API / Re: Add photos to the chunk
« on: November 24, 2017, 12:57:29 PM »
Iv tried it before with small keyboard mistake ^^
works great my friend
thx a lot :-)

39
Python and Java API / Re: Add photos to the chunk
« 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 ??

40
Python and Java API / Re: Add photos to the chunk
« on: November 22, 2017, 03:31:48 PM »
Works great Alexey
Thx a lot :-)

41
Python and Java API / Re: Add photos to the chunk
« 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

42
Python and Java API / Re: Add photos to the chunk
« 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

43
Python and Java API / Re: Add photos to the chunk
« 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


44
Python and Java API / Re: Add photos to the chunk
« on: November 17, 2017, 03:41:47 PM »
it works well
thx Alexey

45
Python and Java API / Re: Add photos to the chunk
« 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

Pages: 1 2 [3] 4