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 - chitty1989

Pages: [1] 2
1
Python and Java API / Marquee select and remove
« on: June 06, 2023, 08:16:37 AM »
Hi i was wondering if there was a script to define a marquee selection across multiple chunks to remove?

2
General / Screenshotting a chunk?
« on: May 24, 2023, 09:04:26 AM »
Hi,

I was just wondering if you take a screenshot of a chunk via a script and incorporate it into a batch script?

3
General / Re: possible to see two chunks at the same time?
« on: September 15, 2022, 05:22:54 AM »
Hey guys is it possible to have a model visible in agisoft with no cameras as well as a chunk that has cameras. 
Im trying to allign chunks with a base model, obviously the base model doesnt have any cameras so i was hoping to have both of them visible at the same time

4
General / Aligning chunks to base model
« on: September 01, 2022, 11:44:43 PM »
Hi,
I have a project where I have multiple chunks of peoples heads that I need to allign to a base model of a head. Do you have any recommendations as to how to allign them?

Note: I have tried the allign chunks via camera method and used one chunk as the reference chunk to allign the rest. This gets me some of the way there but it still results in a little manual movement.  I was just curious if there is a more accurate method.

Also is there a way to view 2 chunks in the scene at a time. Ie. i want to view the base model and the chunk at the same time.

5
Python and Java API / Re: Resizing the region
« on: June 17, 2022, 11:00:17 AM »
Hi is there a way to reset the region first, then run the resize region script. All via a script?

6
Python and Java API / Re: reset region vertically
« on: June 17, 2022, 10:55:39 AM »
Hi is there a basic script to run resetRegion()?

7
Python and Java API / reset region
« on: June 17, 2022, 09:44:26 AM »
Hey guys i was just hoping someone could help me write a python script that can reset the region box?

Regards,
Andrew

8
Im running a script as part of a batch and im getting this message.  The scripts work when not added as part of the batch. however as soon as i put it in the batch it gives the following error

2022-03-22 11:04:44 RunScript: path = C:/Program Files/Agisoft/Metashape Pro/python/Scripts/01GradualSelect_Resize.py
2022-03-22 11:04:44 Can't open script: C:/Program Files/Agisoft/Metashape Pro/python/Scripts/01GradualSelect_Resize.py
2022-03-22 11:04:44 Finished processing in 0.741 sec
2022-03-22 11:04:44 Saving project...
2022-03-22 11:04:44 saved project in 0.001 sec
2022-03-22 11:04:45 Finished batch processing in 3.72 sec (exit code 1)
2022-03-22 11:05:38 Error: Run script failed

9
Python and Java API / Re: region resize script
« on: March 22, 2022, 01:00:54 AM »
Thanks Alexey that worked perfectly!

Is it at all possible to add rotation so the region box isnt on an angle and is facing my front set of cameras?

In the image the red is where the region box is currently in orthographic view and green is where i kinda want the region box to be.

Sorry for asking so much!


10
Python and Java API / Re: Resizing the region
« on: March 21, 2022, 04:19:12 PM »
Hey guys is there a simple script that will take my current region box and double it’s scale?

11
Python and Java API / Re: region resize script
« on: March 21, 2022, 04:15:48 PM »
Hey guys just checking if anyone was able to help on this? I simply just want to take whatever the default region box is and double its size

12
Python and Java API / region resize script
« on: March 21, 2022, 09:18:49 AM »
Hey guys i have this script that resizes the region box, however it takes into account points that are outside of the original region box, making the result very large. All i want to do is take the region box the allignment has given me and scale it up by a factor of 2 or whatever scale i give it

Code: [Select]
import Metashape, math

doc = Metashape.app.document
chunk = doc.chunk
region = chunk.region
T = chunk.transform.matrix

m = Metashape.Vector([1E+1, 1E+1, 1E+1])
M = -m

for point in chunk.point_cloud.points:
if not point.valid:
continue
coord = T * point.coord
for i in range(3):
m[i] = min(m[i], coord[i])
M[i] = max(M[i], coord[i])

center = (M + m) / 2
size = M - m
region.center = T.inv().mulp(center)
region.size = size * (2 / T.scale())

region.rot = T.rotation().t()

chunk.region = region
print("Script finished.")

13
I think i got it!

Code: [Select]
import Metashape

chunk = Metashape.app.document.chunk
index = 0

for chunk in Metashape.app.document.chunks:
for camera in chunk.cameras:
cameraCount = (len(chunk.cameras))
camera.label = "_".join([format(index)])
index += 1
if index == cameraCount:
index = 0


print("Script finished")

14
Hey chitty1989,

you can always insert a loop that loops inside all chunks in document:
Code: [Select]
for chunk in Metashape.app.document.chunks:
     for camera in chunk.cameras:
.....   

be careful the camera.photo.path should not be changed as this is the path to actual image file name on disk irrespective of change in camera.label

Hey Paulo!

Code: [Select]
import PhotoScan

chunk = PhotoScan.app.document.chunk

string = PhotoScan.app.getString("Input prefix to be added to the selected camera labels:")
index = PhotoScan.app.getInt("Input starting index:")

for chunk in Metashape.app.document.chunks:
for camera in chunk.cameras:
if camera.label:
if camera.label[-3] == ".":
camera.label = "_".join([string,"{:04d}".format(index)]) + camera.label[-4:]
else:
camera.label = "_".join([string,"{:04d}".format(index)])
camera.photo.path = camera.photo.path.rsplit("/",1)[0] + "/" + camera.label
index += 1

print("Script finished")

I have something like this now. however this is continuing the count from where the previous chunk left off. So if the previous chunk photos are renamed to 001 to 016, then the next chunk will start at 017 to 022 etc. im hoping to find a way to rename each chunks camera labels the same name ie. 001 to 016 as each chunk should have 16 photos

15
Hi chitty1989,

for a given camera, its label can be stripped of its first 4 characters by:
Code: [Select]
camera.label = camera.label[4:]
and for renaming chunks to folder where images are stored, you can use following to extract folder name from a given camera.photo.path:
Code: [Select]
camera.photo.path
Out[5]: 2022-03-17 21:59:06 'C:/Users/paul.pelletier/Documents/Merida_190718/Vuelo2/img/IMG_6133.JPG'

os.path.dirname(camera.photo.path)
Out[6]: 2022-03-17 22:00:21 'C:/Users/paul.pelletier/Documents/Merida_190718/Vuelo2/img'

os.path.dirname(camera.photo.path).rsplit('/',1)
Out[7]: 2022-03-17 22:01:25 ['C:/Users/paul.pelletier/Documents/Merida_190718/Vuelo2', 'img']

os.path.dirname(camera.photo.path).rsplit('/',1)[-1]
Out[8]: 2022-03-17 22:02:05 'img'

for a base script to rename all chunks in a workspace look at https://github.com/agisoft-llc/metashape-scripts/blob/master/src/contrib/change_chunk_names.py

Hope this gets you started!

Thanks Paulo!

I found this script that allows you to input a prefix and a starting index which is great!
Code: [Select]
import PhotoScan

chunk = PhotoScan.app.document.chunk

string = PhotoScan.app.getString("Input prefix to be added to the selected camera labels:")
index = PhotoScan.app.getInt("Input starting index:")

for camera in chunk.cameras:
if camera.selected:
if camera.label[-4] == ".":
camera.label = "_".join([string,"{:04d}".format(index)]) + camera.label[-4:]
else:
camera.label = "_".join([string,"{:04d}".format(index)])
camera.photo.path = camera.photo.path.rsplit("/",1)[0] + "/" + camera.label
index += 1

print("Script finished")
However the slightly annoying thing is that I have to select all the photos within each chunk and run the script. and then repeat for the next chunk. Is there a way i could do this for all chunks? Maybe if i pre- specified the prefix and starting index in the script and apply it to all photos within each chunk?
Maybe via a nested for loop?

Pages: [1] 2