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.


Topics - magic

Pages: [1]
1
Python Scripting / Access to Workspace with pyside2 GUI
« on: August 13, 2018, 02:02:19 PM »
Hi all,
I have my GUI made with PySide2 and I do some action in first QPlainTextEdit() window.
 I'm printing my selected groups, I would like to know did it is possible to move or copy my workspace tree to QPlainTextEdit() window or QTextEdit() or any others possibility , to get my work more safety , means selecting my groups in my GUI, not direct in my Workspace ?? Coz last week I made some error and I lost my work, I had to start from beginning(from my save), We can do it with python API ??

2
Python Scripting / Calibration from xml files
« on: August 08, 2018, 04:19:21 PM »
Hi team,
I would like to ask You how can I use calibrated parameters from xml file,
I have 2 different camera exif model  , and I would like to apply different  params for different  models,
for all my cameras in few chunks from my 2 xml files (with parameters),
I've tried few combination and doe's not want to go
That my script:

Code: [Select]
import PhotoScan

black_xml = "F:\calibration_ps\CAL_HERO6_2.xml"
session_xml = "F:\calibration_ps\CAL_SESSION4_2.xml"


for chunk in PhotoScan.app.document.chunks:
    #chunk.estimateImageQuality(chunk.cameras)
    for camera in chunk.cameras:
        #print(camera)
        dd = camera.photo.meta["Exif/Model"]
        if dd == "HERO6 Black":
            print(camera, " hero black")
            calib = PhotoScan.Calibration()
            calib.load(black_xml)
            calib = True
        if dd == "HERO4 Session":
            print(camera, " hero black")
            calib = PhotoScan.Calibration()
            calib.load(session_xml)
            calib = True

I'm taking out a meta model , printing it and working well but I cant apply my xml file , what I have to change over here ???

3
Python Scripting / Run script from batch file
« on: July 30, 2018, 01:51:44 PM »
Hi all ,
How we can run a script from bat file ? I've tried few combination and nothing works , my photoscan start my project is charged, but there is no action after, script does not want run how can I charge it ??
Code: [Select]
cd "c:\Program Files\Agisoft\PhotoScan Pro"
photoscan F:\TEST_PHOTOSCAN\toto2.psx
photoscan F:\piotrwork\ps_network\network_combine_test.py
What I have to add over here to start my script ???

4
Python Scripting / BuildModel params network
« on: July 20, 2018, 05:53:15 PM »
Hi all,
I have a problem , I cant run my script , I want do BuildMesh and have errors
- Empty surface
- null frame
Did somebody can help I dont know witch parameters put to the function BuildModel nothing works Im on version 1.4.1

Code: [Select]
import PhotoScan

client = PhotoScan.NetworkClient()
doc = PhotoScan.app.document

task = PhotoScan.NetworkTask()
for c in doc.chunks:
    task.chunks.append(c.key )
    task.frames.append((c.key, 0))
task.name = "BuildModel"
task.params['apply'] = task.chunks
task.params['cameras'] = task.frames
#task.params['faces'] = "high"
#task.params['classes'] = [PhotoScan.PointClass.Ground]
task.params['surface'] = PhotoScan.Arbitrary
task.params['interpolation'] = PhotoScan.EnabledInterpolation
task.params['face_count'] = 1000
task.params['source'] = PhotoScan.DataSource.DenseCloudData
task.params['network_distribute'] = True #fine level task distribution key

path = "F:/TEST_PHOTOSCAN/toto2.psx" #relative path from root folder
client.connect('192.168.0.123') #server ip
batch_id = client.createBatch(path, [task])

client.resumeBatch(batch_id)
print("Debut")
Any help will be appreciated...

5
Python Scripting / Set a region from point A to B
« on: June 19, 2018, 12:39:49 PM »
Hi all
I'm looking for help , I have a probleme to set a region in my project from fixed points A to B, I have a text file with coordinates X,Y like this:
Code: [Select]
    {
        "Y": "131524.72623558177",
        "X": "600237.012492972"
    },
    {
        "Y": "131520.4597589273",
        "X": "600236.8305144551"
    },
    {
        "Y": "131516.19328227278",
        "X": "600236.6485359382"
    },
    {
        "Y": "131511.9268056183",
        "X": "600236.4665574214"
    }
What I'm looking for is to set a region box from 1st coordinates to 2nd (define by zone im my project to get the smallest parts) and do some stuff with , after get a 2nd region, from 2nd coordinates to 3rd (do some stuff with)etc etc
How to do it with python ?? to set my region ?? There is a lot infos over here http://www.agisoft.com/forum/index.php?topic=1886.15 or http://www.agisoft.com/forum/index.php?topic=2488.0
But I can't figured it out since few hours now  , how can I fix it ??? I've tried that but doesn't work at all ....
Code: [Select]
mySize = 4

#select the project
doc = PhotoScan.app.document

# Define: Map region
# MapRegionVec = [CenterX, CenterY, SizeX0, SizeY0, ZRotationDeg]
MapRegionVec = [coord_x, coord_y, mySize, mySize, 0.0]

#get the current chunk
chunk = doc.chunk

#create new region
newregion = PhotoScan.Region()

# Set region size
newregion.size = PhotoScan.Vector([MapRegionVec[2], MapRegionVec[3], chunk.region.size[2]])


# Set region rotation
# build rotation matrix in our coordinate system
RotZDeg = -MapRegionVec[4]
SinRotZ = math.sin(math.radians(RotZDeg))
CosRotZ = math.cos(math.radians(RotZDeg))
RotMat = PhotoScan.Matrix([[CosRotZ, -SinRotZ, 0, 0], [SinRotZ, CosRotZ, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

#  Rotate region bounding box
T = chunk.transform.matrix
v = PhotoScan.Vector([0, 0, 0, 1])
v_t = T * v
v_t.size = 3
m = chunk.crs.localframe(v_t)
m = m * T
m = RotMat * m
s = math.sqrt(m[0, 0] ** 2 + m[0, 1] ** 2 + m[0, 2] ** 2)  # scale factor
R = PhotoScan.Matrix([[m[0, 0], m[0, 1], m[0, 2]], [m[1, 0], m[1, 1], m[1, 2]], [m[2, 0], m[2, 1], m[2, 2]]])
R = R * (1. / s)
newregion.rot = R.t()

# Put newregion to chunk
chunk.region = newregion

I've tried to pout my region center to one of my markers points and thats works , but did we can define a region possition between 2 points as I asked at the beginning of my post ???
Code: [Select]

# Define: Region [CenterX, CenterY, CenterZ, SizeX, SizeY, ZRotationDeg]
MapRegionVec = [600225.8792,131360.0026,67.30138399999889, 173.8, 143.6, -25.0]



# Set region center:
newregion = PhotoScan.Region()
centerUTM = PhotoScan.Vector([MapRegionVec[0], MapRegionVec[1], MapRegionVec[2]])
centerGEO = chunk.crs.unproject(centerUTM)
centerLocal = chunk.crs.localframe(centerGEO)


#newregion.center = PhotoScan.Vector([0,0,0])
newregion.size = PhotoScan.Vector([150,150,90])
chunk.region = newregion


#newregion.size = PhotoScan.Vector([MapRegionVec[3], MapRegionVec[4], chunk.region.size[2]])

# Set region rotation
import math
SinRotZ= math.sin(math.radians(MapRegionVec[5]))
CosRotZ= math.cos(math.radians(MapRegionVec[5]))
newregion.rot = PhotoScan.Matrix( [[SinRotZ,-CosRotZ,0], [CosRotZ,SinRotZ,0], [0,0,1]] )


# put newregion to chunk
chunk.region = newregion



6
Python Scripting / Find and select cameras by time in chunk
« on: May 17, 2018, 02:55:28 PM »
Hi team
I have some script and I can see time all my cameras in chunk(ex 10.59,10.59,10.59,11.00,11.00 etc) , what I want to do is to find and select only the images with specific time for example , cameras been taken at 10am to 4pm , and I want only work with cameras with been taken at 1am05 to 1am25 , and selected them how we can do it it is possible, and I have some error message with split...
AttributeError: 'NoneType' object has no attribute 'split'
2018-05-17 14:08:56 Error: 'NoneType' object has no attribute 'split'
Code: [Select]
import os, PhotoScan

chunk = PhotoScan.app.document.chunk
time_table = list()
for camera in chunk.cameras:
    time = camera.photo.meta['Exif/DateTimeOriginal'].split(" ")[1][:-3].replace(":", ".")
    time_table.append(time)
    time_table.sort()
time_table.sort()
print(time_table)
Thaths what I have for now , any body can help please???

7
Python Scripting / Remove duplicate images
« on: December 29, 2017, 02:38:56 PM »
Hi Alexey
Few days ago iv tried this script to remove all duplicate images from my workspace with works well with low number of images :
Code: [Select]
import PhotoScan, os

chunk = PhotoScan.app.document.chunk
print("start")
photos = set()
for camera in list(chunk.cameras):
      if camera.photo.path in photos:
             chunk.remove(camera)
      else:
             photos.add(camera.photo.path)

Problem starts when after few actions like merge etc and several chunks from 60k cameras I go up to 300k(all doubles) and when I tried to started this script its was like turning about 4 hours  without any results , then iv breaked it , takes to long time, did it is possible to optimize this script and get it run faster ?? Iv tried few others(similar pythons scripts) method but no one of them works with PS. Did we vgot some solution Alexey or we cant do it together with PS??

8
Python Scripting / Loading images from subdirectory to cameras groupes
« on: December 19, 2017, 02:50:48 PM »
Hi All ,

I have a  main directory with a lot of sub-directories and I would like to load them all  to my PhotoScan chunk with a python script, each sub-directory to new camera group ,   
Iv got some script with create camera group but i have no Idea how to modify it to create new camera group for next sub-dir etc ...
Code: [Select]
doc = PhotoScan.app.document
chunk = doc.addChunk()
new_group = chunk.addCameraGroup()

# 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")

for camera in list(chunk.cameras):
camera.group = new_group
Did anybody can help pls ?

9
Python Scripting / 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??

10
Python Scripting / 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()

Pages: [1]