View all Blog

Building a Camera-Based Parking Detection System using VisionAgent

Ankit Khare
January 21, 2025

Picture this: you pull into a busy community parking lot or a shopping mall, and instead of driving circles to hunt for an open space, a digital sign or an app guides you straight to the nearest empty spot. That’s the promise of an automated, camera-based parking detection system. In this post, we’ll take a no-fuss approach to show how you can use VisionAgent to build just that—without layers of complex logic. VisionAgent is a generative Visual AI application builder that follows an agentic framework to handle complex visual tasks requiring reasoning. It modularizes tool selection to pick the best visual tool for a task and leverages built-in visual design patterns to solve particularly complex visual problems.

Why This Matters

  • Saves Time: No more circling around looking for a space. Drivers can see free spots immediately.
  • Reduces Congestion: Less wandering traffic means fewer queues and less frustration.
  • Easy Setup: A few cameras placed around the lot, plus VisionAgent’s detection tools, can get you started quickly.

The Basic Idea

  • Camera Feeds: You install a camera (or cameras) overlooking rows of parking spaces.
  • Car Detection: Every few seconds, you capture a frame from the camera and feed it into your application created using vision code generated by VisionAgent.
  • Empty Spot Identification: Identify which parking stalls are unoccupied by spotting gaps between detected cars (or by labeling parking stall outlines). VisionAgent helps you write the initial code for this, which you can modify yourself or re-prompt VisionAgent to optimize for you.
  • Live Updates: Show a list of empty spots or a real-time feed with bounding boxes drawn in green for empty spaces and red for occupied.

VisionAgent-powered Empty Parking Spots Detector, allowing users to upload parking-lot images for analysis

How VisionAgent Helps

  • Easy Chat Interface: You can prompt the VisionAgent, and it analyzes your prompt to find an optimal solution by breaking down the problem into several solvable steps. Generally, most steps involve writing vision code to solve your problem. For this application, I gave the initial prompt, “find empty car spots,” along with an image, and the VisionAgent planner agentically comes out with the following execution pathway:
    1. Use countgd_object_detection model to detect all cars in the image.
    2. Sort and group detections into horizontal lines.
    3. Analyze gaps between cars to identify empty spots.
    4. Combine car detections and empty spots.
    5. Visualize results with bounding boxes and save the final image.

    VisionAgent leverages an LLM at various steps to verify its observations and create a pathway to solve the problem.

  • Quick Object Detection: VisionAgent has a built-in library of models that it uses to find a suitable model for you, like countgd_object_detection, which can readily identify cars (and even trucks, SUVs, etc.), potentially saving tons of time that goes into model selection and configuration.
  • Flexible Integration: In just a few lines of Python (often combined with Streamlit), you can build a straightforward web interface for viewing camera feeds and utilizing the code generated by the VisionAgent.

Inside the VisionAgent workspace: The system processes the uploaded parking-lot image, executes code to detect cars and empty spaces, and leverages a clear, interactive interface for real-time analysis

VisionAgent UI: The agent outputs the final solution showing the code, code output and it’s visualization

A Lightweight Pipeline

1. Capture an Image

From a webcam, IP camera, or a static snapshot.

2. Detect Cars

detections = countgd_object_detection("car", image)

3. Identify Empty Spots

Either by computing gaps between bounding boxes or by detecting each stall (if you have labeled them in advance). Mark those empty stall            regions as “empty_spot” with a green bounding box.

4. Visualize & Report

Draw bounding boxes:

Print or display the number of cars vs. empty spots.

overlay_bounding_boxes(image, all_detections)

Application Interface showing the annotated image where detected cars (yellow bounding boxes) and empty spots (green bounding boxes) are marked accompanied by detailed statistics on total spots, parked cars, and empty spots

Example Code Snippet

from vision_agent.tools import countgd_object_detection, overlay_bounding_boxes

def detect_parking(image):
    # 1. Detect cars
    car_detections = countgd_object_detection("car", image)

    # 2. Find empty spots (simplified approach: check horizontal gaps, etc.)
    # ... minimal logic to find 'empty_spot' bounding boxes ...

    empty_spots = [
        {"label": "empty_spot", "bbox": [100, 50, 200, 120], "color": (0, 255, 0)}
    ]

    # 3. Combine results & overlay
    all_detections = car_detections + empty_spots
    annotated_img = overlay_bounding_boxes(image, all_detections)

    return annotated_img, all_detections

You would then display annotated_img  in your interface and maybe show the count of detected cars vs. empty spots.

Challenges & Tips

  • Camera Angle: Make sure the camera has a clear view of each parking space.
  • Lighting: Day vs. night can change how well cars are detected. Infrared cameras or good lighting can help.
  • Parking Layout: Some lots have angled slots or half-faded lines, so you might need to tweak your logic for finding empty spots.
  • Performance: If you want real-time detection (e.g., multiple frames per second), you might have to train an efficient model using VisionAgent’s custom model feature where you can input your data and train custom models tailored specifically to your task.

Bring It All Together

  1. Install the VisionAgent Python package.
  2. Set up a camera or upload test photos.
  3. Write a short script or a Streamlit app that:
    • Grabs a frame from the camera.
    • Calls detect_parking (or your variant).
    • Displays the annotated image, plus simple stats like “Cars: X, Empty Spots: Y.”
  4. Refine as needed—perhaps add a “Parking Occupancy: 80% Full” to your user interface.

With VisionAgent handling most of the vision code, you can build a simple, practical parking-lot monitoring system without getting bogged down in advanced computer-vision complexity. In no time, you’ll have a real-time feed telling drivers, “Hey, there’s a green spot open in row 2!”—and that’s an easy win for everyone. Download the full code from this repository, run the Streamlit app locally, and enjoy!

Get LandingAI's Monthly Newsletter

Stay updated with the latest computer vision and AI news and resources delivered to your inbox.

Related Resources