-
Notifications
You must be signed in to change notification settings - Fork 2
/
vpg_annot_v1.m
147 lines (130 loc) · 4.9 KB
/
vpg_annot_v1.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
%% 2017.12.18. Seokju Lee & Junsik Kim
% Matlab code to convert caltech annot. into VPGNet annot.
% Usage: Download Caltech Lanes dataset and change path & dir parameter
% <Directory structure>
% |__ caltech-lanes-dataset (download dataset[1])
% |__ caltech-lane-detection/matlab (copy 'caltech-lane-detection/matlab' [2])
% |__ cordova1
% |__ cordova2
% |__ washington1
% |__ washington2
% |__ vpg_annot_v1.m (current code)
% |__ output.txt (output list file)
%
% [1] http://www.mohamedaly.info/datasets/caltech-lanes
% [2] https://github.com/SeokjuLee/caltech-lane-detection
clear all;
close all; clc;
%% startup (change category)
category = 'cordova2';
% category = 'cordova2';
% category = 'washington1';
% category = 'washington2';
addpath(genpath('./caltech-lane-detection/matlab'))
path = 'D:\workspace\vpgnet\VPGNet\caltech-lanes-dataset'; % change path
file = sprintf('/%s/labels.ccvl', category);
gLabelData = ccvLabel('read', [path file]);
%% spline & grid mask parameters
h = 0.02; % interval for splines
height = 480; % reference image height
width = 640; % reference image width
gg = 8; % grid size for binary mask
grid_x = 1:gg:481;
grid_y = 1:gg:641;
thickness = 2;
%% make annotation file
fileID = fopen(sprintf('./%s.txt', category),'w');
numFrames = size(gLabelData.frames,2);
gLabelSubtypes = {'bw', 'sw', 'dy', 'by', 'sy'};
for i = 1:numFrames
% i is the index of frame
disp(sprintf('frame: %03d',i))
numLanes = size(gLabelData.frames(i).labels, 2); %numLanes is howmany symbol lines detected in pic
segs = [];
splines = {numLanes};
sptypes = {numLanes};
for j = 1:numLanes
splines{j} = ccvEvalBezSpline(gLabelData.frames(i).labels(j).points, h); % convert 4 point to spline (just join them as a straight line)
sptypes{j} = gLabelData.frames(i).labels(j).subtype;
splines_x1 = splines{j};
splines_x2 = splines{j};
splines_x1(:,1) = splines_x1(:,1) - thickness;
splines_x2(:,1) = splines_x2(:,1) + thickness;
splines{j} = [splines{j}; splines_x1; splines_x2];
for k = 1:size(splines{j},1) % make spline points into bounding box
grid_pos_x = floor((splines{j}(k,1)-1)/gg);
grid_pos_y = floor((splines{j}(k,2)-1)/gg);
xmin = grid_pos_x * gg + 1;
xmax = grid_pos_x * gg + gg;
ymin = grid_pos_y * gg + 1;
ymax = grid_pos_y * gg + gg;
grid_width = xmax - xmin; % ? always 7, gg - 1
grid_height = ymax - ymin;
inst_id = j;
lane_id = find(ismember(gLabelSubtypes, sptypes{j}));
segs = [segs; xmin, ymin, xmax, ymax, inst_id, lane_id];
end
segs = unique(segs, 'rows');
end
numLaneSegs = size(segs, 1) - numLanes;
fprintf(fileID,'/%s/f%05d.png %d',category, i-1, size(segs,1));
% img_path = sprintf('%s\\f%05d.png',category,i-1);
% img = imread(img_path);
% figure(99);
% imshow(img);
% hold on;
for j = 1:size(segs,1)
xmin = segs(j,1);
ymin = segs(j,2);
xmax = segs(j,3);
ymax = segs(j,4);
inst_id = segs(j,5);
lane_id = segs(j,6);
fprintf(fileID, ' ');
fprintf( fileID, ' %d', xmin );
fprintf( fileID, ' %d', ymin );
fprintf( fileID, ' %d', xmax );
fprintf( fileID, ' %d', ymax );
% rectangle('Position', [xmin ymin xmax-xmin ymax-ymin])
% NO inst_id CAUSE DONT CARE
fprintf( fileID, ' %d', lane_id ); % depth data -> lane_id
end
% waitforbuttonpress;
fprintf(fileID,'\n');
%% Visualize
% img_path = sprintf('%s\\f%05d.png',category,i-1);
% img = imread(img_path);
% mask_img = zeros(size(img,1), size(img,2));
%
% fig = figure(1);
% set(fig, 'position', [0, 0, 2000, 1000]);
% subplot(1,2,1);
% imshow(img);
% hold on;
% for j = 1:numLanes
% plot(splines{j}(:,1), splines{j}(:,2),'b.','markersize',6);
% end
% hold off
%
% subplot(1,2,2);
% imshow(img);
% hold on;
% for j = 1:size(segs,1)
% rectangle('Position',[segs(j,1),segs(j,2),gg,gg]);
% end
% hold off;
%
% waitforbuttonpress;
%% Make lane GT
% global_im=zeros(480,640);
% locc=segs(:,1:4);
% for ii=1:size(locc,1)
% im=zeros(480,640);
% temp=[locc(ii,1) locc(ii,2) locc(ii,3) locc(ii,2) locc(ii,3) locc(ii,4) locc(ii,1) locc(ii,4)];
% res=im2bw(insertShape(im,'FilledPolygon', temp));
% global_im=global_im|res;
% end
% ver = imresize(global_im,[60,80]);
% imwrite(ver,['./gt_caltech/' category '/' gLabelData.frames(i).frame]);
end
fclose('all');