Forum

Author Topic: Import 2D markers from x,y pixel coordinates, each marker seen in only one image  (Read 6979 times)

SBinary

  • Newbie
  • *
  • Posts: 5
    • View Profile
Hi,

I have a template matching image processing workflow that gives me the coordinates of an object of interest (e.g. traffic light) in each image. I save these coordinates as a .txt file as follows:

markerID+imageName, imageName.DNG, Xpixelcoordinates,Ypixelcoordinates

As each marker has a unique ID which depend on in which image it was seen, I am struggling to import and project these 2D markers to 3D coordinates. Is there a way around this? Is it possible to import markers only seen in one image, and then estimate the marker's 3D coordinates?

I understand that a marker placed in only one photo simply defines a 'ray' i.e. a line originating at the camera location and extending to infinity on the direction of the position it was placed on the photo. And that same marker placed in a second photo defines another 'ray' and where those rays intersect, is the 'position' of the marker in 3d space.

But perhaps it is possible to estimate the 2D marker in one image's pixel coordinate location in other images? That is, based on the known pixel coordinates in one image, estimate the same location in other images. After that I could manually move those markers to improve the 2D location in the given image, and then eventually - with enough images, estimate the 3D coordinates of that 2D  marker? I hope that explanation is clear enough.

I am using Agisoft Metashape Professional Ver. 1.5.5 build 9097 (64bit) on Windows 10.

My code is as follows

Code: [Select]
import PhotoScan
import Metashape

chunk = PhotoScan.app.document.chunk
path = "inputFile.txt"
file = open(path, "rt")  # input file

eof = False
line = file.readline()
if not len(line):
    eof = True

while not eof:

    sp_line = line.rsplit(",", 3)  # splitting read line by four parts
    y = float(sp_line[3])  # y- coordinate of the current projection in pixels
    x = float(sp_line[2])  # x- coordinate of the current projection in pixels
    path = sp_line[1]  # camera label
    marker_name = sp_line[0]  # marker label

    flag = 0
    for i in range(len(chunk.cameras)):

        if chunk.cameras[i].label == path:  # searching for the camera

            for j in range(
                    len(chunk.markers)):  # searching for the marker (comparing with all the marker labels in chunk)
                if chunk.markers[j].label == marker_name:
                    chunk.markers[j].projections[chunk.cameras[i]] = PhotoScan.Marker.Projection(
                        PhotoScan.Vector([x, y]), True)  # setting up marker projection of the correct photo)
                    flag = 1
                    break

            if not flag:
                marker = chunk.addMarker()
                marker.label = marker_name
                marker.projections[chunk.cameras[i]] = PhotoScan.Marker.Projection(PhotoScan.Vector([x, y]), True)
            break

    line = file.readline()  # reading the line from input file
    if not len(line):
        eof = True
        break  # EOF

file.close()
print("Markers import finished.\n")
« Last Edit: March 09, 2020, 07:18:44 PM by SBinary »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15691
    • View Profile
Hello SBinary,

Can you post a few lines from your input text file for the reference?
Best regards,
Alexey Pasumansky,
Agisoft LLC

SBinary

  • Newbie
  • *
  • Posts: 5
    • View Profile
Hello Alexey,

Thank you for having a look! Much appreciated!

The textfile looks something like this,

1,DSC04492.dng,1053,895
2,DSC04492.dng,1273,900
3,DSC04492.dng,2627,932
4,DSC04492.dng,2811,933
5,DSC04492.dng,1121,1202
6,DSC04492.dng,1336,1207
7,DSC04492.dng,2727,1232
8,DSC04492.dng,2931,1236
9,DSC04494.dng,2701,937
10,DSC04494.dng,2903,941
11,DSC04494.dng,2817,1241
12,DSC04515.dng,145,377
13,DSC04515.dng,36,785
14,DSC04516.dng,595,359
15,DSC04516.dng,805,358
16,DSC04516.dng,1010,356
17,DSC04516.dng,502,765
18,DSC04516.dng,704,765
19,DSC04516.dng,927,762
20,DSC04516.dng,915,772

Or like this,

0DSC04492,DSC04492.dng,1053,895
1DSC04492,DSC04492.dng,1273,900
2DSC04492,DSC04492.dng,2627,932
3DSC04492,DSC04492.dng,2811,933
4DSC04492,DSC04492.dng,1121,1202
5DSC04492,DSC04492.dng,1336,1207
6DSC04492,DSC04492.dng,2727,1232
7DSC04492,DSC04492.dng,2931,1236
0DSC04494,DSC04494.dng,2701,937
1DSC04494,DSC04494.dng,2903,941
2DSC04494,DSC04494.dng,2817,1241
0DSC04515,DSC04515.dng,145,377
1DSC04515,DSC04515.dng,36,785
0DSC04516,DSC04516.dng,595,359
1DSC04516,DSC04516.dng,805,358
2DSC04516,DSC04516.dng,1010,356
3DSC04516,DSC04516.dng,502,765
4DSC04516,DSC04516.dng,704,765
5DSC04516,DSC04516.dng,927,762
6DSC04516,DSC04516.dng,915,772

The script seems to work; it says that the markers were imported. but nothing shows up in Metashape. Presumably because each marker is only seen in one image?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15691
    • View Profile
Hello SBinary,

I think that you shouldn't use unique marker label in each line.

Same marker may appear on different images, so the value in the first column may be present in several lines.

I suggest to remove the camera label being added to the marker label in the second example that you have and use the file like this:
0,DSC04492.dng,1053,895
1,DSC04492.dng,1273,900
2,DSC04492.dng,2627,932
3,DSC04492.dng,2811,933
4,DSC04492.dng,1121,1202
5,DSC04492.dng,1336,1207
6,DSC04492.dng,2727,1232
7,DSC04492.dng,2931,1236
0,DSC04494.dng,2701,937
1,DSC04494.dng,2903,941
2,DSC04494.dng,2817,1241
0,DSC04515.dng,145,377
1,DSC04515.dng,36,785
0,DSC04516.dng,595,359
1,DSC04516.dng,805,358
2,DSC04516.dng,1010,356
3,DSC04516.dng,502,765
4,DSC04516.dng,704,765
5,DSC04516.dng,927,762
6,DSC04516.dng,915,772
Best regards,
Alexey Pasumansky,
Agisoft LLC