이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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 (한국어)


