Parking Space Management
Last updated
Last updated
Date: 2021-6-21
Author: 강지훈, 도경민
Github: https://github.com/chloerudals/DLIP_LAB4
Demo Video:
Since the use of private vehicle has increased due to COVID-19, finding parking spaces has been difficult even in our university. Thus, we decided to show the empty parking spaces on the screen to make parking management easier.
Algorithm: 1. Parking lines are detected using HoughlinesP and cars are detected using Yolov5s 2. We improved the detection of parking lines, which had previously been covered by parked cars, by elongating the lines 3. We divided the rectangle the same number as the parking lot. 4. Adjusted distorted regions due to perspectives. 5. By comparing the center of the parking space and the center of the detected box, parking ability is decided. 6. Since cars park in the upper part of the parking space, y axis of the detected box's center is corrected about 10 pixels 7. If a car comes in the camera frame, the car is considered as parking so entering car is printed.
Hardware
NVDIA graphic cards
Software
CUDA
cuDNN
Anaconda
YOLO V5
Or You can follow the instructions from the yolov5 GitHub repository. (requirements)
Before starting, check your gpu to match the version.
First, you need a parking lot's picture to detect the parking lines. (an empty parking lot image would be perfect.)
Image processing is conducted.
Since the lines are mostly white and yellow, select only yellow and white colors from the image.
def select_rgb_white_yellow(image):
Convert the image to gray scale.
Detect the edges with Canny.
Crop the image using roi.
def filter_region(image, vertices): def select_region(image):
Using HoughlinesP, detect the vertical parking lines.
def hough_lines(image): def draw_lines(image, lines, color=[255, 0, 0], thickness=2, make_copy=True):
Draw a rectangle.
def identify_blocks(image, lines, make_copy=True):
Adjust the rectangle.
Merge the rectangle with the adjusted verticle lines to delineate the parking lines.
Count the total parking spaces.
def draw_parking(image, rects, make_copy = True, color=[255, 0, 0], thickness=1, save = True):
Assign a number to the parking spaces.
def assign_spots_map(image, spot_dict=final_spot_dict, make_copy = True, color=[255, 0, 0], thickness=2):
To see a detailed explanation. Click Here
Car detection is done by YOLO V5s with COCO datasets.
Firstly, find the centers of the parking space and the car.
If the distance between the centers are less than 40, the parking space is determined as occupied.
Since we are using 'YOLO V5s model', we set the default for weights as 'yolov5s'.
Image size is set = 608
conf-thres value = 0.3
iou-thres value = 0.4
view-img's action is set as 'store_false' to view the image.
save-txt's action is set as 'store_false' to save the result.
classes's default is added as 2 to only view car class.
The bounding box's line-thickness is edited to 2.
parser.add_argument('--weights', nargs='+', type=str, default='yolov5s.pt', help='model.pt path(s)')
parser.add_argument('--img-size', type=int, default=608, help='inference size (pixels)')
parser.add_argument('--conf-thres', type=float, default=0.3, help='object confidence threshold')
parser.add_argument('--iou-thres', type=float, default=0.4, help='IOU threshold for NMS')
parser.add_argument('--view-img', action='store_false', help='display results')
parser.add_argument('--save-txt', action='store_false', help='save results to *.txt')
parser.add_argument('--classes', nargs='+', type=int, default=2, help='filter by class: --class 0, or --class 0 2 3')
parser.add_argument('--line-thickness', default=2, type=int, help='bounding box thickness (pixels)')
Download video to your yolov5 repository.
Download image to your yolov5\data\images directory.
Overwrite detect.py to the yolov5 repository.
Overwrite datasets.py to your yolov5\utils directory.
Detect the parking lines without conducting parking space image and adjusting the lines.
Specify the vehicles whether they are entering, leaving or staying for a minute.
Give an alarm to the securitary, if there is a double-parked car.
To watch a short explanatory video. Click Here