-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorcheck.m
More file actions
45 lines (44 loc) · 1.48 KB
/
errorcheck.m
File metadata and controls
45 lines (44 loc) · 1.48 KB
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
clear
load frame
I = rgb2gray(frame);
BW = imbinarize(I);
out = edge(I, 'Roberts');
[H,T,R] = hough(out);
P = houghpeaks(H, 3, 'threshold', ceil(0.3*max(H(:))));
lines = houghlines(BW, T, R, P, 'FillGap', 5, 'MinLength', 7);
out = uint8(repmat(out, 1, 1, 3)) .* 255;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
xspace = xy(1, 1):xy(2, 1);
yspace = fix(xy(1, 2) + xspace*(xy(2,2)-xy(1, 2))/(xy(2, 1)-xy(1, 1)));
if sum(yspace < 0) > 0
yspace = yspace(yspace > 0);
xspace = xspace(1:length(yspace));
end
% error check block
try
for i = 1:length(xspace)
out(yspace(i), xspace(i),1) = 0;
out(yspace(i), xspace(i),3) = 0;
end
catch
tmpxSpc = xspace;
tmpySpc = yspace;
tmpki = [k i];
return
end
if xy(1, 2) <= xy(2, 2)
centroids(k, :) = [xy(1, 1) + (xy(2, 1) - xy(1, 1))/2, ...
xy(1, 2) + (xy(2, 2) - xy(1, 2))/2];
bboxes(k, :) = [xy(1, 1) xy(2, 2) (xy(2, 1) - xy(1, 1))...
xy(2, 2) - xy(1, 2)];
else
centroids(k, :) = [xy(1, 1) + (xy(2, 1) - xy(1, 1))/2, ...
xy(2, 2) + (xy(1, 2) - xy(2, 2))/2];
bboxes(k, :) = [xy(1, 1) xy(1, 2) (xy(2, 1) - xy(1, 1))...
xy(1, 2) - xy(2, 2)];
end
end
mask = ones(size(BW));
mask(find(out(:, :, 2)> 200 & out(:, :, 1) == 0 & ...
out(:, :, 1) == 0)) = 0;