Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
21_22-J 34
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 34
21_22-J 34
Commits
3804f714
Commit
3804f714
authored
May 01, 2022
by
Janage Tiran Harsha Jayawardana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload app
parent
f7a22960
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
0 deletions
+112
-0
staircase-count-api/app.py
staircase-count-api/app.py
+112
-0
No files found.
staircase-count-api/app.py
0 → 100644
View file @
3804f714
from
flask
import
Flask
,
request
,
jsonify
import
math
import
cv2
import
os
app
=
Flask
(
__name__
)
@
app
.
route
(
"/"
)
def
indexfun
():
return
"welcome"
@
app
.
route
(
"/predict"
,
methods
=
[
'POST'
])
def
getStepCount
():
file
=
request
.
files
[
'file'
]
image_path
=
"./images/"
+
file
.
filename
file
.
save
(
image_path
)
image
=
cv2
.
imread
(
image_path
)
gray_image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_RGB2GRAY
)
gaussian_image
=
cv2
.
GaussianBlur
(
gray_image
,(
9
,
9
),
0
,
0
)
canny_image
=
cv2
.
Canny
(
gaussian_image
,
80
,
240
,
3
)
# canny_image = cv2.Canny(gaussian_image,50,120)
output_image
=
cv2
.
cvtColor
(
canny_image
,
cv2
.
COLOR_GRAY2BGR
)
output_image2
=
cv2
.
cvtColor
(
canny_image
,
cv2
.
COLOR_GRAY2BGR
)
output_image3
=
cv2
.
cvtColor
(
canny_image
,
cv2
.
COLOR_GRAY2BGR
)
lines
=
list
()
lines
=
cv2
.
HoughLinesP
(
canny_image
,
1
,
math
.
pi
/
180
,
30
,
40
,
5
)
for
i
in
range
(
0
,
len
(
lines
)):
line
=
lines
[
i
][
0
]
cv2
.
line
(
output_image
,(
line
[
0
],
line
[
1
]),(
line
[
2
],
line
[
3
]),(
0
,
0
,
255
),
3
,
5
)
y_values
=
list
()
x_values
=
list
()
# print(lines)
# print("################")
# print(lines[0][0]) #[ 25 189 167 189]
# print(lines.shape)
# remove vertical lines
for
i
in
range
(
0
,
len
(
lines
)):
line
=
lines
[
i
][
0
]
#line -> [ 25 189 167 189]
#line -> y1-[1] -> 189
#line -> y2-[3] -> 189
if
(
abs
(
line
[
1
]
-
line
[
3
]))
<
5
:
y_values
.
append
([
line
[
1
],
line
[
3
]])
x_values
.
append
([
line
[
0
],
line
[
2
]])
#line -> x1-[0] -> 25
#line -> x2-[2] -> 167
if
(
abs
(
line
[
0
]
-
line
[
2
]))
>
100
:
y_values
.
append
([
line
[
1
],
line
[
3
]])
x_values
.
append
([
line
[
0
],
line
[
2
]])
# print(y_values)
# print("################")
# print(y_values[0]) #[189, 189]
for
i
in
range
(
0
,
len
(
y_values
)):
# y_ax -> [189, 189]
y_ax
=
y_values
[
i
]
x_ax
=
x_values
[
i
]
cv2
.
line
(
output_image2
,(
x_ax
[
0
],
y_ax
[
0
]),(
x_ax
[
1
],
y_ax
[
1
]),(
0
,
0
,
255
),
3
,
5
)
# remove unwanted horizontal lines
# print(y_values)
# print("################")
# print(y_values[0][0]) #189
# # y_ax -> 189
y_ax
=
list
()
y_ax
.
append
(
y_values
[
0
][
0
])
stair_count
=
0
flag
=
1
for
i
in
range
(
0
,
len
(
y_values
)):
line
=
y_values
[
i
]
#line -> [189, 189]
for
j
in
range
(
0
,
len
(
y_ax
)):
# y_ax -> 189
# This value will calculate with help of step height and width (15,40,60)
step_heigth_mean
=
15
if
(
abs
(
y_ax
[
j
]
-
line
[
1
])
<
step_heigth_mean
):
flag
=
0
if
flag
:
cv2
.
line
(
output_image3
,(
0
,
line
[
1
]),(
output_image3
.
shape
[
1
],
line
[
1
]),(
0
,
0
,
255
),
3
,
5
)
stair_count
=
stair_count
+
1
y_ax
.
append
(
line
[
1
])
flag
=
1
print
(
"Stair count :"
+
str
(
stair_count
))
os
.
remove
(
image_path
)
return
jsonify
({
"steps"
:
str
(
stair_count
)})
if
__name__
==
"__main__"
:
app
.
run
(
debug
=
True
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment