Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-027
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
1
Merge Requests
1
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-027
2022-027
Commits
80629389
Commit
80629389
authored
Nov 13, 2022
by
Jayasundara M.D.Y.L
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update ageidentification.py
parent
127d27e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
1 deletion
+52
-1
Age Level Identification/ageidentification.py
Age Level Identification/ageidentification.py
+52
-1
No files found.
Age Level Identification/ageidentification.py
View file @
80629389
hjk
\ No newline at end of file
import
cv2
def
faceBox
(
faceNet
,
frame
):
frameHight
=
frame
.
shape
[
0
]
frameWidth
=
frame
.
shape
[
1
]
blob
=
cv2
.
dnn
.
blobFromImage
(
frame
,
1.0
,
(
227
,
227
),
[
104
,
117
,
123
],
swapRB
=
False
)
faceNet
.
setInput
(
blob
)
detection
=
faceNet
.
forward
()
bboxs
=
[]
for
i
in
range
(
detection
.
shape
[
2
]):
confidence
=
detection
[
0
,
0
,
i
,
2
]
if
confidence
>
0.7
:
x1
=
int
(
detection
[
0
,
0
,
i
,
3
]
*
frameWidth
)
y1
=
int
(
detection
[
0
,
0
,
i
,
4
]
*
frameHight
)
x2
=
int
(
detection
[
0
,
0
,
i
,
5
]
*
frameWidth
)
y2
=
int
(
detection
[
0
,
0
,
i
,
6
]
*
frameHight
)
bboxs
.
append
([
x1
,
y1
,
x2
,
y2
])
cv2
.
rectangle
(
frame
,
(
x1
,
y1
),
(
x2
,
y2
),(
0
,
255
,
0
),
0
)
return
frame
,
bboxs
faceProto
=
"opencv_face_detector.pbtxt"
faceModel
=
"opencv_face_detector_uint8.pb"
ageProto
=
"age_deploy.prototxt"
ageModel
=
"age_net.caffemodel"
genderProto
=
"gender_deploy.prototxt"
genderModel
=
"gender_net.caffemodel"
faceNet
=
cv2
.
dnn
.
readNet
(
faceModel
,
faceProto
)
ageNet
=
cv2
.
dnn
.
readNet
(
ageModel
,
ageProto
)
genderNet
=
cv2
.
dnn
.
readNet
(
genderModel
,
genderProto
)
MODEL_MEAN_VALUES
=
(
78.4263377603
,
87.7689143744
,
114.895847746
)
ageList
=
[
'(0-2)'
,
'(4-6)'
,
'(8-12)'
,
'(15-20)'
,
'(25-32)'
,
'(38-43)'
,
'(48-53)'
,
'(60-100)'
]
genderList
=
[
'Male'
,
'Female'
]
video
=
cv2
.
VideoCapture
(
0
)
while
True
:
ret
,
frame
=
video
.
read
()
frame
,
bboxs
=
faceBox
(
faceNet
,
frame
)
for
bbox
in
bboxs
:
face
=
frame
[
bbox
[
1
]:
bbox
[
3
],
bbox
[
0
]:
bbox
[
2
]]
blob
=
cv2
.
dnn
.
blobFromImage
(
face
,
1.0
,
(
227
,
227
),
MODEL_MEAN_VALUES
,
swapRB
=
False
)
genderNet
.
setInput
(
blob
)
genderPred
=
genderNet
.
forward
()
gender
=
genderList
[
genderPred
[
0
]
.
argmax
()]
ageNet
.
setInput
(
blob
)
agePred
=
ageNet
.
forward
()
age
=
ageList
[
agePred
[
0
]
.
argmax
()]
lable
=
"{}, {}"
.
format
(
gender
,
age
)
cv2
.
putText
(
frame
,
lable
,(
bbox
[
0
],
bbox
[
1
]
-
10
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.8
,
(
255
,
255
,
255
),
2
)
cv2
.
imshow
(
"Age Detector"
,
frame
)
k
=
cv2
.
waitKey
(
1
)
if
k
==
ord
(
'q'
):
break
video
.
release
()
cv2
.
distroyAllWindows
()
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