Forum

Author Topic: valid/invalid matches between image pairs  (Read 9205 times)

James

  • Hero Member
  • *****
  • Posts: 748
    • View Profile
valid/invalid matches between image pairs
« on: July 24, 2013, 05:56:43 PM »
am i right in thinking that matching points between image pairs are not currently accessible though the python api?

i was hoping to be able to do some filtering based on ratio of valid to invalid matches or similar on a particularly messy dataset i have to work on.

james

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: valid/invalid matches between image pairs
« Reply #1 on: July 24, 2013, 06:08:49 PM »
Hello James,

Currently these numbers are not accessible through Python, but if you wish I can post a sample script to do the calculations (unfortunately, for large datasets it's quite slow).
Best regards,
Alexey Pasumansky,
Agisoft LLC

James

  • Hero Member
  • *****
  • Posts: 748
    • View Profile
Re: valid/invalid matches between image pairs
« Reply #2 on: July 25, 2013, 11:43:49 AM »
Thanks Alexey, that might be really useful!

The dataset is <100 36MP images which could potentially be treated in two chunks so hopefully not too large.

Thank you,

James

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: valid/invalid matches between image pairs
« Reply #3 on: July 25, 2013, 12:30:32 PM »
Hello James,

I think the code should be the following:

Code: [Select]
import PhotoScan

doc = PhotoScan.app.document
chunk = doc.activeChunk

point_cloud = chunk.point_cloud
point_proj = point_cloud.projections

photo_matches = list()
total_matches = list() #here the result will be stored

for photo in chunk.photos:
try:
photo_proj = point_proj[photo]
total = set()
for proj in photo_proj:
total.add(proj.index)
except:
total = set()
photo_matches.append(total)

for i in range(0, len(chunk.photos) - 1):
for j in range(i + 1, len(chunk.photos)):
match = photo_matches[i] & photo_matches[j]

total = 0
valid = 0
invalid = 0

for p_index in match:
if point_cloud.points[p_index].valid:
valid += 1
total = len(match)
invalid = total - valid

total_matches.append((chunk.photos[i].label, chunk.photos[j].label, total, valid, invalid)) #the result - photo1, photo2, total, valid, invalid

Best regards,
Alexey Pasumansky,
Agisoft LLC

tkwasnitschka

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Visualizing matches between images
« Reply #4 on: March 03, 2017, 06:57:05 PM »
I am trying to write a skript that will give me a table like this with labels and pose coordinates for any image pair that has more than three valid matches:

Code: [Select]
Label_A, X, Y, Z, Label_B, X, Y, Z
Could anyone help me out, I am having a hard time working my way through Alexeys above skript getting it to the current API version as well as expanded...

A visualization like this used by Pizarro et al. 2017 would be an awesome basis to visualize a net of matching camera poses in order to identify partial reconstructions that may have received a first order alignment through ground control points, but actually have no link (yet) to the model.

This is as far as I have come. For some reason, all point numbers are always zero.

Code: [Select]
import PhotoScan

doc = PhotoScan.app.document
chunk = doc.chunk

point_cloud = chunk.point_cloud
point_proj = point_cloud.projections

photo_matches = list()
total_matches = list() #here the result will be stored

for photo in chunk.cameras:
try:
photo_proj = point_proj[photo]
total = set()
for proj in photo_proj:
total.add(proj.index)
except:
total = set()
photo_matches.append(total)

for i in range(0, len(chunk.cameras) - 1):
for j in range(i + 1, len(chunk.cameras)):
match = photo_matches[i] & photo_matches[j]

total = 0
valid = 0
invalid = 0

for p_index in match:
if point_cloud.points[p_index].valid:
valid += 1
total = len(match)
invalid = total - valid

pos_i = chunk.crs.project(chunk.transform.matrix.mulp(chunk.cameras[i].center))
pos_j = chunk.crs.project(chunk.transform.matrix.mulp(chunk.cameras[j].center))

if valid > 3:
total_matches.append((chunk.cameras[i].label, pos_i , chunk.cameras[j].label, pos_j, total, valid, invalid)) #the result - photo1, photo2, total, valid, invalid
else:
continue

print(total_matches)

« Last Edit: March 03, 2017, 10:14:04 PM by tkwasnitschka »

tkwasnitschka

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: valid/invalid matches between image pairs
« Reply #5 on: March 08, 2017, 11:20:09 AM »
Anyone?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: valid/invalid matches between image pairs
« Reply #6 on: March 09, 2017, 10:45:09 AM »
Hello Tom,

What are Z values in the desired output? Or you need XYZ for the 3D point and also 2D projections for each image pair?
Best regards,
Alexey Pasumansky,
Agisoft LLC

tkwasnitschka

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: valid/invalid matches between image pairs
« Reply #7 on: March 09, 2017, 03:48:59 PM »
Hello Alexey,

I just needthe xyz positions of each camera pair so I can plot the camera positions and a line between them, as in the link I shared earlier.

(In fact I will probably import it into 3DSmax as my models are arbitrary and a planar projection would be just confusing.)

That position export part of the script seemed to work though - when I tested it on a short demo project, I ended up getting zeros for the point statistics on all photos in all three variables, so I assume something with the code in the first part is not okay...

Thanks!
Tom

tkwasnitschka

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: valid/invalid matches between image pairs
« Reply #8 on: March 09, 2017, 04:00:42 PM »
You could also say it a lot easier:

If there are more than 3 matches between two cameras, draw a line shape between their 3D coordinates.

This effectively visualizes the clusters created in the bundle adjustment and identifies where manual tie point placement may be needed or where there is just no image overlap a priori.
« Last Edit: March 16, 2017, 11:21:14 PM by tkwasnitschka »

tkwasnitschka

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: valid/invalid matches between image pairs
« Reply #9 on: March 16, 2017, 11:23:11 PM »
Unfortunately I still have not made any progress and could not find any help from other users I know.
Just a fixed version of above script would do it for me.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: valid/invalid matches between image pairs
« Reply #10 on: May 24, 2017, 10:55:25 PM »
Hello Tom,

I've posted the related script that helps to identify the pairs of cameras that have more that three valid matching points in the corresponding thread, please let me know if it works as expected:
http://www.agisoft.com/forum/index.php?topic=6989
Best regards,
Alexey Pasumansky,
Agisoft LLC