# Automatic 2D Floorplan CAD Generation from 3D Point Clouds
## 3 Proposed Method
### Wall Detection
We then detect actual walls from the wall candidate lines. The expected result is presented in Figure 2(c). Algorithm 2 has the following steps:  
* Inputs are the depth image that results from Algorithm 1 and the thresholds, i.e., minimum points for the wall line, \(minPoints\); minimum length of the wall line, \(minLen\); and determined area, \(detArea\). * Define the wall candidate lines, \(clines\) (lines between 1 and 6). If a pixel, \(depthImg_{ij}\), has an intensity value greater than 0, i.e., the pixel is not black, then the pixel is a part of the wall candidate lines. Therefore, the horizontal and vertical lines that pass the pixel are drawn. In detail, the horizontal and vertical lines are described by two points: \((0,j)\) and \((depthImg.cols-1,j)\), and \((i,0)\) and \((i,depthImg.rows-1)\). This process is repeatedly done for all pixels in \(depthImg\). * Define actual wall lines from wall candidate lines (lines between 7 and 20). First, we check the pixels in each wall candidate line, \(clines\). If there are points around the pixel within the predefined area threshold (the default value is 50 pixels), it means that the pixel can be a part of the wall line. We set an area threshold value because there are some missing points and noise from the LIDAR sensor. We set \(pLines[i]\) to 1 if the \(i\)-th pixel satisfies the condition, and set it to 0 otherwise. As a result, we obtain the \(pLines\) vector, which is a sequence of 0 and 1 for each wall candidate line. The size of the \(pLines\) vector is equal to the width and height of the depth image for the horizontal and vertical wall candidate lines, respectively. Based on the \(pLines\) vector, we determine the actual wall lines using the thresholds, i.e., minimum points on the wall line, \(minPoints\), and minimum length of the wall line, \(minLen\). For example, if \(pLines=\{1,1,1,1,1,1,0,0,0,1,1,1,1,1\}\), we can see two sequences of ones. If these two sequences meet the threshold condition, they are determined to be actual wall lines. ```
Input: Depth image \(depthImg\), threshold of minimum points in wall line \(minPoints\), threshold of minimum length of wall line \(minLen\), threshold of determined area \(detArea\) Output: Wall Lines contains wall informations
1 Create array contains horizontal and vertical lines \(clines\);
2 for each pixel in \(depthImg\)do
3 if (a pixel value of \(depthImg_{ij}\)) > 0 then
4 Save points corresponding horizontal and vertical lines, \((0,j)\) and \((depthImg.cols-1,j)\), \((i,0)\) and \((i,depthImg.rows-1)\) to \(clines\);
5 end for
6
7
8 end for
9
10 Create an array \(wallLines\);
11 for each line \(l\) in \(clines\)do
12 Create a zero array with the same size of \(l\), \(pLines\);
13 foreach pixel \(i\) in \(l\)do
14 if there are points around \(i\) within \(detArea\)then
15\(pLines[i]\) = 1;
16
17 end for
18
19 end for
20
21 Detect sequences of 1 from \(pLines\);
22 if sequence has more points than \(minPoints\) and is longer than \(minLen\)then
23 Store detected sequence to \(wallLines\);
24
25 end for
26
27 end for return\(wallLines\)
```  
**Algorithm 2**Detect Wall Lines from Wall Candidate Lines.