![]() |
To set up a parking lot camera for our project, Here we have used a downloaded video and converted it into an image. This setup allows us to simulate a real parking lot scenario for analysis. This approach enables us to experiment and develop our parking lot monitoring system without needing access to a real parking lot. This article’s main goal is to walk you through one of the simplest methods for creating a smart parking system with just a webcam and a few lines of Python code. Sample Video: Link ![]() Parking Video The Selector Image to choose the locationWe must construct the selector first. First, we import the necessary modules. Following that, we can set to work generating the image from which the parking spaces will be chosen. To do that, we can save the initial frame that the webcam captures, and utilize the image to choose the locations. The following code works like this:
Having saved the first frame in the image variable, we can now utilize the selectROIs function to identify our parking spaces. Regions of interest, or ROIs, are parts of the image to which various functions and filters will be applied in order to obtain the desired results. Using the selectROIs function once more, this will yield a list (type: numpy.ndarray) with the numbers we require to put together photos using their borders as our ROIs.
We’ll save our list in the “r” variable. The following are the arguments passed to the cv2.selectROIs function:
It’s time to enter all of the parking spaces that have been chosen into a.csv file. Once we get the correct data, we may save it in the.csv file that we will use in the future. ![]() Applying selector algorithm on all parking slots The Detector to process the ImageAfter parking spaces have been chosen, it’s time to process the images. The method I used to tackle this was:
Step 1: We must define a function for each of these operations so that it may be used at each location. This is how the function looks like:
Now that we have the function, all we need to do is apply it to each set of coordinates in the.csv file. First of all, we have several parameters that would be useful if we could change them in real time while the script is running, preferably via a GUI. To accomplish this, we need to construct a few track bars. Fortunately, OpenCV allows us to do so without requiring additional libraries. Step 2: First, we need a callback function that does nothing but serves as a parameter when producing track bars with OpenCV. Actually, the callback parameter has a specific purpose, but we do not use it here.
Step 3: Now we need to make the track bars. To accomplish this, we will use the cv2.namedWindow and cv2.createTrackbar functions.
Step 4: Now that we’ve constructed the GUI for operating the parameters, there’s just one thing remaining. This represents the number of available spots in the image. This is defined in the drawRectangle as spots.loc. This is a static variable that must be defined at the start of the program. This variable is static because we want the outcome of every drawRectangle function we call to be written to the same global variable rather than a different variable for each function. This ensures that the returned number of available spaces does not exceed the actual amount.
Step 5: Now that we’re almost there, all we need to do is extract the data from the.csv file, convert it all to integers, and run our created functions in an infinite loop.
Understanding the Loop in Our Script
What remains is to write the number of available spots on the resulting image, display the Canny function and result. Output Video ConclusionSmart parking is a popular topic these days, and there are numerous implementations that can lead to a well-functioning system. I am aware that this is not ideal there are many alternatives that are more tuned and can operate in a variety of situations. |
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 22 |