Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-235 Vehicle parking system
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
3
Merge Requests
3
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
2022-235
2022-235 Vehicle parking system
Commits
7ca78e9b
Commit
7ca78e9b
authored
Nov 10, 2022
by
Alahakoon K.M.R.A.B
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'IT18203004' into 'master'
IT18203004 to merge master branch See merge request
!12
parents
99bbafcd
e4821c01
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
125 additions
and
0 deletions
+125
-0
component_4/__pycache__/human_action_detector.cpython-38.pyc
component_4/__pycache__/human_action_detector.cpython-38.pyc
+0
-0
component_4/human_action_detector.py
component_4/human_action_detector.py
+125
-0
component_4/sample_data/test1.jpeg
component_4/sample_data/test1.jpeg
+0
-0
No files found.
component_4/__pycache__/human_action_detector.cpython-38.pyc
0 → 100644
View file @
7ca78e9b
File added
component_4/human_action_detector.py
0 → 100644
View file @
7ca78e9b
import
cv2
import
mediapipe
as
mp
import
numpy
as
np
import
os
import
random
mp_drawing
=
mp
.
solutions
.
drawing_utils
mp_pose
=
mp
.
solutions
.
pose
mp_drawing
=
mp
.
solutions
.
drawing_utils
mp_holistic
=
mp
.
solutions
.
holistic
mp_pose
=
mp
.
solutions
.
pose
mp_drawing
.
DrawingSpec
(
color
=
(
0
,
0
,
255
),
thickness
=
2
,
circle_radius
=
2
)
def
calculate_angle
(
a
,
b
,
c
):
a
=
np
.
array
(
a
)
# First
b
=
np
.
array
(
b
)
# Mid
c
=
np
.
array
(
c
)
# End
radians
=
np
.
arctan2
(
c
[
1
]
-
b
[
1
],
c
[
0
]
-
b
[
0
])
-
np
.
arctan2
(
a
[
1
]
-
b
[
1
],
a
[
0
]
-
b
[
0
])
angle
=
np
.
abs
(
radians
*
180.0
/
np
.
pi
)
if
angle
>
180.0
:
angle
=
360
-
angle
return
angle
def
get_human_thred
():
cap
=
cv2
.
VideoCapture
(
0
)
## Setup mediapipe instance
with
mp_pose
.
Pose
(
min_detection_confidence
=
0.5
,
min_tracking_confidence
=
0.5
)
as
pose
:
while
cap
.
isOpened
():
ret
,
frame
=
cap
.
read
()
# Recolor image to RGB
image
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
)
image
.
flags
.
writeable
=
False
# Make detection
results
=
pose
.
process
(
image
)
# Recolor back to BGR
image
.
flags
.
writeable
=
True
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_RGB2BGR
)
# Extract landmarks
try
:
landmarks
=
results
.
pose_landmarks
.
landmark
# Get coordinates
shoulder
=
[
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_SHOULDER
.
value
]
.
x
,
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_SHOULDER
.
value
]
.
y
]
elbow
=
[
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_ELBOW
.
value
]
.
x
,
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_ELBOW
.
value
]
.
y
]
wrist
=
[
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_WRIST
.
value
]
.
x
,
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_WRIST
.
value
]
.
y
]
# Calculate angle
angle
=
calculate_angle
(
shoulder
,
elbow
,
wrist
)
# Visualize angle
cv2
.
putText
(
image
,
str
(
angle
),
tuple
(
np
.
multiply
(
elbow
,
[
640
,
480
])
.
astype
(
int
)),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
255
,
255
,
255
),
2
,
cv2
.
LINE_AA
)
except
:
pass
# Render detections
mp_drawing
.
draw_landmarks
(
image
,
results
.
pose_landmarks
,
mp_pose
.
POSE_CONNECTIONS
,
mp_drawing
.
DrawingSpec
(
color
=
(
245
,
117
,
66
),
thickness
=
2
,
circle_radius
=
2
),
mp_drawing
.
DrawingSpec
(
color
=
(
245
,
66
,
230
),
thickness
=
2
,
circle_radius
=
2
)
)
cv2
.
imshow
(
'Mediapipe Feed'
,
image
)
if
cv2
.
waitKey
(
10
)
&
0xFF
==
ord
(
'q'
):
break
cap
.
release
()
cv2
.
destroyAllWindows
()
def
get_human_thred_temp
():
with
mp_pose
.
Pose
(
min_detection_confidence
=
0.5
,
min_tracking_confidence
=
0.5
)
as
pose
:
sample_imgs
=
os
.
listdir
(
'component_4/sample_data'
)
frame
=
cv2
.
imread
(
'component_4/sample_data/'
+
str
(
random
.
choice
(
sample_imgs
)))
# Recolor image to RGB
image
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
)
image
.
flags
.
writeable
=
False
# Make detection
results
=
pose
.
process
(
image
)
# Recolor back to BGR
image
.
flags
.
writeable
=
True
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_RGB2BGR
)
# Extract landmarks
try
:
landmarks
=
results
.
pose_landmarks
.
landmark
# Get coordinates
shoulder
=
[
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_SHOULDER
.
value
]
.
x
,
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_SHOULDER
.
value
]
.
y
]
elbow
=
[
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_ELBOW
.
value
]
.
x
,
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_ELBOW
.
value
]
.
y
]
wrist
=
[
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_WRIST
.
value
]
.
x
,
landmarks
[
mp_pose
.
PoseLandmark
.
LEFT_WRIST
.
value
]
.
y
]
# Calculate angle
angle
=
calculate_angle
(
shoulder
,
elbow
,
wrist
)
if
angle
>
60
:
return
True
else
:
return
False
except
:
return
False
component_4/sample_data/test1.jpeg
0 → 100644
View file @
7ca78e9b
12.2 KB
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