text_plain_output_1.png
import cv2

import numpy as np # linear algebra

import os

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import scipy
import math
import numpy as np
import pandas as pd
import cv2
import matplotlib.pyplot as plt
import os
eps = 1e-15
train_calibration_csvs = []
train_pair_covisibility_csvs = []
test_calibration_csvs = []
test_pair_covisibility_csvs = []
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        if 'train' in dirname and 'pair_covisibility.csv' in filename:
            train_pair_covisibility_csvs.append(os.path.join(dirname, filename))
        if 'train' in dirname and 'calibration.csv' in filename:
            train_calibration_csvs.append(os.path.join(dirname, filename))
        if 'test' in dirname and 'pair_covisibility.csv' in filename:
            test_pair_covisibility_csvs.append(os.path.join(dirname, filename))
        if 'test' in dirname and 'calibration.csv' in filename:
            test_calibration_csvs.append(os.path.join(dirname, filename))
test_csv = '/kaggle/input/image-matching-challenge-2022/test.csv'
train_csv = '/kaggle/input/image-matching-challenge-2022/train/scaling_factors.csv'

def getImagesFromCSV(train_csvf, calibration_csvs, pair_covisibility_csvs, category_index, pair_index):
    train_csv = pd.read_csv(train_csvf)
    category_csv = pd.read_csv(calibration_csvs[category_index])
    pair_covisibility = pd.read_csv(pair_covisibility_csvs[category_index])
    pair_covisibility = pair_covisibility[pair_covisibility['covisibility'] >= 0.1]
    imgs = pair_covisibility['pair'][pair_index].split('-')
    F = pair_covisibility['fundamental_matrix'][pair_index]
    p_new = []
    R = []
    T = []
    K = []
    for img in imgs:
        image_loc = '/kaggle/input/image-matching-challenge-2022/train/' + str(train_csv['scene'][category_index]) + '/images/' + str(img) + '.jpg'
        p_new.append(cv2.imread(image_loc))
        R.append(np.array(np.array(category_csv[category_csv['image_id'] == img]['rotation_matrix'])[0].split(' '), dtype=np.float32).reshape((3, 3)))
        T.append(np.array(np.array(category_csv[category_csv['image_id'] == img]['translation_vector'])[0].split(' '), dtype=np.float32).reshape((3,)))
        K.append(np.array(np.array(category_csv[category_csv['image_id'] == img]['camera_intrinsics'])[0].split(' '), dtype=np.float32).reshape((3, 3)))
    df = pd.DataFrame({'imgs': p_new, 'R': R, 'T': T, 'K': K, 'F': F})
    return df
df = getImagesFromCSV(train_csv, train_calibration_csvs, train_pair_covisibility_csvs, 0, 0)

print(df['imgs'][0].shape)