Forum

Author Topic: How to create markers a specific image pixels  (Read 9655 times)

mapper

  • Newbie
  • *
  • Posts: 3
    • View Profile
How to create markers a specific image pixels
« 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?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14003
    • View Profile
Re: How to create markers a specific image pixels
« Reply #1 on: September 29, 2014, 01:38:41 PM »
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:

Code: [Select]
chunk.markers[j].projections[chunk.cameras[i]] = (x,y)
Best regards,
Alexey Pasumansky,
Agisoft LLC

mrafiei

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • آموزش پهپاد نقشه برداری و فتوگرامتری برد کوتاه
Re: How to create markers a specific image pixels
« Reply #2 on: February 25, 2015, 10:34:20 PM »
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.
<a href="https://maan.ir/product/uav_package/">آموزش نقشه برداری هوایی با پهپاد</a>

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14003
    • View Profile
Re: How to create markers a specific image pixels
« Reply #3 on: February 25, 2015, 11:39:38 PM »
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?
Best regards,
Alexey Pasumansky,
Agisoft LLC

mrafiei

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • آموزش پهپاد نقشه برداری و فتوگرامتری برد کوتاه
Re: How to create markers a specific image pixels
« Reply #4 on: February 27, 2015, 09:57:12 AM »
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.
<a href="https://maan.ir/product/uav_package/">آموزش نقشه برداری هوایی با پهپاد</a>

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14003
    • View Profile
Re: How to create markers a specific image pixels
« Reply #5 on: February 27, 2015, 12:08:52 PM »
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):
Code: [Select]
#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()
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppkong

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: How to create markers a specific image pixels
« Reply #6 on: April 02, 2015, 11:45:18 AM »
When I run this python,It prompted me to the following:
Code: [Select]
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?
« Last Edit: April 02, 2015, 11:47:52 AM by ppkong »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14003
    • View Profile
Re: How to create markers a specific image pixels
« Reply #7 on: April 02, 2015, 12:00:55 PM »
Hello ppkong,

Are you using latest release version?
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppkong

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: How to create markers a specific image pixels
« Reply #8 on: April 02, 2015, 12:18:14 PM »
Hello ppkong,
Are you using latest release version?
Yes!version114_2021

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14003
    • View Profile
Re: How to create markers a specific image pixels
« Reply #9 on: April 02, 2015, 12:22:39 PM »
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.
Best regards,
Alexey Pasumansky,
Agisoft LLC

b3059651

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: How to create markers a specific image pixels
« Reply #10 on: April 03, 2015, 12:04:52 AM »
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

b3059651

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: How to create markers a specific image pixels
« Reply #11 on: April 03, 2015, 01:05:18 AM »
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

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14003
    • View Profile
Re: How to create markers a specific image pixels
« Reply #12 on: April 03, 2015, 01:12:00 AM »
Hello Maria,

Do you need to get estimated marker coordinates? Because if there are no source values you can't get the errors.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppkong

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: How to create markers a specific image pixels
« Reply #13 on: April 03, 2015, 04:23:46 AM »
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?

b3059651

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: How to create markers a specific image pixels
« Reply #14 on: April 03, 2015, 10:31:25 PM »
Hello Alexey,

Thank you for your reply. Yes I realised it after I posted the query.

Regards,
Maria