I followed this code that works (see the question at the end)
import numpy as np
import cv2
img1 = cv2.imread('rectif/Camera1.tif',-1)
img2 = cv2.imread('rectif/Camera2.tif',-1)
img3 = cv2.imread('rectif/Camera3.tif',-1)
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
gray3 = cv2.cvtColor(img3, cv2.COLOR_BGR2GRAY)
orb = cv2.ORB(1000, 1.2)
#extract features
(kp1,des1) = orb.detectAndCompute(gray1, None)
(kp2,des2) = orb.detectAndCompute(gray2, None)
(kp3,des3) = orb.detectAndCompute(gray3, None)
# Create matcher
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# Do matching
matches = bf.match(des1,des2)
matches2 = bf.match(des1,des3)
# Sort the matches based on distance. Least distance
# is better
matches = sorted(matches, key=lambda val: val.distance)
matches2 = sorted(matches2, key=lambda val: val.distance)
But I do not have complete consciousness of what matches
python structure is. I learned that I can extract the X,Y coordinates of feature by
lkp1 = [kp1[mat.queryIdx].pt for mat in matches] #X,Y of features img1
lkp2 = [kp2[mat.trainIdx].pt for mat in matches] #X,Y of features img2
but I am definitely not an expert. I am wondering if there is a chance to order the matches, and extract the feature (their indices in matches structure) that are in common between img1 and img2 and img 3. Better, I would like to obtain 3 list of x,y coordinates, if they have the same index, they represent the same feature in image.
The ideal result (not so simple of course) would be something like
wannabe_matches = bf.match(des1,des2,des3)
There is a way to do something like this (PSEUDOCODE: this is not a working code!)
matches = bf.match(des1,des2)
matches2 = bf.match(des1,des3)
for mat in matches:
for mat2 in matches2:
if mat.descriptor == mat2.descriptor: #how it can be done?
img1_idx = mat.queryIdx
img2_idx = mat.trainIdx
img3_idx = mat2.trainIdx
(x1,y1) = kp1[img1_idx].pt
(x2,y2) = kp2[img2_idx].pt
(x3,y3) = kp2[img3_idx].pt
# Append to each list
list_kp1.append((x1, y1))
list_kp2.append((x2, y2))
list_kp3.append((x3, y3))
Or anything better that lead me to the result?
I am working with python 2.7 and openCV 2.4.13 (not openCV 3!)