これまでの私のコード:
from collections import OrderedDict as od
def load(fileIn, fileOut):
with open(fileIn+'.txt') as fin, open(fileOut+'.txt', 'w') as fout:
dict = od()
for line in fin:
row = line.split()
id = int(row[0])
frame = int(row[2])
rect = [int(row[3]),int(row[4]),int(row[5]),int(row[6])]
dict = {frame:[id, rect]}
fout.writelines(str(dict)+'\n')
テキスト ファイルから読み取り、特定の方法で並べ替え、新しいファイルに書き込みます。別のfor
ループを追加するか、場合によってはさらに 2 つ追加する必要があるので、それを書く前に並べ替えることができます。これが私が苦労している場所です。
より明確にするために、入力と出力の例を次に示します。
入力:
2 109 1 561 1 20 28 1
2 109 2 557 1 24 32 1
2 109 3 557 5 24 32 1
2 109 4 553 5 28 32 1
2 109 5 553 1 36 40 1
239 195 1 101 549 40 28 1
239 195 2 100 549 40 28 1
239 195 3 98 549 40 28 1
239 195 4 91 551 40 28 1
239 195 5 93 549 40 28 1
出力:
{1: [2, [561, 1, 20, 28]]}
{2: [2, [557, 1, 24, 32]]}
{3: [2, [557, 5, 24, 32]]}
{4: [2, [553, 5, 28, 32]]}
{5: [2, [553, 1, 36, 40]]}
{1: [239, [101, 549, 40, 28]]}
{2: [239, [100, 549, 40, 28]]}
{3: [239, [98, 549, 40, 28]]}
{4: [239, [91, 551, 40, 28]]}
{5: [239, [93, 549, 40, 28]]}
私は、異なる s のすべての値を、それらすべてが共有rect
する共通の 1 つのキーの下にグループ化しようとしています。frame
したがって、毎回frame
異なるファイルに 1 が 100 回出現する場合、1 つのファイルに100 個の異なるs が含まれるすべてのsが必要です。id
rect
key
rect
したがって、その例は次のようになります。
{1:[rect],[rect],[rect],[rect],[rect],[rect],[rect],[rect],[rect]}
{2:[rect],[rect],[rect],[rect],[rect],[rect],[rect],[rect],[rect]}
{3:[rect],[rect],[rect],[rect],[rect],[rect],[rect],[rect],[rect]}
frame
1
次に、あるファイルとframe
1
別のファイルを比較できます。