Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: mapper on September 24, 2014, 08:13:23 PM
-
I have a series of predefined GCPs that I want to use as markers to improve my model's reference. In a previous step in my work flow I have identified their pixel locations in the frames containing them. How do I use python to create a marker at a predefined image pixel?
-
Hello mapper,
You can use the following code line to specify 2D coordinates for the marker with index j on the camera with index i:
chunk.markers[j].projections[chunk.cameras[i]] = (x,y)
-
Hi Alexey
I copy this code and pasted in the "Run Script" menu, but it did not work at all.
for example i wrote this code:
chunk.markers[1].projections[chunk.cameras[3]] = (1000,1000)
but I did not see any thing.
Please help me to do that, I need it severely. thank you very much.
-
Hello mrafiei,
And what is the output in the console pane after you input this line?
Have you defined chunk = PhotoScan.app.document.chunk at first?
-
Hi Mr.Pasumansky
Excuse me, I am not familiar with python scripting. But I want to mark GCPs with a code to do this process very fast.
I have a lot of GCPs in pixel in image coordinate, and I want to mark them with a code, because I can not mark them with pointing them on the photos.
Could you give me a complete code and how to use that code for this action?
I know this is a big request, but I appreciate you if you help me.
Thank you very much.
-
Hello mrefiei,
In case you wish to import marker projections in pixels and place them on the corresponding images you can use the following script (for PhotoScan Pro 1.1):
#markers import script
#input file format:
#marker_label camera_label x-coord y_coord
#(TAB separator)
import PhotoScan
doc = PhotoScan.app.document
chunk = doc.chunk
path = PhotoScan.app.getOpenFileName("Specify input file with marker coordinates:")
print("Import started...") #informational message
photos_total = len(chunk.cameras) #number of photos in chunk
markers_total = len(chunk.markers) #number of markers in chunk
file = open(path, "rt") #input file
eof = False
line = file.readline()
if len(line) == 0:
eof = True
while not eof:
print(line)
sp_line = line.rsplit("\t", 3) #splitting read line by four parts
y = float(sp_line[3]) #x- coordinate of the current projection in pixels
x = float(sp_line[2]) #y- coordinate of the current projection in pixels
camera_label = sp_line[1] #camera label
marker_name = sp_line[0] #marker label
flag = 0
for camera in chunk.cameras:
if camera.label.upper() == camera_label.upper(): #searching for the image (comparing with all the photo paths in chunk)
for marker in chunk.markers: #searching for the marker (comparing with all the marker labels in chunk)
if marker.label == marker_name:
marker.projections[camera] = (x, y) #setting up marker projection of the correct photo)
flag = 1
break
if not flag: #adding new marker if no correspondence found
chunk.addMarker()
chunk.markers[-1].label = marker_name
chunk.markers[-1].projections[camera] = (x, y) #setting up marker projection of the correct photo)
break
line = file.readline() #reading the line in input file
if not len(line):
eof = True
break # End of File
print("Script finished") #information message
file.close()
-
When I run this python,It prompted me to the following:
Import started...
A1 11092.tif 22 34
Traceback (most recent call last):
File "E:/ImportMarker.py", line 51, in <module>
chunk.markers[-1].label = marker_name
AttributeError: 'PhotoScan.Marker' object attribute 'label' is read-only
I want to know how to solve it?
-
Hello ppkong,
Are you using latest release version?
-
Hello ppkong,
Are you using latest release version?
Yes!version114_2021
-
Hello ppkong,
That's strange. Have you tried to input manually just a few lines from the code, like
chunk.addMarker()
chunk.markers[-1].label = marker_name
If the problem is still there, please send the project file and input text file to support@agisoft.com. You can remove mesh, dense cloud, depth maps and even sparse cloud from the project to reduce the file size.
-
Hi all,
This is a very useful script. It is working nicely to mine. Though, I would like to ask how can this script be further developed so to compute the 3D coordinates from this image with the error in pixels? It seems that the new marker is imported in the reference marker panel but without x,y,z, in object space. Is this possible to extend this script?
Thanks a lot
Maria
-
Hi all again,
I actually now realized that I can use the script as seen in a older thread http://www.agisoft.com/forum/index.php?topic=3411.msg17803#msg17803 in order to convert pixel coordinates to 3D coordinates. If I generate a mesh with high accuracy the resulting x, y, z, coordinates in the object space should be reliable. I would like some feedback on that, please.
Thanks a lot.
Maria
-
Hello Maria,
Do you need to get estimated marker coordinates? Because if there are no source values you can't get the errors.
-
Hello ppkong,
That's strange. Have you tried to input manually just a few lines from the code, like
chunk.addMarker()
chunk.markers[-1].label = marker_name
If the problem is still there, please send the project file and input text file to support@agisoft.com. You can remove mesh, dense cloud, depth maps and even sparse cloud from the project to reduce the file size.
Thank you so much Alexey!Although I do not know what the reason is, but I follow your argument has to solve the problem.But in general, marker Photo Center as the origin, and are in millimeters, should be how to deal with this situation?
-
Hello Alexey,
Thank you for your reply. Yes I realised it after I posted the query.
Regards,
Maria