In this report it will be explained how a surveillance video of a parking can be analyzed by means of different Computer Vision techniques in order to identify how many available parking lots there are. In particular, we will show first how parking lots are identified by their contour lines, and then how we find out whether they are empty or not.
1. The Parking Lot
Alessandro Florio - 161704
University of Trento
Department of Information Engineering and Computer Science
Master of Science in Computer Science
Abstract. In this report it will be explained how a surveillance video of
a parking can be analyzed by means of different Computer Vision tech-
niques in order to identify how many available parking lots there are.
In particular, we will show first how parking lots are identified by their
contour lines, and then how we find out whether they are empty or not.
2. Table of Contents
1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Frame analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1 Preprocessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Rectangle detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Identification of parking lots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.1 Polygon extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.2 Parking lot emptiness check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1 Introduction
In this section we will briefly explain how the algorithm is structured, leaving to
the following sections a more detailed description of each main subpart.
The algorithm is structured into two distinct phases and has a period of NFRAMES
- set to 200 - frames. One phase consists in identifying the parking lots in a frame,
as it will be explained in section 2, for the first NFRAMES-1 frames. The second
phase, which occurs at the remaining frame of each period, consists in analyzing
the output of the first one in order to detect where exactly parking lots are and
whether they are free or busy, as it will be explained in section 3.
2 Frame analysis
This phase takes one frame from the video and analyzes it to find out where
parking lots are; we recall that this phase is repeated for NFRAMES-1 frames
before passing to the second one.
2.1 Preprocessing
First of all, the frame is converted into a gray-scale image; then the Canny edge
detector algorithm is run to detect the possible edges. Since the Canny algorithm
produces two edges for each parking contour line, we dilate the output and then
compute its skeleton.
Grayscale Canny Skeleton
3. Once edges have been detected, the following step consists into defining lines,
which successively are going to identify parking lots. For this purpose, a proba-
bilistic Hough transform is applied to the skeleton image.
Skeleton Lines
2.2 Rectangle detection
In order to be able to detect a parking lot, we started from the assumption that
this is - in the real world - a rectangle. In the provided video, instead, there is
an unavoidable distortion, in addition to a non-aligned perspective. Moreover,
only three out of the four borders are painted on the asphalt.
Therefore, in this case we identify a parking lot as a pseudo-horizontal line which
intersects two pseudo-vertical lines. We consider horizontal lines all those lines
for which the absolute value of their slope is smaller or equal than 1/2, and
vertical lines all the remaining ones.
The algorithm then runs this way: for every line, if it is a vertical line we loop on
all the horizontal lines and see whether they intersect1
; if they do intersect, the
intersection point and the other endpoint of the vertical line are saved. When
all lines have been tested for a horizontal line, points closer than 15 pixels are
merged and substituted by their average, because they were probably generated
by other noise lines intersecting the horizontal one. Finally, if for that horizontal
line four points were found (two intersections and the other two endpoints of
the two vertical lines), a quadrilateral polygon is drawn on a temporary binary
image; if the number of points is greater than four but is even, it is the case that
the same horizontal line is detected for two different parking lots: so points are
ordered by the x coordinate, and taken four at a time, by shifting of two points,
because two intermediate points belong both to the first and to the second park-
ing lot. Also in this case, the quadrilateral polygons are drawn on the temporary
binary image.
1
Actually, lines are elongated by 12 pixels on each side because - due to erosion or
to a non-optimal configuration of the Hough transform - they may be shorter than
how they should be.
4. When parking lots have been drawn for all horizontal lines, the image containing
all the parking lots of the frame is added - with a transparency proportional to
NFRAMES - to another external image, which will collect all the parking lots
of the NFRAMES-1 frames.
3 Identification of parking lots
This phase takes the image produced by the fist phase for the previous NFRAMES-
1 frames; we recall that this phase occurs every NFRAMES frames, while for
the other frames only the first one is run2
.
3.1 Polygon extraction
As it can be seen in the image above, the input image of this phase is an average
of the parking lots found during all the iterations of the first phase. This step was
needed because little light changes from frame to frame led to different results in
the preprocessing and line identification steps. Taking the average instead leads
to more robust results.
Since at each frame the found lots were drawn white on a black background and
with an adequate transparency, in order to find the areas which were mostly
identified as parking lots, we have to consider the brighter pixels, and this is
done by thresholding the image into a binary image. After an opening operation
aimed at eliminating possible overlaps, contours of the different parking lots are
found, and polygons are substituted by their convex hull.
2
When this phase runs, the frame doesn’t take part to the parking lot identification.
However, since NFRAMES is a great number, a single frame doesn’t influence that
much, and allows a faster computation during this phase.
5. Input Thresholding, opening, convex hull
3.2 Parking lot emptiness check
Since cars parked at the center of the parking, where almost no distortion in
the video occurs, do not occlude the parking lines, those lots can be identified
as available; therefore it is useful to check whether they are really available or
not. This is done by computing the histogram of all the hulls obtained above
(in the HSV color space, and considering only hue and saturation), and then
comparing the histogram of each found lot with all the other; if the correlation
with other lots is overall greater than 25%, it is marked as a free parking lot,
otherwise either is the parking lot busy or it is not a parking lot at all, but a
noise polygon.
Input RGB
HSV Output
6. Finally, all the parking lots that have been found to be available are drawn
on the frame of the video that is going to be shown in a window, and will be
drawn until this second phase is repeated in the next iterations.
4 Results
We have presented a system able to detect available parking lots by finding
their contour lines, and to check whether they are available by comparing their
histograms with the ones of other found lots.
However, since too many parameters - which had to be found out empirically - are
involved, the algorithm is not 100% precise. In particular, we register both false
negatives (when the contour lines of the parking lot are not correctly detected
or are occluded by cars parked in the near lot) and false positives (when the
histogram check is not as accurate as desired). In our implementation we had
to make a trade-off between false positive and false negatives; in our opinion it
was more important to have few false positives and more false negatives rather
than the opposite: it is better to think a parking is full and maybe there is some
space, rather than believing it is free and not finding an available parking lot!
In some cases also one line dividing two parking lots was not detected, and at
the end two lots were recognized as a single one.
Moreover, due to light changes, even if the situation remains the same, the first
phase of the program can provide different result, and consequently also the
second phase from one time to another.
By analizing the results of the algorithm on the entire video, we came out with
a precision of 93.7%, meaning that we could well spot out busy parking lots,
but a recall of 64.7%, which shows that many false negatives were found, due to
the comparison of the area inside the found polygons through histograms. The
parameters we have set are strong enough to avoid in most cases false positives,
but too strong to correctly recognize free parking lots.
5 Conclusion
The parking lot detector provided works well in optimal situations, but still has
some problem with noise in frames. A greater video quality may reduce artifacts
that lead to wrong interpretations. Also having a video where different scenarios
were shown could have made the algorithm more robust to other situations whose
patterns could not be taken into account.