-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParseGround.m
65 lines (46 loc) · 2.51 KB
/
ParseGround.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
function [GroundPlane, PosHeight, SegRaw, GroundRaw, Edges] = ParseGround( dispar,focal,basel,x0,sx,y0,sy,imgRgb,model, p1 )
% ---------------------- Parameters for Ground Parsing --------------------
DepthShrink_Para = p1.DepthShrink_Para;
MinGridRegion_Para = p1.MinGridRegion_Para;
stepZ = p1.stepZ;
stepX = p1.stepX;
MinGroundRegion_Para = p1.MinGroundRegion_Para;
GroundEdge_RefinePara = p1.GroundEdge_RefinePara;
maxDistance = p1.maxDistance;
Edge_Para = p1.Edge_Para;
% -------------------------------------------------------------------------
[height, width] = size(dispar);
%% ============ GRID Segmentation for Finding Ground Plane
dispar = double(dispar);
[SegRaw, GroundRaw] = SegGRID_Ground_mex(dispar,focal,basel,x0,sx,MinGridRegion_Para,DepthShrink_Para,stepZ,stepX);
GroundPlane = GroundRaw;
%% ============== Fit Plane & Get Height
dispar = double(dispar);
xyzPoints = zeros(height,width,3);
worldZ = (focal * basel) ./ dispar;
worldX = (repmat(1:width,height,1)-x0).*worldZ/(focal/sx);
worldY = (repmat((1:height)',1,width)-y0).*worldZ/(focal/sy);
xyzPoints(:,:,1) = worldX;
xyzPoints(:,:,2) = worldY;
xyzPoints(:,:,3) = worldZ;
xyzPoints = xyzPoints * 1000;
GroundPoints = [worldX(GroundPlane==1), worldY(GroundPlane==1), worldZ(GroundPlane==1)];
GroundPoints = GroundPoints * 1000;
ptCloud = pointCloud(GroundPoints);
[modelPlane,inlierIndices,outlierIndices] = pcfitplane(ptCloud,maxDistance);
PlaneP = modelPlane.Parameters;
xyzPoints(:,:,2) = xyzPoints(:,:,2) - ((PlaneP(4)-PlaneP(1)*xyzPoints(:,:,1)-PlaneP(3)*xyzPoints(:,:,3))/PlaneP(2));
PosHeight = -xyzPoints(:,:,2);
PosHeight(abs(PosHeight)==Inf)=NaN;
GroundHeight = nanmean(PosHeight(GroundPlane==1));
GroundPlane = uint8((GroundPlane==1) | (PosHeight<GroundHeight));
GroundPlane = logical(GroundPlane);
GroundPlane = MergeSeg_Ground_mex(GroundPlane,GroundEdge_RefinePara,height*width/MinGroundRegion_Para);
PosHeight = PosHeight - GroundHeight;
PosHeight(PosHeight<0) = 0;
%% ============== Refine according to RGB
Edges = edgesDetect(imgRgb,model);
Edges = 1 - Edges;
GroundPlane = logical(GroundPlane);
GroundPlane = GroundRefine_mex(Edges,GroundPlane,Edge_Para);
end