Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
23-064
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
23-064
23-064
Commits
424fe18a
Commit
424fe18a
authored
Oct 29, 2023
by
Yashmika Anusara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Actor Identification System Backend
parent
726750b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
211 additions
and
0 deletions
+211
-0
Actor Identification System/Actor Identification System.txt
Actor Identification System/Actor Identification System.txt
+0
-0
Actor Identification System/app.py
Actor Identification System/app.py
+211
-0
No files found.
Actor Identification System/Actor Identification System.txt
deleted
100644 → 0
View file @
726750b6
Actor Identification System/app.py
0 → 100644
View file @
424fe18a
from
flask
import
Flask
,
request
from
werkzeug.utils
import
secure_filename
import
cv2
from
flask_cors
import
CORS
from
ultralytics
import
YOLO
app
=
Flask
(
__name__
)
cors
=
CORS
(
app
)
@
app
.
route
(
"/movie-actor-identification"
,
methods
=
[
'POST'
])
def
actor_identification
():
if
request
.
method
==
'POST'
:
f
=
request
.
files
[
'movie'
]
f
.
save
(
"Film-Trailer/"
+
secure_filename
(
f
.
filename
))
# return 'file uploaded successfully'
# Starting moudle running
face_para
=
cv2
.
CascadeClassifier
(
'../Body_Parameters/haarcascade_frontalface_default.xml'
);
face_recognizer
=
cv2
.
face
.
LBPHFaceRecognizer_create
()
face_recognizer
.
read
(
'../Trained_file/face_trained.yml'
)
people
=
[
'Channa Perera'
,
'Danu Innasithamby'
,
'Dinakshie Priyasad'
,
'Eraj Gunewardena'
,
'Iresha Asanki De Silva'
,
'Mashi Siriwardene'
,
'Meena Kumari'
,
'Nadeeka Gunasekara'
,
'Sarah Illyas'
,
'Saranga Disasekara'
,
'Shereen Willis'
,
'Tanasha Satarasinghe'
,
'Yureni Noshika'
]
person
=
[]
Uploadfile
=
"Film-Trailer/"
+
f
.
filename
video_file
=
Uploadfile
.
strip
()
# print(video_file)
cap
=
cv2
.
VideoCapture
(
video_file
)
# cap for "Video Capture Object"
if
not
cap
.
isOpened
():
print
(
"Error opening Video File."
)
try
:
while
True
:
# Capture frame-by-frame
ret
,
frame
=
cap
.
read
()
gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
face
=
face_para
.
detectMultiScale
(
gray
,
1.2
,
8
)
for
(
x
,
y
,
w
,
h
)
in
face
:
face_roi
=
gray
[
y
:
y
+
h
,
x
:
x
+
w
]
label
,
confidence
=
face_recognizer
.
predict
(
face_roi
)
cv2
.
rectangle
(
frame
,
(
x
,
y
),
(
x
+
w
,
y
+
h
),
(
0
,
255
,
0
),
2
)
cv2
.
putText
(
frame
,
str
(
people
[
label
]),
(
x
,
y
-
10
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
1
,
(
0
,
255
,
0
),
2
,
cv2
.
LINE_AA
)
person
.
append
(
people
[
label
])
# print(people[label], confidence)
cv2
.
imshow
(
'frame'
,
frame
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
# if frame is read correctly, ret is True
if
not
ret
:
print
(
"Can't retrieve frame - stream may have ended. Exiting.."
)
break
except
:
print
(
"Film Trailer Analyze Complete"
)
# When everything done, release the capture
removeduplicperson
=
list
(
set
(
person
))
print
(
removeduplicperson
)
cap
.
release
()
cv2
.
destroyAllWindows
()
return
removeduplicperson
@
app
.
route
(
"/movie-film-marketing"
,
methods
=
[
'POST'
])
def
filmtype_identification
():
if
request
.
method
==
'POST'
:
f
=
request
.
files
[
'movie'
]
f
.
save
(
"Film-Trailer/"
+
secure_filename
(
f
.
filename
))
# return 'file uploaded successfully'
# Starting module running
face_para
=
cv2
.
CascadeClassifier
(
'../Body_Parameters/haarcascade_frontalface_default.xml'
);
face_recognizer
=
cv2
.
face
.
LBPHFaceRecognizer_create
()
face_recognizer
.
read
(
'../Trained_file/trainer.yml'
)
emotion
=
[
'anger'
,
'happy'
,
'neutral'
,
'sad'
]
x
=
1
filmtype
=
[]
romantic
=
0
action
=
0
comedy
=
0
Uploadfile
=
"Film-Trailer/"
+
f
.
filename
video_file
=
Uploadfile
.
strip
()
# print(video_file)
cap
=
cv2
.
VideoCapture
(
video_file
)
# cap for "Emotions Video Capture Object"
cap2
=
cv2
.
VideoCapture
(
video_file
)
# cap for "Pose Video Capture Object"
fps
=
cap2
.
get
(
cv2
.
CAP_PROP_FPS
)
n
=
0
if
not
cap
.
isOpened
():
print
(
"Error opening Video File."
)
try
:
if
x
==
1
:
print
(
"Film Trailer Emotions Analyze Started"
)
x
+=
1
while
True
:
# Capture frame-by-frame
ret
,
frame
=
cap
.
read
()
gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
face
=
face_para
.
detectMultiScale
(
gray
,
1.3
,
8
)
for
(
x
,
y
,
w
,
h
)
in
face
:
face_roi
=
gray
[
y
:
y
+
h
,
x
:
x
+
w
]
label
,
confidence
=
face_recognizer
.
predict
(
face_roi
)
cv2
.
rectangle
(
frame
,
(
x
,
y
),
(
x
+
w
,
y
+
h
),
(
0
,
255
,
0
),
2
)
cv2
.
putText
(
frame
,
str
(
emotion
[
label
]),
(
x
,
y
-
10
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
1
,
(
0
,
255
,
0
),
2
,
cv2
.
LINE_AA
)
if
(
emotion
[
label
]
==
"anger"
):
filmtype
.
append
(
"action"
)
elif
(
emotion
[
label
]
==
"happy"
):
filmtype
.
append
(
"romantic"
)
# filmtype.append("comedy")
elif
(
emotion
[
label
]
==
"sad"
):
filmtype
.
append
(
"romantic"
)
elif
(
emotion
[
label
]
==
"neutral"
):
filmtype
.
append
(
"romantic"
)
filmtype
.
append
(
"comedy"
)
# print(people[label], confidence)
cv2
.
imshow
(
'frame'
,
frame
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
# if frame is read correctly, ret is True
if
not
ret
:
print
(
"Can't retrieve frame - stream may have ended. Exiting.."
)
break
except
:
if
x
==
589
:
print
(
"Film Trailer Pose Analyze Started"
)
while
True
:
ret
,
frame2
=
cap2
.
read
()
if
(
7
*
n
)
%
fps
==
0
:
model
=
YOLO
(
'../Trained_file/best.pt'
)
# Run inference on image
results
=
model
.
predict
(
frame2
)
# results list
result
=
results
[
0
]
# print(len(result.boxes))
for
box
in
result
.
boxes
:
label
=
result
.
names
[
box
.
cls
[
0
]
.
item
()]
filmtype
.
append
(
label
)
n
+=
1
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
if
not
ret
:
# print("Can't retrieve frame - stream may have ended. Exiting..")
break
print
(
"Film Trailer Emotions & Pose Analyze Complete"
)
for
item
in
filmtype
:
if
item
==
"romantic"
:
romantic
+=
1
elif
item
==
"action"
:
action
+=
1
elif
item
==
"comedy"
:
comedy
+=
1
per_romantic
=
romantic
/
len
(
filmtype
)
*
100
per_action
=
action
/
len
(
filmtype
)
*
100
per_comedy
=
comedy
/
len
(
filmtype
)
*
100
romantic_rounded_number
=
format
(
per_romantic
,
".2f"
)
action_rounded_number
=
format
(
per_action
,
".2f"
)
comedy_rounded_number
=
format
(
per_comedy
,
".2f"
)
film_genre_values
=
{
"romantic"
:
romantic_rounded_number
,
"action"
:
action_rounded_number
,
"comedy"
:
comedy_rounded_number
}
sorted_genres
=
sorted
(
film_genre_values
.
items
(),
key
=
lambda
item
:
float
(
item
[
1
]),
reverse
=
True
)
highest_genre_1
=
sorted_genres
[
0
]
highest_genre_2
=
sorted_genres
[
1
]
print
(
highest_genre_1
,
highest_genre_2
)
result
=
{
"highest_genre_1"
:
{
"genre"
:
highest_genre_1
[
0
],
"value"
:
highest_genre_1
[
1
]
},
"highest_genre_2"
:
{
"genre"
:
highest_genre_2
[
0
],
"value"
:
highest_genre_2
[
1
]
}
}
# When everything done, release the capture
cap2
.
release
()
cv2
.
destroyAllWindows
()
return
result
if
__name__
==
'__main__'
:
app
.
run
(
debug
=
True
)
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