Skip to content

Commit 9f2e57f

Browse files
committed
First commit for parking project
0 parents  commit 9f2e57f

File tree

335 files changed

+97873
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

335 files changed

+97873
-0
lines changed

.gitignore

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
db.sqlite3
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/
105+
106+
# Additional ignore folders
107+
.idea/
108+
__pycache__/
109+
datasets/
110+
#trained_model/
111+
weights/

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Parking_DeepLearning
2+
3+
4+
![주석 2019-10-11 160755](https://user-images.githubusercontent.com/7313213/66631884-2be5fc00-ec42-11e9-9707-dd1102c7f2c4.jpg)
5+
6+
7+
8+
This project is implemented by referring following two references:
9+
10+
CNN for Parking lot:
11+
https://github.com/dalmia/WannaPark/tree/master/parking_lot_detection
12+
13+
Flask Streaming Web server:
14+
https://blog.miguelgrinberg.com/post/flask-video-streaming-revisited
15+
16+
Parking dataset:
17+
https://web.inf.ufpr.br/vri/databases/parking-lot-database/

custom.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import keras.backend as K
2+
from keras.engine.topology import Layer, InputSpec
3+
4+
class LocalResponseNormalization(Layer):
5+
6+
def __init__(self, n=5, alpha=0.0005, beta=0.75, k=2, **kwargs):
7+
self.n = n
8+
self.alpha = alpha
9+
self.beta = beta
10+
self.k = k
11+
super(LocalResponseNormalization, self).__init__(**kwargs)
12+
13+
def build(self, input_shape):
14+
self.shape = input_shape
15+
super(LocalResponseNormalization, self).build(input_shape)
16+
17+
def call(self, x, mask=None):
18+
if K.image_dim_ordering == "th":
19+
_, f, r, c = self.shape
20+
else:
21+
_, r, c, f = self.shape
22+
squared = K.square(x)
23+
pooled = K.pool2d(squared, (self.n, self.n), strides=(1, 1),
24+
padding="same", pool_mode="avg")
25+
if K.image_dim_ordering == "th":
26+
summed = K.sum(pooled, axis=1, keepdims=True)
27+
averaged = self.alpha * K.repeat_elements(summed, f, axis=1)
28+
else:
29+
summed = K.sum(pooled, axis=3, keepdims=True)
30+
averaged = self.alpha * K.repeat_elements(summed, f, axis=3)
31+
denom = K.pow(self.k + averaged, self.beta)
32+
return x / denom
33+
34+
def get_output_shape_for(self, input_shape):
35+
return input_shape
36+
37+
def compute_output_shape(self, input_shape):
38+
return input_shape

opencv/base_camera.py

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import time
2+
import threading
3+
try:
4+
from greenlet import getcurrent as get_ident
5+
except ImportError:
6+
try:
7+
from thread import get_ident
8+
except ImportError:
9+
from _thread import get_ident
10+
11+
12+
class CameraEvent(object):
13+
"""An Event-like class that signals all active clients when a new frame is
14+
available.
15+
"""
16+
def __init__(self):
17+
self.events = {}
18+
19+
def wait(self):
20+
"""Invoked from each client's thread to wait for the next frame."""
21+
ident = get_ident()
22+
if ident not in self.events:
23+
# this is a new client
24+
# add an entry for it in the self.events dict
25+
# each entry has two elements, a threading.Event() and a timestamp
26+
self.events[ident] = [threading.Event(), time.time()]
27+
return self.events[ident][0].wait()
28+
29+
def set(self):
30+
"""Invoked by the camera thread when a new frame is available."""
31+
now = time.time()
32+
remove = None
33+
for ident, event in self.events.items():
34+
if not event[0].isSet():
35+
# if this client's event is not set, then set it
36+
# also update the last set timestamp to now
37+
event[0].set()
38+
event[1] = now
39+
else:
40+
# if the client's event is already set, it means the client
41+
# did not process a previous frame
42+
# if the event stays set for more than 5 seconds, then assume
43+
# the client is gone and remove it
44+
if now - event[1] > 5:
45+
remove = ident
46+
if remove:
47+
del self.events[remove]
48+
49+
def clear(self):
50+
"""Invoked from each client's thread after a frame was processed."""
51+
self.events[get_ident()][0].clear()
52+
53+
54+
class BaseCamera(object):
55+
thread = None # background thread that reads frames from camera
56+
frame = None # current frame is stored here by background thread
57+
last_access = 0 # time of last client access to the camera
58+
event = CameraEvent()
59+
60+
def __init__(self):
61+
"""Start the background camera thread if it isn't running yet."""
62+
if BaseCamera.thread is None:
63+
BaseCamera.last_access = time.time()
64+
65+
# start background frame thread
66+
BaseCamera.thread = threading.Thread(target=self._thread)
67+
BaseCamera.thread.start()
68+
69+
# wait until frames are available
70+
while self.get_frame() is None:
71+
time.sleep(0)
72+
73+
def get_frame(self):
74+
"""Return the current camera frame."""
75+
BaseCamera.last_access = time.time()
76+
77+
# wait for a signal from the camera thread
78+
BaseCamera.event.wait()
79+
BaseCamera.event.clear()
80+
81+
return BaseCamera.frame
82+
83+
@staticmethod
84+
def frames():
85+
""""Generator that returns frames from the camera."""
86+
raise RuntimeError('Must be implemented by subclasses.')
87+
88+
@classmethod
89+
def _thread(cls):
90+
"""Camera background thread."""
91+
print('Starting camera thread.')
92+
frames_iterator = cls.frames()
93+
for frame in frames_iterator:
94+
BaseCamera.frame = frame
95+
BaseCamera.event.set() # send signal to clients
96+
time.sleep(0)
97+
98+
# if there hasn't been any clients asking for frames in
99+
# the last 10 seconds then stop the thread
100+
if time.time() - BaseCamera.last_access > 120:
101+
frames_iterator.close()
102+
print('Stopping camera thread due to inactivity.')
103+
break
104+
BaseCamera.thread = None

opencv/colors.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
COLOR_BLACK = (0, 0, 0)
2+
COLOR_BLUE = (255, 0, 0)
3+
COLOR_GREEN = (0, 255, 0)
4+
COLOR_RED = (0, 0, 255)
5+
COLOR_WHITE = (255, 255, 255)

parking_app.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
import os
3+
from importlib import import_module
4+
from flask import Flask, render_template, Response
5+
6+
# import camera driver
7+
if os.environ.get('CAMERA'):
8+
Camera = import_module('camera_' + os.environ['CAMERA']).Camera
9+
else:
10+
from parking_prediction import Camera
11+
12+
# Raspberry Pi camera module (requires picamera package)
13+
# from camera_pi import Camera
14+
15+
app = Flask(__name__)
16+
17+
@app.route('/')
18+
def index():
19+
"""Video streaming home page."""
20+
print("index page")
21+
return render_template('parking_cnn_page.html')
22+
23+
def gen(camera):
24+
"""Video streaming generator function."""
25+
print("Gen camera obj")
26+
while True:
27+
frame = camera.get_frame()
28+
yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
29+
30+
@app.route('/video_feed')
31+
def video_feed():
32+
print("video feed page")
33+
"""Video streaming route. Put this in the src attribute of an img tag."""
34+
return Response(gen(Camera()), mimetype='multipart/x-mixed-replace; boundary=frame')
35+
36+
if __name__ == '__main__':
37+
app.run(host='127.0.0.1', port=62597, threaded=True)

0 commit comments

Comments
 (0)