-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchFormsGtQuery.m
124 lines (110 loc) · 5.06 KB
/
searchFormsGtQuery.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
function [ ] = searchFormsGtQuery()
figure;
gameId = 2;
gameIdStr = sprintf ('%02d', gameId);
playsIdToMatch = dlmread(['../formations/odGame' gameIdStr]);
playsIdToMatch = playsIdToMatch(:, 2);
playsIdExp = dlmread(['../formsExemplar/odGame' gameIdStr 'RectForm']);
playsIdExp = playsIdExp(:, 2);
gameODs = textread(['../formations/game' int2str(gameId) '_ODK'],'%c');
rectLosCntGts = dlmread(['../losCntGt/Game' gameIdStr 'LosCntGtRect']);
expPlaysSz = size(playsIdExp, 1);
matchPlaysSz = size(playsIdToMatch, 1);
for i = 1 : expPlaysSz
costs = zeros(matchPlaysSz, 1);
assignMats = cell(matchPlaysSz, 1);
pCells = cell(matchPlaysSz, 1);
expPlayId = playsIdExp(i);
expPlayIdStr = sprintf ('%03d', expPlayId);
q = dlmread(['../formsExemplar/Game' gameIdStr '/' 'vid' expPlayIdStr '.pos']);
for j = 1 : matchPlaysSz
curPlayId = playsIdToMatch(j);
curPlayIdStr = sprintf ('%03d', curPlayId);
p = dlmread(['../formations/Game' gameIdStr '/' 'vid' curPlayIdStr '.pos']);
pCells{j} = p;
if(gameODs(expPlayId) == gameODs(curPlayId))
[assignMats{j}, costs(j)] = matchTwoForm(q, p);
else
costs(j) = inf;
assignMats{j} = [];
end
end
[~, sortIdx] = sort(costs);
expSearchVidPlotsPath = ['../plotsSearch/Game' gameIdStr '/vid' expPlayIdStr '_search'];
if(exist(expSearchVidPlotsPath, 'file') ~= 0)
rmdir(expSearchVidPlotsPath, 's');
end
mkdir(expSearchVidPlotsPath);
img2 = imread(['../formExmpImgs/Game' gameIdStr 'Los/' gameIdStr '0' expPlayIdStr 'Rect.jpg']);
img2Orig = imread(['../formExmpImgs/Game' gameIdStr 'Los/' gameIdStr '0' expPlayIdStr '.jpg']);
searchResNum = 4;
bestSearchRes = zeros(size(img2, 1), 2 * size(img2, 2), size(img2, 3));
bestSearchResOrig = zeros(size(img2Orig, 1), 2 * size(img2Orig, 2), size(img2Orig, 3));
bestSearchRes(:, (size(img2, 2) / 2 ) : (size(img2, 2) / 2 + size(img2, 2) - 1), :) = img2;
bestSearchResOrig(:, (size(img2Orig, 2) / 2 ) : (size(img2Orig, 2) / 2 + size(img2Orig, 2) - 1), : ) = img2Orig;
bestImg1 = cell(searchResNum, 1);
bestImg1Orig = cell(searchResNum, 1);
for k = 1:searchResNum
curPlayId = playsIdToMatch(sortIdx(k));
curPlayIdStr = sprintf ('%03d', curPlayId);
img1 = imread(['../formImgs/Game' gameIdStr 'GtLos/' gameIdStr '0' curPlayIdStr 'Rect.jpg']);
img1Orig = imread(['../formImgs/Game' gameIdStr 'GtLos/' gameIdStr '0' curPlayIdStr '.jpg']);
bestImg1{k} = img1;
bestImg1Orig{k} = img1Orig;
end
bestSearchRes = [bestSearchRes; [bestImg1{1} bestImg1{2}]; [bestImg1{3} bestImg1{4}]];
bestSearchResOrig = [bestSearchResOrig; [bestImg1Orig{1} bestImg1Orig{2}]; [bestImg1Orig{3} bestImg1Orig{4}]];
imshow(bestSearchRes);
hold on
plotPath = [expSearchVidPlotsPath '/vid' expPlayIdStr '_best_' int2str(searchResNum) '.jpg'];
Image = getframe(gcf);
imwrite(Image.cdata, plotPath);
hndl = gcf();
close(hndl);
hold off;
imshow(bestSearchResOrig);
plotPath = [expSearchVidPlotsPath '/vid' expPlayIdStr '_best_' int2str(searchResNum) 'Orig.jpg'];
Image = getframe(gcf);
imwrite(Image.cdata, plotPath);
hndl = gcf();
close(hndl);
hold off;
worstSearchRes = zeros(size(img2, 1), 2 * size(img2, 2), size(img2, 3));
worstSearchResOrig = zeros(size(img2Orig, 1), 2 * size(img2Orig, 2), size(img2Orig, 3));
worstSearchRes(:, (size(img2, 2) / 2 ) : (size(img2, 2) / 2 + size(img2, 2) - 1), :) = img2;
worstSearchResOrig(:, (size(img2Orig, 2) / 2 ) : (size(img2Orig, 2) / 2 + size(img2Orig, 2) - 1), : ) = img2Orig;
worstImg1 = cell(searchResNum, 1);
worstImg1Orig = cell(searchResNum, 1);
wstIdx = 1;
for k = matchPlaysSz : -1 : 1
if(costs(sortIdx(k)) ~= inf)
curPlayId = playsIdToMatch(sortIdx(k));
curPlayIdStr = sprintf ('%03d', curPlayId);
img1 = imread(['../formImgs/Game' gameIdStr 'GtLos/' gameIdStr '0' curPlayIdStr 'Rect.jpg']);
img1Orig = imread(['../formImgs/Game' gameIdStr 'GtLos/' gameIdStr '0' curPlayIdStr '.jpg']);
worstImg1{wstIdx} = img1;
worstImg1Orig{wstIdx} = img1Orig;
wstIdx = wstIdx + 1;
end
if((wstIdx - 1) == searchResNum)
break;
end
end
worstSearchRes = [worstSearchRes; [worstImg1{1} worstImg1{2}]; [worstImg1{3} worstImg1{4}]];
worstSearchResOrig = [worstSearchResOrig; [worstImg1Orig{1} worstImg1Orig{2}]; [worstImg1Orig{3} worstImg1Orig{4}]];
imshow(worstSearchRes);
plotPath = [expSearchVidPlotsPath '/vid' expPlayIdStr '_worst_' int2str(searchResNum) '.png'];
Image = getframe(gcf);
imwrite(Image.cdata, plotPath);
hndl = gcf();
close(hndl);
hold off;
imshow(worstSearchResOrig);
plotPath = [expSearchVidPlotsPath '/vid' expPlayIdStr '_worst_' int2str(searchResNum) 'Orig.png'];
Image = getframe(gcf);
imwrite(Image.cdata, plotPath);
hndl = gcf();
close(hndl);
hold off;
end
end