📚
DLIP
  • Introduction
  • Prerequisite
  • Image Processing Basics
    • Notes
      • Thresholding
      • Spatial Filtering
      • Masking with Bitwise Operation
      • Model n Calibration
    • Tutorial
      • Tutorial: Install OpenCV C++
      • Tutorial: Create OpenCV Project
      • Tutorial: C++ basics
      • Tutorial: OpenCV Basics
      • Tutorial: Image Watch for Debugging
      • Tutorial: Spatial Filter
      • Tutorial: Thresholding and Morphology
      • Tutorial: Camera Calibration
      • Tutorial: Color Image Processing
      • Tutorial: Edge Line Circle Detection
      • Tutorial: Corner Detection and Optical Flow
      • Tutorial: OpenCV C++ Cheatsheet
      • Tutorial: Installation for Py OpenCV
      • Tutorial: OpenCv (Python) Basics
    • LAB
      • Lab Report Template
      • Lab Report Grading Criteria
      • LAB Report Instruction
      • LAB: Grayscale Image Segmentation
        • LAB: Grayscale Image Segmentation -Gear
        • LAB: Grayscale Image Segmentation - Bolt and Nut
      • LAB: Color Image Segmentation
        • LAB: Facial Temperature Measurement with IR images
        • LAB: Magic Cloak
      • LAB: Straight Lane Detection and Departure Warning
      • LAB: Dimension Measurement with 2D camera
      • LAB: Tension Detection of Rolling Metal Sheet
  • Deep Learning for Perception
    • Notes
      • Lane Detection with Deep Learning
      • Overview of Deep Learning
        • Object Detection
        • Deep Learning Basics: Introduction
        • Deep Learning State of the Art
        • CNN, Object Detection
      • Perceptron
      • Activation Function
      • Optimization
      • Convolution
      • CNN Overview
      • Evaluation Metric
      • LossFunction Regularization
      • Bias vs Variance
      • BottleNeck Unit
      • Object Detection
      • DL Techniques
        • Technical Strategy by A.Ng
    • Tutorial - PyTorch
      • Tutorial: Install PyTorch
      • Tutorial: Python Numpy
      • Tutorial: PyTorch Tutorial List
      • Tutorial: PyTorch Example Code
      • Tutorial: Tensorboard in Pytorch
      • Tutorial: YOLO in PyTorch
        • Tutorial: Yolov8 in PyTorch
        • Tutorial: Train Yolo v8 with custom dataset
          • Tutorial: Train Yolo v5 with custom dataset
        • Tutorial: Yolov5 in Pytorch (VS code)
        • Tutorial: Yolov3 in Keras
    • LAB
      • Assignment: CNN Classification
      • Assignment: Object Detection
      • LAB: CNN Object Detection 1
      • LAB: CNN Object Detection 2
      • LAB Grading Criteria
    • Tutorial- Keras
      • Train Dataset
      • Train custom dataset
      • Test model
      • LeNet-5 Tutorial
      • AlexNet Tutorial
      • VGG Tutorial
      • ResNet Tutorial
    • Resource
      • Online Lecture
      • Programming tutorial
      • Books
      • Hardware
      • Dataset
      • Useful sites
  • Must Read Papers
    • AlexNet
    • VGG
    • ResNet
    • R-CNN, Fast-RCNN, Faster-RCNN
    • YOLOv1-3
    • Inception
    • MobileNet
    • SSD
    • ShuffleNet
    • Recent Methods
  • DLIP Project
    • Report Template
    • DLIP 2021 Projects
      • Digital Door Lock Control with Face Recognition
      • People Counting with YOLOv4 and DeepSORT
      • Eye Blinking Detection Alarm
      • Helmet-Detection Using YOLO-V5
      • Mask Detection using YOLOv5
      • Parking Space Management
      • Vehicle, Pedestrian Detection with IR Image
      • Drum Playing Detection
      • Turtle neck measurement program using OpenPose
    • DLIP 2022 Projects
      • BakeryCashier
      • Virtual Mouse
      • Sudoku Program with Hand gesture
      • Exercise Posture Assistance System
      • People Counting Embedded System
      • Turtle neck measurement program using OpenPose
    • DLIP Past Projects
  • Installation Guide
    • Installation Guide for Pytorch
      • Installation Guide 2021
    • Anaconda
    • CUDA cuDNN
      • CUDA 10.2
    • OpenCV
      • OpenCV Install and Setup
        • OpenCV 3.4.13 with VS2019
        • OpenCV3.4.7 VS2017
        • MacOS OpenCV C++ in XCode
      • Python OpenCV
      • MATLAB-OpenCV
    • Framework
      • Keras
      • TensorFlow
        • Cheat Sheet
        • Tutorial
      • PyTorch
    • IDE
      • Visual Studio Community
      • Google Codelab
      • Visual Studio Code
        • Python with VS Code
        • Notebook with VS Code
        • C++ with VS Code
      • Jupyter Notebook
        • Install
        • How to use
    • Ubuntu
      • Ubuntu 18.04 Installation
      • Ubuntu Installation using Docker in Win10
      • Ubuntu Troubleshooting
    • ROS
  • Programming
    • Python_Numpy
      • Python Tutorial - Tips
      • Python Tutorial - For Loop
      • Python Tutorial - List Tuple, Dic, Set
    • Markdown
      • Example: API documentation
    • Github
      • Create account
      • Tutorial: Github basic
      • Tutorial: Github Desktop
    • Keras
      • Tutorial Keras
      • Cheat Sheet
    • PyTorch
      • Cheat Sheet
      • Autograd in PyTorch
      • Simple ConvNet
      • MNIST using LeNet
      • Train ConvNet using CIFAR10
  • Resources
    • Useful Resources
    • Github
Powered by GitBook
On this page
  • Introduction
  • Requirements
  • Follow the steps for setting YOLO V5 in the Anaconda.
  • Essential codes to understand the program.
  • How to run the program
  • Future work
  • Reference

Was this helpful?

  1. DLIP Project
  2. DLIP 2021 Projects

Parking Space Management

PreviousMask Detection using YOLOv5NextVehicle, Pedestrian Detection with IR Image

Last updated 3 years ago

Was this helpful?

Date: 2021-6-21

Author: 강지훈, 도경민

Github:

Demo Video:


Introduction

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.

Requirements

  1. Hardware

    • NVDIA graphic cards

  2. Software

    • CUDA

    • cuDNN

    • Anaconda

    • YOLO V5

Follow the steps for setting YOLO V5 in the Anaconda.

Before starting, check your gpu to match the version.

  # create a conda env name=yolov5 (you can change your env name)
  conda create -n yolov5 python=3.8
  conda activate yolov5
  
  # Installation process
  conda install cudatoolkit=10.2
  conda install cudnn
  conda install tensorflow-gpu=2.3.0
  conda install keras
  conda install pillow
  conda install matplotlib
  conda install opencv
  
  # clone yolov5
  git clone https://github.com/ultralytics/yolov5.git
  
  # update
  conda update -yn base -c defaults conda
  
  # install Lib for YOLOv5
  conda install -c anaconda cython numpy pillow scipy seaborn pandas requests
  conda install -c conda-forge matplotlib pyyaml tensorboard tqdm opencv 
  # install pytorch
  conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
 
  # Extra
  conda install -c conda-forge onnx

Essential codes to understand the program.

Finding the parking lines.

  • 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.

  def convert_gray_scale(image):

Detect the edges with Canny.

  def detect_edges(image, low_threshold=500, high_threshold=1000):
  • 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):

Detect cars.

  • Car detection is done by YOLO V5s with COCO datasets.

Distinguish whether the parking space is empty or not.

  • 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.

for *xyxy, conf, cls in reversed(det):
    bx1, by1, bx2, by2 = xyxy[0], xyxy[1], xyxy[2], xyxy[3]
    bcx, bcy = abs(bx2 + bx1) / 2, abs(by2 + by1) / 2 + 10
    cv2.circle(im0, (int(bcx), int(bcy)), 5, (255, 255, 255), 2)
    parking_distance = math.sqrt((bcx - pcx)**2 + (bcy - pcy)**2)

    if parking_distance < 40:
        cv2.polylines(im0, [poly_points], 1, [0, 0, 255], 2)
        cv2.line(im0, (int(bcx), int(bcy)), (int(pcx), int(pcy)), (255, 255, 255), 2)
        cv2.putText(im0, "%d" %spot_cnt, text_coordinate, cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 3)
        Parked_Space_Array.append(spot_cnt)
        break

Editing Parser

  • 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)')

How to run the program

Future work

  • 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.

Reference

To watch a short explanatory video.

Or You can follow the instructions from the yolov5 GitHub repository.

To see a detailed explanation.

Download to your yolov5 repository.

Download to your yolov5\data\images directory.

Overwrite to the yolov5 repository.

Overwrite to your yolov5\utils directory.

(requirements)
Click Here
Demo Video
video
image
detect.py
datasets.py
dudesparsh: Parking detector
https://github.com/chloerudals/DLIP_LAB4
Click Here
detect edges
rect
roi
parking lot
gray
line
delineated_image
marked_spot_images