Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-101
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
Sachith Fernando
2020-101
Commits
ea733587
Commit
ea733587
authored
Jan 04, 2021
by
sachith.fernando
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start and save recording done
parent
2e2c21fd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
160 additions
and
9 deletions
+160
-9
AttendanceApp/api.py
AttendanceApp/api.py
+27
-0
AttendanceApp/templates/AttendanceApp/Initiate_Lecture.html
AttendanceApp/templates/AttendanceApp/Initiate_Lecture.html
+53
-1
AttendanceApp/test.py
AttendanceApp/test.py
+58
-0
AttendanceApp/urls.py
AttendanceApp/urls.py
+7
-2
AttendanceApp/views.py
AttendanceApp/views.py
+15
-6
No files found.
AttendanceApp/api.py
View file @
ea733587
...
...
@@ -10,6 +10,7 @@ from rest_framework.views import APIView
from
rest_framework.parsers
import
MultiPartParser
,
FormParser
from
.
import
record
from
.
import
test
as
t
from
rest_framework.views
import
*
...
...
@@ -171,3 +172,29 @@ class InitiateLecture(APIView):
return
Response
({
"response"
:
"success"
})
class
stopRecording
(
APIView
):
def
get
(
self
,
request
):
t
.
isStop
=
1
return
Response
({
"response"
:
"stopped"
})
def
post
(
self
,
request
):
pass
# test method (delete later)
class
TestAPI
(
APIView
):
def
get
(
self
,
request
):
t
.
isStop
=
0
param
=
request
.
query_params
.
get
(
'param'
)
# t.test()
t
.
IPWebcamTest
()
return
Response
({
"response"
:
"started"
})
def
post
(
self
,
request
):
pass
\ No newline at end of file
AttendanceApp/templates/AttendanceApp/Initiate_Lecture.html
View file @
ea733587
...
...
@@ -43,6 +43,50 @@ function toggleLectureLive() {
y
.
style
.
display
=
"
none
"
;
}
}
var
timer
=
false
;
//this is a test function
function
testAPI
()
{
timer
=
true
startTimer
()
let
param
=
'
sachith
'
;
//call the API
fetch
(
'
http://127.0.0.1:8000/attendance/test-api/?param=
'
+
param
)
.
then
((
res
)
=>
res
.
json
())
.
then
((
out
)
=>
{})
.
catch
((
err
)
=>
alert
(
'
error:
'
+
err
));
}
var
time
=
'
time
'
;
function
f
()
{
let
param
=
'
sachith
'
;
//call the API
fetch
(
'
http://127.0.0.1:8000/attendance/stop-api/?param=
'
+
param
)
.
then
((
res
)
=>
res
.
json
())
.
then
((
out
)
=>
{
timer
=
false
startTimer
();
})
.
catch
((
err
)
=>
alert
(
'
error:
'
+
err
));
}
function
startTimer
()
{
var
min
=
0
;
var
seconds
=
0
;
if
(
timer
)
{
var
sec
=
0
;
function
pad
(
val
)
{
return
val
>
9
?
val
:
"
0
"
+
val
;
}
setInterval
(
function
(){
min
=
pad
(
parseInt
(
sec
/
60
,
10
));
seconds
=
pad
(
++
sec
%
60
)
document
.
getElementById
(
"
seconds
"
).
innerHTML
=
pad
(
++
sec
%
60
);
document
.
getElementById
(
"
minutes
"
).
innerHTML
=
pad
(
parseInt
(
sec
/
60
,
10
));
},
1000
);
}
else
{
document
.
getElementById
(
"
secondsStop
"
).
innerHTML
=
seconds
;
document
.
getElementById
(
"
minutesStop
"
).
innerHTML
=
min
;
}
}
</script>
{% endblock %}
...
...
@@ -60,13 +104,21 @@ function toggleLectureLive() {
<div
class=
"card-body"
>
<button
type=
"button"
class=
"btn btn-success"
id=
"initiate_btn"
onclick=
"toggleLectureLive()"
>
Show Live Stream
</button>
{#
<button
type=
"button"
class=
"btn btn-success"
id=
"test_btn"
onclick=
"testAPI()"
>
Test
</button>
#}
</div>
<span
id=
"minutes"
></span>
:
<span
id=
"seconds"
></span>
<span
id=
"minutesStop"
></span>
:
<span
id=
"secondsStop"
></span>
<div
style=
"vertical-align: middle; border-style: none; background-color: #055270; height: 500px; width: 100%"
>
<div
class=
"row justify-content-center"
>
<img
id=
"liveStreamLecture"
style=
"display: none; height: inherit; margin-bottom: -25px;"
src=
"{% url 'webcam_feed' %}"
>
</div>
<div
class=
"row justify-content-center"
>
<button
style=
"display: none; width: 70px; height: 70px;"
id=
"liveStreamLectureStartButton"
class=
"btn btn-warning btn-circle"
><i
class=
"fas fa-video"
></i></button>
<div
class=
"col"
>
<button
style=
"display: none; width: 70px; height: 70px;"
id=
"liveStreamLectureStartButton"
class=
"btn btn-warning btn-circle"
onclick=
"testAPI()"
><i
class=
"fas fa-video"
></i></button>
</div>
<div
class=
"col"
>
<button
style=
"display: block; width: 70px; height: 70px;"
id=
"liveStreamLectureStartButton"
class=
"btn btn-warning btn-circle"
onclick=
"f()"
><i
class=
"fas fa-square"
></i></button>
</div>
</div>
</div>
</div>
...
...
AttendanceApp/test.py
0 → 100644
View file @
ea733587
import
urllib3
import
urllib.request
as
req
import
cv2
import
numpy
as
np
import
time
isStop
=
0
def
IPWebcamTest
():
# Replace the URL with your own IPwebcam shot.jpg IP:port
# url = 'http://192.168.2.35:8080/shot.jpg'
url
=
'http://192.168.8.103:8080/shot.jpg'
# url = 'http://192.168.1.11:8080/startvideo?force=1&tag=rec'
# url = 'http://192.168.1.11:8080/stopvideo?force=1'
size
=
(
600
,
600
)
vid_cod
=
cv2
.
VideoWriter_fourcc
(
*
'XVID'
)
# vid_cod = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
# output = cv2.VideoWriter("cam_video.avi", vid_cod, 20.0, (640, 480))
# output = cv2.VideoWriter("cam_video.mp4", vid_cod, 20.0, size)
output
=
cv2
.
VideoWriter
(
"cam_video.mp4"
,
vid_cod
,
10.0
,
size
)
no_of_frames
=
0
while
True
:
# Use urllib to get the image from the IP camera
imgResp
=
req
.
urlopen
(
url
)
# imgResp = urllib3.respon
# Numpy to convert into a array
imgNp
=
np
.
array
(
bytearray
(
imgResp
.
read
()),
dtype
=
np
.
uint8
)
# Finally decode the array to OpenCV usable format ;)
img
=
cv2
.
imdecode
(
imgNp
,
-
1
)
# resize the image
img
=
cv2
.
resize
(
img
,
(
600
,
600
))
# put the image on screen
# cv2.imshow('IPWebcam', img)
# write to the output writer
output
.
write
(
img
)
# To give the processor some less stress
# time.sleep(0.1)
# time.sleep(1)
no_of_frames
+=
1
if
isStop
==
1
:
break
# imgResp.release()
# cv2.destroyAllWindows()
print
(
'no of frames: '
,
no_of_frames
)
\ No newline at end of file
AttendanceApp/urls.py
View file @
ea733587
...
...
@@ -2,7 +2,7 @@ from django.urls import path
from
.api
import
student_list
,
student_detail
,
subject_list
,
subject_detail
,
attendance_list
,
StudentAPIView
,
\
StudentDetails
from
django.conf.urls
import
url
from
.api
import
FileView
,
InitiateLecture
from
.api
import
*
from
.
import
views
urlpatterns
=
[
...
...
@@ -19,5 +19,10 @@ urlpatterns = [
url
(
r'^upload/$'
,
FileView
.
as_view
(),
name
=
'file-upload'
),
path
(
'webcam_feed'
,
views
.
webcam_feed
,
name
=
'webcam_feed'
),
# this url will initiate the lecture
url
(
r'^process-initiate-lecture/$'
,
InitiateLecture
.
as_view
())
url
(
r'^process-initiate-lecture/$'
,
InitiateLecture
.
as_view
()),
# this url will be used for testing
url
(
r'^test-api/$'
,
TestAPI
.
as_view
()),
url
(
r'^stop-api/$'
,
stopRecording
.
as_view
())
]
AttendanceApp/views.py
View file @
ea733587
from
django.shortcuts
import
render
from
django.http.response
import
StreamingHttpResponse
from
AttendanceApp.camera
import
IPWebCam
from
FirstApp.MongoModels
import
LectureVideo
from
FirstApp.serializers
import
LectureVideoSerializer
def
initiate_lecture
(
request
):
lecture_video
=
LectureVideo
.
objects
.
all
()
lecture_video_ser
=
LectureVideoSerializer
(
lecture_video
,
many
=
True
)
print
(
'lecture video data: '
,
lecture_video_ser
.
data
)
return
render
(
request
,
"AttendanceApp/Initiate_lecture.html"
)
def
gen
(
camera
):
while
True
:
frame
=
camera
.
get_frame
()
yield
(
b
'--frame
\r\n
'
b
'Content-Type: image/jpeg
\r\n\r\n
'
+
frame
+
b
'
\r\n\r\n
'
)
def
webcam_feed
(
request
):
return
StreamingHttpResponse
(
gen
(
IPWebCam
()),
content_type
=
'multipart/x-mixed-replace; boundary=frame'
)
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