Please note that this repository is forked from Priya Dwivedi's project on GitHub. You can find the her article here and her base source code here.
-
webcam_test/- Sample image to run and test the code on -
train_data/- Training data for CNN model. Sample data included -
for_cnn/- Directory to keep generated images for CNN. You have to manually label these images by separating them into sub-folders insidetrain_data/as structure below. Please note thatfor_cnn/is just only a directory to keep temporary images. It plays no role in main process.
.
├── for_cnn
└── train_data
├──train
| ├──empty
| └──occupied
└── test
├──empty
└──occupied
For the best training result, you should separate them with the ratio 8:2 for train:test
-
templates- Sample template to test API provided byFlask -
camera.py- Python class for getting frames from your webcam
Change
self.video = cv2.VideoCapture(1)
to
self.video = cv2.VideoCapture(0)
or
self.video = cv2.VideoCapture('your_video.avi') # for static video
if you don't have an external webcam
-
CNN_model_for_occupancy.py- Python script for starting your model training process. In the first time you run the script, it may take a long time for downloading the model. Please note that I am using Priya Dwivedi's model and it works well on my data. -
opencv_identifier.py- Python script for parking spot detection -
main.py- Python script using Flask to provide API -
config.json- Config file for dynamic data -
read_data.py- Python script to read data fromconfig.json. This script is imported in other Python files. You do not need to run this script. -
webcam_utils.py- Python utils script that help you capturing video from webcams and save images for CNN model, etc. User's manual is written below. -
image_utils- Python utils script that implementsOpenCVframework's algorithms.
Run
python webcam_utils.py --mode
Where --mode:
-
capture- Start a video capturing instance. Pressqto stop. Presscto toggle capturing mode. Video captured is save asoutpy.avi -
show-video- Show the video you captured asoutpy.avi -
save-a-frame- Readoutpy.aviand save a random frame aswebcam_test/test_frame.jpg -
save-frames- Readoutpy.aviand save many random frames intowebcam_test/ -
get-training-data- Read all images inwebcam_test/and generate slot images intofor_cnn/
- Original image
- Selecting region of interested (ROI)
- Perspective transformation
- Image Resization
- Image Bluration
- Finding edges
- Finding lines
- Clustering blocks
- Seperating parking slots
- Predicting occupation
-
You would need Python 2.7 or 3.6 here
-
Please follow this instruction to install
tensorflowortensorflow-gpu, depends on your hardware. -
Install
opencv2
pip install opencv
or
conda install opencv
- Install
flaskversion0.12.2. Please note that higherflaskversions could bring unexpected result.
pip install flask=0.12.2
or
conda install flask=0.12.2
-
Prepare training data with
webcam_utils.py. Your prepared data will be infor_cnn/. However, please note that training data should be available intrain_data/with structure above. I have prepared some sample data for you intrain_data/. Therefore, you may skip this step. -
Run
CNN_model_for_occupancy.pyto start training model. Make sure you find filecar1.h5after training process. -
Run
main.pyto start server. Your API should be available at http://0.0.0.0:8081/









