Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-073
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
2022-073
2022-073
Commits
b8422f8c
Commit
b8422f8c
authored
Nov 12, 2022
by
Randika Monarawila
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into 'Randika-FInal-Changes'
# Conflicts: # web-app/backend/server.py
parents
b5dcaeaa
5133ac3c
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
17819 additions
and
124 deletions
+17819
-124
.gitignore
.gitignore
+1
-1
web-app/backend/controler.py
web-app/backend/controler.py
+4
-2
web-app/backend/requirements.txt
web-app/backend/requirements.txt
+0
-0
web-app/backend/server.py
web-app/backend/server.py
+25
-20
web-app/backend/test_vids/Testing_vid
web-app/backend/test_vids/Testing_vid
+0
-0
web-app/backend/trainAnn.py
web-app/backend/trainAnn.py
+39
-39
web-app/frontend/package-lock.json
web-app/frontend/package-lock.json
+17743
-54
web-app/frontend/src/pages/attention_demo/attentionspan.jsx
web-app/frontend/src/pages/attention_demo/attentionspan.jsx
+7
-5
web-app/package-lock.json
web-app/package-lock.json
+0
-3
No files found.
.gitignore
View file @
b8422f8c
...
...
@@ -6,7 +6,7 @@ node_modules
#pycache & face exp model
web-app/backend/__pycache__/
web-app/backend/facialExp.h5
web-app/backend/
test_vids/
web-app/backend/
uploads/att.mp4
/.pnp
.pnp.js
...
...
web-app/backend/controler.py
View file @
b8422f8c
import
cv2
as
cv
import
numpy
as
np
from
trainAnn
import
headPose
,
headDistence
,
facialExperssions
,
blinkCount
,
detector
import
os
from
keras.models
import
load_model
from
sklearn.preprocessing
import
OneHotEncoder
...
...
@@ -76,5 +76,7 @@ def captureImage(link,frameSkip):
if
__name__
==
"__main__"
:
scoreLst
=
captureImage
(
"C:/SLIIT/Final Research implementation/Backend/new model 2.0/Main Project code/uploads/test2.mp4"
,
10
)
directory
=
os
.
getcwd
()
destination
=
directory
+
r"\uploads\att.mp4"
scoreLst
=
captureImage
(
destination
,
10
)
print
(
scoreLst
)
web-app/backend/requirements.txt
View file @
b8422f8c
B
absl-py==1.2.0
...
...
web-app/backend/server.py
View file @
b8422f8c
...
...
@@ -21,45 +21,50 @@ from controler import captureImage
from
keras.models
import
load_model
from
sklearn.preprocessing
import
OneHotEncoder
from
datetime
import
datetime
# Attention classes
attClass
=
{
0
:
'Low Attention'
,
1
:
'Mid Attention'
,
2
:
'High Attention'
}
UPLOAD_FOLDER
=
'C:/SLIIT/Final Research implementation/Backend/new model 2.0/Main Project code/uploads'
ALLOWED_EXTENSIONS
=
set
(
[
'mkv'
,
'webm'
,
'mp4'
,
'txt'
,
'pdf'
,
'png'
,
'jpg'
,
'jpeg'
,
'gif'
])
x
=
datetime
.
datetime
.
now
()
# Initializing flask app
app
=
Flask
(
__name__
)
cors
=
CORS
(
app
)
app
.
config
[
'CORS_HEADERS'
]
=
'Content-Type'
app
.
config
[
'UPLOAD_FOLDER'
]
=
UPLOAD_FOLDER
# for prediction
@
app
.
route
(
'/upload'
,
methods
=
[
'POST'
])
@
app
.
route
(
'/attentionPrediction'
,
methods
=
[
'POST'
])
@
cross_origin
()
def
predictAttention
():
print
(
request
)
target
=
os
.
path
.
join
(
UPLOAD_FOLDER
,
'test_vids'
)
if
not
os
.
path
.
isdir
(
target
):
os
.
mkdir
(
target
)
directory
=
os
.
getcwd
()
dataJson
=
[]
file
=
request
.
files
[
'file'
]
testNo
=
request
.
form
.
get
(
'questionIndex'
)
filename
=
secure_filename
(
"Testing_vid"
)
destination
=
"/"
.
join
([
target
,
filename
])
file
.
save
(
destination
)
session
[
'uploadFilePath'
]
=
destination
filename
=
request
.
form
.
get
(
'filename'
)
if
file
is
None
or
filename
==
""
:
return
jsonify
({
'error: no file'
})
file
.
save
(
"./uploads/"
+
filename
)
destination
=
directory
+
r"\uploads\att.mp4"
scoreLst
=
captureImage
(
destination
,
10
)
dataDict
=
{
'low_attention'
:
scoreLst
[
0
],
'mid_attention'
:
scoreLst
[
1
],
'high_attention'
:
scoreLst
[
2
],
}
dataJson
.
append
(
dataDict
)
dt_string
=
datetime
.
now
()
.
strftime
(
"
%
d/
%
m/
%
Y
%
H:
%
M:
%
S"
)
db
.
db
[
'attentionlevelScore'
]
.
insert_one
({
"activityName"
:
"Manual_Attention_Test"
,
"questionIndex"
:
testNo
,
"attentionLevelScore"
:
scoreLst
,
})
print
(
"Prediction"
,
scoreLst
)
return
scoreLst
"activityName"
:
"Manual_Attention_Test"
,
"questionIndex"
:
testNo
,
"attentionLevelScore"
:
dataDict
,
"createdAt"
:
dt_string
,
})
print
(
"Prediction02"
,
scoreLst
)
print
(
"Prediction"
,
dataDict
)
return
jsonify
(
dataJson
)
@
app
.
route
(
'/parents/'
,
methods
=
[
'POST'
,
'GET'
])
...
...
web-app/backend/test_vids/Testing_vid
deleted
100644 → 0
View file @
b5dcaeaa
File deleted
web-app/backend/trainAnn.py
View file @
b8422f8c
...
...
@@ -70,7 +70,7 @@ def headDistence(frame3,detector):
# Finding distance
f
=
650
d
=
(
W
*
f
)
/
w
cvzone
.
putTextRect
(
frame3
,
f
'Depth: {int(d)}cm'
,(
facedis
[
10
][
0
]
-
100
,
facedis
[
10
][
1
]
-
50
),
scale
=
2
)
#
cvzone.putTextRect(frame3, f'Depth: {int(d)}cm',(facedis[10][0] - 100, facedis[10][1] - 50),scale=2)
return
frame3
,
str
(
d
),
True
return
frame3
,
False
,
False
...
...
@@ -87,8 +87,8 @@ def blinkCount(frame2,detector):
frame2
,
faces
=
detector
.
findFaceMesh
(
frame2
,
draw
=
False
)
if
faces
:
face
=
faces
[
0
]
for
id
in
idList
:
cv
.
circle
(
frame2
,
face
[
id
],
2
,
(
255
,
0
,
255
),
cv
.
FILLED
)
#
for id in idList:
#
cv.circle(frame2, face[id], 2, (255, 0, 255), cv.FILLED)
leftUp
=
face
[
159
]
leftDown
=
face
[
23
]
...
...
@@ -98,8 +98,8 @@ def blinkCount(frame2,detector):
lengthVerticl
,
_
=
detector
.
findDistance
(
leftUp
,
leftDown
)
lengthHorz
,
_
=
detector
.
findDistance
(
leftLEnd
,
leftREnd
)
cv
.
line
(
frame2
,
leftUp
,
leftDown
,
(
0
,
200
,
0
),
2
)
cv
.
line
(
frame2
,
leftLEnd
,
leftREnd
,
(
0
,
200
,
0
),
2
)
#
cv.line(frame2, leftUp, leftDown, (0, 200, 0), 2)
#
cv.line(frame2, leftLEnd, leftREnd, (0, 200, 0), 2)
ratio
=
int
((
lengthVerticl
/
lengthHorz
)
*
100
)
ratioList
.
append
(
ratio
)
...
...
@@ -119,8 +119,8 @@ def blinkCount(frame2,detector):
counter
=
0
# writer3.writerow([blinkCounter])
cvzone
.
putTextRect
(
frame2
,
f
'Blink Time: {blinkTime}'
,
(
20
,
50
),
1
,
2
,
(
255
,
255
,
255
),
(
255
,
0
,
0
),
cv
.
FONT_HERSHEY_SIMPLEX
)
imgPlot
=
plotY
.
update
(
ratioAvg
,
color
=
(
255
,
0
,
0
))
#
cvzone.putTextRect(frame2, f'Blink Time: {blinkTime}', (20, 50), 1, 2, (255, 255, 255), (255, 0, 0), cv.FONT_HERSHEY_SIMPLEX)
#
imgPlot = plotY.update(ratioAvg, color=(255, 0, 0))
return
frame2
,
blinkTime
...
...
@@ -143,9 +143,9 @@ def headPose(image,imgCount=0):
for
face_landmarks
in
results
.
multi_face_landmarks
:
for
idx
,
lm
in
enumerate
(
face_landmarks
.
landmark
):
if
idx
==
33
or
idx
==
263
or
idx
==
1
or
idx
==
61
or
idx
==
291
or
idx
==
199
:
if
idx
==
1
:
nose_2d
=
(
lm
.
x
*
img_w
,
lm
.
y
*
img_h
)
nose_3d
=
(
lm
.
x
*
img_w
,
lm
.
y
*
img_h
,
lm
.
z
*
3000
)
#
if idx == 1:
#
nose_2d = (lm.x * img_w, lm.y * img_h)
#
nose_3d = (lm.x * img_w, lm.y * img_h, lm.z * 3000)
x
,
y
=
int
(
lm
.
x
*
img_w
),
int
(
lm
.
y
*
img_h
)
...
...
@@ -185,44 +185,44 @@ def headPose(image,imgCount=0):
z
=
angles
[
2
]
*
360
# See where the user's head tilting
if
y
<
-
10
:
text
=
"Looking Left"
elif
y
>
10
:
text
=
"Looking Right"
elif
x
<
-
10
:
text
=
"Looking Down"
elif
x
>
10
:
text
=
"Looking Up"
else
:
text
=
"Forward"
#
if y < -10:
#
text = "Looking Left"
#
elif y > 10:
#
text = "Looking Right"
#
elif x < -10:
#
text = "Looking Down"
#
elif x > 10:
#
text = "Looking Up"
#
else:
#
text = "Forward"
# Display the nose direction
nose_3d_projection
,
jacobian
=
cv
.
projectPoints
(
nose_3d
,
rot_vec
,
trans_vec
,
cam_matrix
,
dist_matrix
)
#
nose_3d_projection, jacobian = cv.projectPoints(nose_3d, rot_vec, trans_vec, cam_matrix, dist_matrix)
p1
=
(
int
(
nose_2d
[
0
]),
int
(
nose_2d
[
1
]))
p2
=
(
int
(
nose_2d
[
0
]
+
y
*
10
),
int
(
nose_2d
[
1
]
-
x
*
10
))
#
p1 = (int(nose_2d[0]), int(nose_2d[1]))
#
p2 = (int(nose_2d[0] + y * 10), int(nose_2d[1] - x * 10))
cv
.
line
(
image
,
p1
,
p2
,
(
255
,
0
,
0
),
3
)
#
cv.line(image, p1, p2, (255, 0, 0), 3)
# Add the text on the image
# writer.writerow([str(np.round(x, 2)), str(np.round(y, 2)), str(np.round(z, 2)), text])
text
=
str
(
imgCount
+
1
)
+
" "
+
text
#
text=str(imgCount+1)+" "+text
cvzone
.
putTextRect
(
image
,
text
,
(
20
,
50
),
1
,
2
,
(
255
,
255
,
255
),
(
255
,
0
,
0
),
cv
.
FONT_HERSHEY_SIMPLEX
)
cv
.
putText
(
image
,
"x: "
+
str
(
np
.
round
(
x
,
2
)),
(
500
,
50
),
cv
.
FONT_HERSHEY_SIMPLEX
,
1
,
(
0
,
0
,
255
),
2
)
cv
.
putText
(
image
,
"y: "
+
str
(
np
.
round
(
y
,
2
)),
(
500
,
100
),
cv
.
FONT_HERSHEY_SIMPLEX
,
1
,
(
0
,
0
,
255
),
2
)
cv
.
putText
(
image
,
"z: "
+
str
(
np
.
round
(
z
,
2
)),
(
500
,
150
),
cv
.
FONT_HERSHEY_SIMPLEX
,
1
,
(
0
,
0
,
255
),
2
)
#
cvzone.putTextRect(image, text, (20, 50), 1, 2, (255, 255, 255),
#
(255, 0, 0), cv.FONT_HERSHEY_SIMPLEX)
#
cv.putText(image, "x: " + str(np.round(x, 2)), (500, 50), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
#
cv.putText(image, "y: " + str(np.round(y, 2)), (500, 100), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
#
cv.putText(image, "z: " + str(np.round(z, 2)), (500, 150), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
end
=
time
.
time
()
totalTime
=
end
-
start
#
totalTime = end - start
try
:
fps
=
1
/
totalTime
except
:
fps
=
0
#
try:
#
fps = 1 / totalTime
#
except:
#
fps =0
# print("FPS: ", fps)
cv
.
putText
(
image
,
f
'FPS: {int(fps)}'
,
(
20
,
450
),
cv
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
255
,
0
,
0
),
2
)
#
cv.putText(image, f'FPS: {int(fps)}', (20, 450), cv.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)
mp_drawing
.
draw_landmarks
(
image
=
image
,
...
...
@@ -255,10 +255,10 @@ def facialExperssions(image):
img_arr
=
np
.
asarray
(
image2
)
.
reshape
((
224
,
224
,
3
))
pre
=
model
.
predict
(
np
.
array
([
img_arr
]))
predictions
=
np
.
argmax
(
pre
,
axis
=
1
)
#
predictions =np.argmax(pre,axis=1)
# print(expressions[predictions[0]])
cv
.
putText
(
image
,
expressions
[
predictions
[
0
]],
(
x
-
padding
,
y
-
padding
-
20
),
cv
.
FONT_HERSHEY_SIMPLEX
,
1.5
,
(
0
,
255
,
255
),
2
,
cv
.
LINE_4
,)
cv
.
rectangle
(
image
,
(
x
-
padding
,
y
-
padding
),
(
x
+
w
+
padding
,
y
+
h
+
padding
),
(
255
,
255
,
255
),
thickness
=
2
)
#
cv.putText(image,expressions[predictions[0]], (x-padding, y-padding-20), cv.FONT_HERSHEY_SIMPLEX, 1.5, (0, 255, 255), 2,cv.LINE_4,)
#
cv.rectangle(image, (x-padding, y-padding), (x + w+padding, y + h+padding), (255, 255, 255), thickness = 2)
# cv.imshow("image",image)
return
image
,
pre
,
True
except
:
...
...
web-app/frontend/package-lock.json
View file @
b8422f8c
This diff is collapsed.
Click to expand it.
web-app/frontend/src/pages/attention_demo/attentionspan.jsx
View file @
b8422f8c
...
...
@@ -70,14 +70,16 @@ const AttentionSpan_screen = () => {
console
.
log
(
"
testing
"
,
blob
);
const
data
=
new
FormData
();
data
.
append
(
"
file
"
,
blob
);
data
.
append
(
"
filename
"
,
"
att.mp4
"
)
data
.
append
(
"
questionIndex
"
,
id
);
await
API
.
post
(
"
upload
"
,
data
,
{
await
API
.
post
(
"
attentionPrediction
"
,
data
,
{
headers
:
{
"
Access-Control-Allow-Origin
"
:
"
*
"
,
},
})
.
then
((
res
)
=>
{
setattention
(
res
.
data
);
console
.
log
(
res
.
data
[
0
])
setattention
(
res
.
data
[
0
]);
setisClicked
(
true
);
})
.
catch
((
err
)
=>
{
...
...
@@ -221,15 +223,15 @@ const AttentionSpan_screen = () => {
<>
<
p
>
Low level attention :
{
"
"
}
{
attention
[
0
]
*
100
}
{
Math
.
round
(
attention
.
low_attention
*
100
)
}
%
</
p
>
<
p
>
Mid level attention :
{
"
"
}
{
attention
[
1
]
*
100
}
{
Math
.
round
(
attention
.
mid_attention
*
100
)
}
%
</
p
>
<
p
>
High level attention :
{
"
"
}
{
attention
[
2
]
*
100
}
{
Math
.
round
(
attention
.
high_attention
*
100
)
}
%
</
p
>
</>
)
}
...
...
web-app/package-lock.json
deleted
100644 → 0
View file @
b5dcaeaa
{
"lockfileVersion"
:
1
}
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