Parking Slot Detection Github
Parking-slot-markings recognition algorithm, which is used to automate the target position selection of automatic parking assist system. Peak-pair detection and clustering in Hough space recognize marking lines. Specially, one-dimensional filter in Hough space is designed to utilize a priori knowledge about. 5) Monitor the state of a parking slot. The parking slot may be fully in use or free. This system seeks to constantly monitor what is happening in the slot to identify parking spaces that are available or occupied. 6) Collect the time and date of activities happening in a given parking slot. Every time the state of the parking slots.
Dataset Download
You can download CNRPark+EXT using the following links:
CNRPark+EXT.csv (18.1 MB)
CSV collecting metadata for each patch of both CNRPark and CNR-EXT datasets
CNRPark-Patches-150x150.zip (36.6 MB)
segmented images (patches) of parking spaces belonging to the CNRPark preliminary subset.
Files follow this organization:<CAMERA>/<CLASS>/YYYYMMDD_HHMM_<SLOT_ID>.jpg
, where:<CAMERA>
can beA
orB
,<CLASS>
can befree
orbusy
,YYYYMMDD_HHMM
is the zero-padded 24-hour capture datetime,<SLOT_ID>
is a local ID given to the slot for that particular camera
E.g:
A/busy/20150703_1425_32.jpg
CNR-EXT-Patches-150x150.zip (449.5 MB)
segmented images (patches) of parking spaces belonging to the CNR-EXT subset.
Files follow this organization:PATCHES/<WEATHER>/<CAPTURE_DATE>/camera<CAM_ID>/<W_ID>_<CAPTURE_DATE>_<CAPTURE_TIME>_C0<CAM_ID>_<SLOT_ID>.jpg
,
where:<WEATHER>
can beSUNNY
,OVERCAST
orRAINY
,<CAPTURE_DATE>
is the zero-paddedYYYY-MM-DD
formatted capture date,<CAM_ID>
is the number of the camera, ranging1
-9
,<W_ID>
is a weather identifier, that can beS
,O
orR
,<CAPTURE_TIME>
is the zero-padded 24-hourHH.MM
formatted capture time,<SLOT_ID>
is a global ID given to the monitored slot; this can be used to uniquely identify a slot in the CNR-EXT dataset.
E.g:
PATCHES/SUNNY/2015-11-22/camera6/S_2015-11-22_09.47_C06_205.jpg
The
LABELS
folder contains a list file for each split of the dataset used in our experiments. Each line in list files follow this format:<IMAGE_PATH> <LABEL>
, where:<IMAGE_PATH>
is the path to a slot image,<LABEL>
is0
forfree
,1
forbusy
.
CNR-EXT_FULL_IMAGE_1000x750.tar (1.1 GB)
full frames of the cameras belonging to the CNR-EXT subset. Images have been downsampled from 2592x1944 to 1000x750 due to privacy issues.
Files follow this organization:FULL_IMAGE_1000x750/<WEATHER>/<CAPTURE_DATE>/camera<CAM_ID>/<CAPTURE_DATE>_<CAPTURE_TIME>.jpg
,
where:<WEATHER>
can beSUNNY
,OVERCAST
orRAINY
,<CAPTURE_DATE>
is the zero-paddedYYYY-MM-DD
formatted capture date,<CAM_ID>
is the number of the camera, ranging1
-9
,<CAPTURE_TIME>
is the zero-padded 24-hourHHMM
formatted capture time.
The archive contains also 9 CSV files (one per camera) containing the bounding boxes of each parking space with which patches have been segmented. Pixel coordinates of the bouding boxes refer to the 2592x1944 version of the image and need to be rescaled to match the 1000x750 version.
splits.zip (27.2 MB)
all the splits used in our experiments. Those splits combine our datasets and also third-party datasets (such as PKLot).
For a fun weekend project, I decided to play around with the OpenCV (Open Source Computer Vision) library in python.
OpenCV is an extensive open source library (available in python, Java, and C++) that’s used for image analysis and is pretty neat.
The lofty goal for my OpenCV experiment was to take any static image or video of a parking lot and be able to automatically detect whenever a parking space was available or occupied.
Through research and exploration, I discovered how lofty of a goal that was (at least for the scope of a weekend). What I was able accomplish was to detect how many spots were available in a parking lot, with just a bit of upfront work by the user.
This page is a walkthrough of my process and what I learned along the way.
I’ll start with an overview, then talk about my process, and end with some ideas for future work.
Overview
The above link takes you to a video of the parking space detection program in action.
To run:
Program flow is as follows:
- User inputs file name for a video, a still image from the video, and a path for the output file of parking space coordinates.
- User clicks 4 corners for each spot they want tracked. Presses ‘q’ when all desired spots are marked.
- Video begins with the user provided boxes overlayed the video. Occupied spots initialized with red boxes, available spots with green.
- Car leaves a space, the red box turns green.
- Car drives into a free space, the green box turns red.
The data on the entering and exiting of these cars can be used for a number of purposes: closest spot detection, analytics on parking lot usage, and for those counters outside of parking garages that tell you how many cars are on each level (to name a few).
This project was my first tour through computer vision, so to get it working in a weekend, I went the “express learning” route. That consisted of auditing this Computer Vision and Image Analytics course, reading through OpenCV documentation, querying the net, and toggling OpenCV function parameters to see what happened. Overall, a lot of learning and a ton of fun.
Process
The beginning
My first thought was how can I tell whether a parking space is empty?
Well, if a space is empty, it would be the color of the pavement. Otherwise, it wouldn’t be.
I also knew that I needed a way to mark the boundaries of the space, so that I could return the number of spots available.
Let’s grab an image and head to the OpenCV docs!
Line Detection
To detect the parking spots, I knew I could take advantage of the lines demarking the boundaries.
The Hough Transform is a popular feature extraction technique for detecting lines. OpenCV encapsulates the math of the Hough Transform into HoughLines(). Further abstraction in captured in HoughLinesP(), which is the probabilistic model of creating lines with the points that HoughLines() returns. For more info, check out the OpenCV Hough Lines tutorial.
The following is a walkthrough to prepare an image to detect lines with the Hough Transform. Links point to OpenCV documentation for each function. Arguments for each function are given as keyword args for clarity.
Reading in this image:
I converted it to gray scale to reduce the info in the photo:
Gave it a good Gaussian blur to remove even more unnecessary noise:
Detected the edges with Canny:
And then, a few behind-the-scenes rhos and thetas later, we have our Hough Line results.
Well that wasn’t quite what I expected.
I experimented a bit with the hough line, but toggling the parameters kept getting me the same one line.
A bit of digging and I found a promising post on StackOverflow
After following the directions of the top answer, I got this:
Which gave me more lines, but I still had to figure out which lines were part of the parking space and which weren’t. Then, I would also need to detect when a car moved from a spot.
I was running into a challenge; with this approach, I needed an empty parking lot to overlay with an image of a non-empty lot. Which would also call for a mask to cover unimportant information (trees, light posts, etc.)
Given my scope for the weekend, it was time to find another approach.
Drawing Rectangles
If my program wasn’t able to detect parking spots on it’s own, maybe it was reasonable to expect that the user give positions for each of the parking spots.
Now, the goal was to find a way to click on the parking lot image and to store the 4 points that made up a parking space for all of the spaces in the lot.
I discovered that I could do this using a mouse as a “paintbrush”
After some calculations for the center of the rectangle (to label each space), I got this:
Finishing touches
Parking Slot Detection Github Failed
After drawing the rectangles, all there was left to do was examine the area of each rectangle to see if there was a car in there or not.
Parking Slot Detection Github Tool
By taking each (filtered and blurred) rectangle, determining the area, and doing an average on the pixels, I was able to tell when there wasn’t a car in the spot if the average was high (more dark pixels). I changed the color of the bounding box accordingly and viola, a parking detection program!
The code for drawing the rectangles and motion detection is pretty generic. It’s seperated out into classes and should be reusable outside of the context of a parking lot. I have tested this with two different parking lot videos and it worked pretty well. I plan to make other improvements and try to seperate OpenCV references to make code easier to test. I’m open to ideas and feedback.
Check out the code for more!
Future work
- Hook up a webcam to a Raspberry Pi and have live parking monitoring at home!
- Transform parking lot video to have overview perspective (for clearer rectangles)
- Experiment with HOG descriptors to detect people or other objects of interest