現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to detect free spots in a parking area?
2 ビュー (過去 30 日間)
古いコメントを表示
Hello All,
I am working on a project which is to detect vacant spots in a park. I have a row of 10 spots on a small model just like in the images attached here:
I want to write a program that tells the webcam to take an image and when there is motion, take another image and compare the two to tell how many spots are available.
Please provide a source code with any explanation that you know will aid me.
Thank you.
4 件のコメント
manpreet singh
2014 年 5 月 17 日
Hello Hazha,
I am working on the same project, can you please share your code with me. I am looking for an idea.
Kind Regards.
karthik devaraj
2018 年 3 月 28 日
Hello have you done this ? Kindly help me win your code to detect car parking please
Hazman Mat Husin
2018 年 11 月 22 日
Hi hazha, im from uthm and my final project is about this.. can i get the coding please?if you there please email me at hazmanmathusin@yahoo.com
Pratiksha Pradhan
2020 年 10 月 7 日
Hello, I am doing something similar for an undergraduate school project. Could you please share your code for reference?
採用された回答
Image Analyst
2014 年 4 月 20 日
See my attached demo that detects motion in a video. You'll just have to replace read() with getsnapshot(), or snapshot if you're using the new webcam add-on introduced with R2014a.
To see if a parking spot is taken, just compare the color in the known locations to black. Do it for every color channel.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Get means in the rectangle of this parking place.
redMean = mean2(redChannel(row1:row2, col1:col2));
greenMean = mean2(greenChannel(row1:row2, col1:col2));
blueMean = mean2(blueChannel(row1:row2, col1:col2));
% Set a flag to say if it's taken or not.
taken = abs(redMean - redBlack) > tolerance & abs(greenMean- greenBlack) > tolerance & abs(blueMean - blueBlack) > tolerance;
Of course you have to know row1, row2, col1, and col2 for every location that you want to inspect, but that's no problem. Then repeat the above code for every parking spot. You might make taken be an array.
You should check Vision Bibliography. There are published papers on this. I assume this is an undergraduate project so you might be able to get away with just copying known methods. If it's a graduate project, then you're going to have to invent something totally new to the world or else improve on the methods that have already been published.
Huang, C.C.[Ching-Chun], Wang, S.J.[Sheng-Jyh],
A Hierarchical Bayesian Generation Framework for Vacant Parking Space Detection,
CirSysVideo(20), No. 12, December 2010, pp. 1770-1785.
Suhr, J.K.[Jae Kyu], Jung, H.G.[Ho Gi],
Sensor Fusion-Based Vacant Parking Slot Detection and Tracking,
ITS(15), No. 1, February 2014, pp. 21-36.
Suhr, J.K.[Jae Kyu], Jung, H.G.[Ho Gi], Bae, K.[Kwanghyuk], Kim, J.[Jaihie],
Automatic free parking space detection by using motion stereo-based 3D reconstruction,
MVA(21), No. 2, February 2010, pp. xx-yy.
and so on.
37 件のコメント
Hazha
2014 年 4 月 20 日
Thanks a lot @Image Analyst for your answer. You are correct! This is an undergraduate project.
I am sorry, but I do not see the attachment!
Also, there is no need to compare two images with each other, correct? We are comparing the color of the cars with the color of the pavement?
Plus, how will my loop look like?
Thanks again.
Image Analyst
2014 年 4 月 20 日
Sorry. Here's the file. No you don't need to compare images themselves, just the color values extracted from small rectangles that are the parking spaces.
You would define the starting rows and columns for each space (arrays called rows and columns), and a width and height, say 20 and 30 pixels respectively. Then do
rgbImage = getsnapshot();
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
for ps = 1 : 10 % Loop over 10 spaces
row1 = rows(ps);
row2 = row1 + 30; % or whatever the height is.
col1 = columns(ps);
col2 = col1 + 20; % or whatever the width is.
% Get means in the rectangle of this parking place.
redMean = mean2(redChannel(row1:row2, col1:col2));
greenMean = mean2(greenChannel(row1:row2, col1:col2));
blueMean = mean2(blueChannel(row1:row2, col1:col2));
% Set a flag to say if it's taken or not.
taken = abs(redMean - redBlack) > tolerance & abs(greenMean- greenBlack) & tolerance & abs(blueMean - blueBlack) > tolerance;
end
Hazha
2014 年 4 月 20 日
編集済み: Image Analyst
2014 年 4 月 20 日
@Image Analyst
A couple of questions:
- I ran the above code and all I get is a lot of numbers and an error at the end(see attachment).
- I ran the code you attached, but is there a small program to tell the camera:if there is motion, take an image, tell me how many spots are available?
- In case there is a black colored car, how should we deal with that? since the color of my pavement is black also?
Please explain with code, if possible.
Thank you.
Image Analyst
2014 年 4 月 20 日
There is no attachment. What code did you run? Did you see how I subtracted one frame from the prior frames? Did you do the same thing in your code?
If it's a black car that will tell you how large the smallest tolerance needs to be. If you're getting a lot of false alarms (says a car is there when there's not), then you might have to either raise the tolerance or also check texture. The texture of the ground will be different. for example do an edge detection and measure that also. Smooth ground will not have many edges but a car will, even a black car.
Hazha
2014 年 4 月 21 日
Attached is what I have so far.
For the black car, can you please show me how to do that texture detection?
Hazha
2014 年 4 月 21 日
Did you look at my code? I still get only a lot of numbers after running the whole script which I have attached in my previous comment. How can I fix that?
Image Analyst
2014 年 4 月 21 日
No I didn't have time. And I need to leave again soon for an errand. I'll be gone a few hours. You could have saved some time by posting the error.
Hazha
2014 年 4 月 21 日
The error is attached.
I really need to finish this very soon that's why I needed you to look at it soon.
Thanks.
Image Analyst
2014 年 4 月 21 日
Hazha when people post code you need to think about what they post and see where it needs to be modified. Just because in my sample code I used the variable name of "rgbImage" does not mean that you also used that exact name. What did you call your image? Maybe you called it originalImage or something similar, or worst case some single letter like I or X or A or some bad choice like that. What did you use? Replace my "rgbImage" with whatever you used. That's what people do when people post sample code for them - they adapt it.
Hazha
2014 年 4 月 21 日
Okay, I changed that. Now I get other errors, please find attached both error and code.
I also fixed a lot other errors, but this one just seems to me a very annoying one!
Thanks.
Image Analyst
2014 年 4 月 21 日
You have weird characters in there that aren't apostrophes. I fixed them for you:
vid = videoinput('winvideo', 1, 'YUY2_320x240');
Hazha
2014 年 4 月 23 日
@Image Analyst,
Can you please check the whole code? I really need to complete this in a few days.
Thanks.
dhia jamaa
2015 年 5 月 18 日
Hello to all. i am working about the same idea. my problem is, for an image with a certain number of parking spots, how to locate each spot and to know their coordinates. any idea?? thanks in advance
Zain Rajani
2016 年 12 月 8 日
what is redBlack, greenBlack and blueBlack in the code mean? and what is it use for? please tell me
Thank you.
Image Analyst
2016 年 12 月 8 日
It tells you how much of a difference there is between the color of the black asphalt (or concrete) and what is in the picture (like a car), so you can tell if the parking space is empty or if there is a vehicle there.
Walter Roberson
2016 年 12 月 8 日
Image Analyst: the problem was that your code has
taken = abs(redMean - redBlack) > tolerance & abs(greenMean- greenBlack) > tolerance & abs(blueMean - blueBlack) > tolerance;
without defining redBlack, greenBlack, blueBlack .
Zain Rajani
2016 年 12 月 8 日
Yes please define what is RedBlack, greenblack and blueblack in your code. Please
Image Analyst
2016 年 12 月 8 日
I don't know what they are. You have to measure what they are for your blank (no car) image. Look in the parking space and measure the RGB value of the parking space with no car in there. That's what you should pick/use for the values. Perhaps it's 50,39,45 -- I don't know. Measure it with imtool in MATLAB, or with Photoshop or whatever, then use those values in your code.
Zain Rajani
2016 年 12 月 8 日
So you mean to say that I need to measure the red mean, blue mean and green mean for image with no cars and substitute this in place of redBlack and so on?
Image Analyst
2016 年 12 月 8 日
Yes. And if the values vary from one parking spot to the next, or from one time of day to the next, then you might need a whole array of color values so you can use the right color in the right place at the right time. It can get more complicated. For example, do you think the color changes with weather? Sure it does. Not only might it be brighter or darker, like if an overhead lamp turns on, but the color of the light may change, like from noon to sunset to overcast to cloudy, etc. Perhaps you need to also make another measurement that says how uniform the value is. Like if it's an empty parking spot the value over the spot may have a low standard deviation but if a car is there the St Dev might be higher because of windows, bumpers, door handles, etc.
Zain Rajani
2016 年 12 月 9 日
How to get the tolerance if I assume that weather conditions and light remains the same?
Image Analyst
2016 年 12 月 9 日
After examining the parking place ROI to find the mean and standard deviation of the colors, try some values and see if they work?
Zain Rajani
2016 年 12 月 9 日
Can you please tell me how to count the number of cars present in an image?
Image Analyst
2016 年 12 月 9 日
Inspect every parking space seeing if the image of it matches features for an empty one. If a particular parking spot is not empty, set some element of some array that represents that parking lot to "true". Then to count all the cars there, simply sum your parking lot array:
numberOfCarsParked = sum(parkingLotArray(:));
Cristian Cuenca Moreno
2022 年 2 月 26 日
Hello,
I'm doing a project just like yours and I can't get it to draw just one x or a circle in each parking space, but it draws several, do you know how I could fix this problem?
Image Analyst
2022 年 2 月 26 日
@Cristian Cuenca Moreno I think you must have modified the script. Attach the actual m-file you are using.
Cristian Cuenca Moreno
2022 年 3 月 3 日
¿Could the mask be calculated from the image of the empty parking lot?
Image Analyst
2022 年 3 月 3 日
Sure. I just took an image that had cars in it, but that doesn't matter, and painted over the spaces. The spaces were white and elsewhere was black. I then saved it as a gray scale mask image.
Cristian Cuenca Moreno
2022 年 3 月 6 日
Could you tell me some code or idea that allows me to make such a mask?
Image Analyst
2022 年 3 月 6 日
For example, if you don't have Photoshop you can use the open source GIMP or any other paint program.
Cristian Cuenca Moreno
2022 年 3 月 6 日
Sorry if I haven't explained it very well. I was referring to how to calculate it using matlab.
Walter Roberson
2022 年 3 月 6 日
"¿Could the mask be calculated from the image of the empty parking lot?"
NO.
At least not without using a large source of external information for Deep Learning to be able to figure out by calculation what the "meaning" of each pixel is. Is that narrow spot marked out with lines motorcycle parking? Is it there to prevent people from blocking a utility closet? Is it there because the water flow is designed to fall there? Is this spot double-width because it is a handicap spot allowing for vans with ramps and that is marked on the wall? Is this spot double-width because the markings have faded?
You cannot reliably calculate the mask without a lot of real-world knowledge. But as a human looking at a set of photographs, you can probably draw in the boundaries fairly well.
Image Analyst
2022 年 3 月 6 日
Just to build on what Walter said, I'm sure you'd spend way more time trying to develop an image processing program to identify spaces than if you just hand drew them. I mean, why spend days or weeks trying to develop a program to automatically identify spaces when you can hand draw them in a few minutes? If you have a parking lot image, just upload it and I can give you back the mask with just a few minutes work.
Cristian Cuenca Moreno
2022 年 3 月 7 日
Ok, thaks
My objective was to build a code trained to do it itself whit some lines but if its very tedious, its better to draw it
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)


