Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-045
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
2020-045
2020-045
Commits
c0b2843d
Commit
c0b2843d
authored
Jan 10, 2021
by
Pradeepika123
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1/10/2021
parent
78ff0b1c
Pipeline
#2062
failed with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
270 additions
and
13 deletions
+270
-13
Resting/Readings.csv
Resting/Readings.csv
+61
-0
RestingAPIProject/RestingApp/views.py
RestingAPIProject/RestingApp/views.py
+189
-12
VideoFrames.py
VideoFrames.py
+20
-1
No files found.
Resting/Readings.csv
0 → 100644
View file @
c0b2843d
frame_ID,prediction
frame0.jpg,1
frame1.jpg,1
frame2.jpg,1
frame3.jpg,1
frame4.jpg,1
frame5.jpg,1
frame6.jpg,1
frame7.jpg,1
frame8.jpg,1
frame9.jpg,1
frame10.jpg,1
frame11.jpg,1
frame12.jpg,1
frame13.jpg,1
frame14.jpg,1
frame15.jpg,1
frame16.jpg,1
frame17.jpg,1
frame18.jpg,1
frame19.jpg,1
frame20.jpg,1
frame21.jpg,1
frame22.jpg,1
frame23.jpg,1
frame24.jpg,1
frame25.jpg,1
frame26.jpg,1
frame27.jpg,1
frame28.jpg,1
frame29.jpg,1
frame30.jpg,1
frame31.jpg,1
frame32.jpg,1
frame33.jpg,1
frame34.jpg,1
frame35.jpg,1
frame36.jpg,1
frame37.jpg,1
frame38.jpg,1
frame39.jpg,1
frame40.jpg,1
frame41.jpg,1
frame42.jpg,1
frame43.jpg,1
frame44.jpg,1
frame45.jpg,1
frame46.jpg,1
frame47.jpg,1
frame48.jpg,1
frame49.jpg,1
frame50.jpg,1
frame51.jpg,1
frame52.jpg,1
frame53.jpg,1
frame54.jpg,1
frame55.jpg,1
frame56.jpg,1
frame57.jpg,1
frame58.jpg,1
frame59.jpg,1
RestingAPIProject/RestingApp/views.py
View file @
c0b2843d
import
json
import
json
import
os
from
datetime
import
timedelta
from
datetime
import
timedelta
import
lm
as
lm
import
model.imagegenerator
as
im
from
background_task
import
background
from
background_task
import
background
from
background_task.models
import
Task
from
background_task.models
import
Task
from
django.contrib.auth
import
authenticate
,
login
from
django.contrib.auth
import
authenticate
,
login
...
@@ -33,6 +36,9 @@ from sympy import fft
...
@@ -33,6 +36,9 @@ from sympy import fft
from
datetime
import
datetime
from
datetime
import
datetime
from
rest_framework.authtoken.models
import
Token
from
rest_framework.authtoken.models
import
Token
from
django_file_md5
import
calculate_md5
from
django_file_md5
import
calculate_md5
import
cv2
from
imutils.video
import
FileVideoStream
from
glob
import
glob
def
index
(
request
):
def
index
(
request
):
return
render
(
request
,
'user_example/index.html'
)
return
render
(
request
,
'user_example/index.html'
)
...
@@ -118,8 +124,6 @@ class CustomAuthToken(ObtainAuthToken):
...
@@ -118,8 +124,6 @@ class CustomAuthToken(ObtainAuthToken):
})
})
# DOGS
# DOGS
@
api_view
([
"POST"
])
@
api_view
([
"POST"
])
@
csrf_exempt
@
csrf_exempt
@
permission_classes
([
IsAuthenticated
])
@
permission_classes
([
IsAuthenticated
])
...
@@ -198,7 +202,6 @@ def delete_DogProfile(request):
...
@@ -198,7 +202,6 @@ def delete_DogProfile(request):
# POSITION
# POSITION
@
api_view
([
"POST"
])
@
api_view
([
"POST"
])
@
csrf_exempt
@
csrf_exempt
@
permission_classes
([
IsAuthenticated
])
@
permission_classes
([
IsAuthenticated
])
...
@@ -230,7 +233,6 @@ def getPositionNameById(request):
...
@@ -230,7 +233,6 @@ def getPositionNameById(request):
# RESTING ACTIVITY PER DAY
# RESTING ACTIVITY PER DAY
@
api_view
([
"GET"
])
@
api_view
([
"GET"
])
@
csrf_exempt
@
csrf_exempt
@
permission_classes
([
IsAuthenticated
])
@
permission_classes
([
IsAuthenticated
])
...
@@ -316,7 +318,6 @@ def delete_restingActivityPerDay(request, resting_id):
...
@@ -316,7 +318,6 @@ def delete_restingActivityPerDay(request, resting_id):
# DAILY
# DAILY
@
api_view
([
"POST"
])
@
api_view
([
"POST"
])
@
csrf_exempt
@
csrf_exempt
@
permission_classes
([
IsAuthenticated
])
@
permission_classes
([
IsAuthenticated
])
...
@@ -402,7 +403,6 @@ def highlightsPerDay(request):
...
@@ -402,7 +403,6 @@ def highlightsPerDay(request):
# WEEKLY
# WEEKLY
@
api_view
([
"POST"
])
@
api_view
([
"POST"
])
@
csrf_exempt
@
csrf_exempt
@
permission_classes
([
IsAuthenticated
])
@
permission_classes
([
IsAuthenticated
])
...
@@ -576,8 +576,6 @@ def highlightsPerMonth(request):
...
@@ -576,8 +576,6 @@ def highlightsPerMonth(request):
# ANNUALLY
# ANNUALLY
@
api_view
([
"POST"
])
@
api_view
([
"POST"
])
@
csrf_exempt
@
csrf_exempt
@
permission_classes
([
IsAuthenticated
])
@
permission_classes
([
IsAuthenticated
])
...
@@ -663,9 +661,188 @@ def highlightsPerYear(request):
...
@@ -663,9 +661,188 @@ def highlightsPerYear(request):
# load model
model
,
graph
=
lm
.
ModelInitializer
()
# class Main:
# def __init__(self):
#Video Processing and resting state prediction
@
csrf_exempt
\ No newline at end of file
def
restStatePrediction
():
cap
=
cv2
.
VideoCapture
(
'rtsp://admin:UEWOMQ@192.168.0.100:554/H.264'
)
results
=
[]
i
=
0
while
(
cap
.
isOpened
()):
ret
,
frame
=
cap
.
read
()
if
ret
==
False
:
break
cv2
.
imwrite
(
'kang'
+
str
(
i
)
+
'.jpg'
,
frame
)
i
+=
1
img_tensor
=
im
.
InputImageGeneratorVideo
(
frame
)
prediction
=
pd
.
Predict
(
img_tensor
,
model
,
graph
)
prediction
[
'frame'
]
=
frame
results
.
append
(
prediction
)
Data
.
append_list_as_row
(
Reading
.
csv
,
frame
,
results
)
cap
.
release
()
cv2
.
destroyAllWindows
()
def
append_list_as_row
(
file_name
,
list_of_elem
):
with
open
(
file_name
,
'a+'
,
newline
=
''
)
as
write_obj
:
# Create a writer object from csv module
csv_writer
=
writer
(
write_obj
)
csv_writer
.
writerow
(
list_of_elem
)
class
Data
:
data
=
''
Read
=
[]
def
__init__
(
self
,
data
):
self
.
data
=
data
def
ReadData
(
self
):
self
.
Read
=
pd
.
read_csv
(
self
.
data
)
return
self
.
Read
def
append_list_as_row
(
self
,
file_name
,
list_of_elem
):
# Open file in append mode
with
open
(
file_name
,
'a+'
,
newline
=
''
)
as
write_obj
:
# Create a writer object from csv module
csv_writer
=
writer
(
write_obj
)
# Add contents of list as last row in the csv file
csv_writer
.
writerow
(
list_of_elem
)
#sensor resting time and calculate mean resting time
def
getSensorRestTime
(
rest
):
activity
=
rest
sensorData
=
Walk
.
objects
.
filter
(
activity
=
activity
)
serializer
=
WalkSerializer
(
sensorData
,
many
=
True
)
for
i
in
range
(
len
(
serializer
.
data
)):
value
=
serializer
.
data
[
i
][
'positionPerDay'
]
return
value
@
api_view
([
"POST"
])
@
csrf_exempt
@
permission_classes
([
IsAuthenticated
])
def
calcMeanRestingTime
(
request
):
payload
=
json
.
loads
(
request
.
body
)
minutes
=
RestingActivity
.
objects
.
filter
(
position
=
payload
[
'position'
],
dog
=
payload
[
'dog'
],
date
=
payload
[
'date'
])
serializer
=
RestingActivitySerializer
(
minutes
,
many
=
True
)
if
len
(
serializer
.
data
)
>
0
:
dailyTotal
=
0
for
i
in
range
(
len
(
serializer
.
data
)):
dailyTotal
+=
1
return
JsonResponse
([{
'minutes per day'
:
dailyTotal
}],
safe
=
False
,
status
=
status
.
HTTP_200_OK
)
else
:
return
JsonResponse
([{
'minutes per day'
:
0
}],
safe
=
False
,
status
=
status
.
HTTP_200_OK
)
#resting activity level changes
def
compareBreedData
(
breed
,
restingMinutes
):
RestingMinutes
,
breedRestingMinutes
=
0
,
0
print
(
"Now comparing "
+
breed
)
activityStatusOfTheDog
=
''
breedRestingMinutes
=
getBreedActivityData
(
breed
)
if
RestingMinutes
>
breedRestingMinutes
:
print
(
"Activity level is high"
)
#Activity -> Resting
activityStatusOfTheDog
=
'high'
elif
RestingMinutes
<
breedRestingMinutes
:
print
(
"The actual activity level of the dog is : "
+
str
(
breedRestingMinutes
)
+
" minutes"
)
print
(
"But the current activity level of the dog is "
+
str
(
RestingMinutes
)
+
" minutes"
)
print
(
"Therefore .. Activity level is low"
)
activityStatusOfTheDog
=
'low'
elif
RestingMinutes
==
breedRestingMinutes
:
print
(
"Activity level is equal"
)
activityStatusOfTheDog
=
'equal'
# Add the status to the Dog Status Table
ConvertedDate
=
datetime
.
now
()
activityStatus
=
DogStatus
.
objects
.
create
(
user_id
=
1
,
dog_id
=
1
,
date
=
ConvertedDate
,
activity
=
1
,
status
=
activityStatusOfTheDog
,
)
DogStatusSerializer
(
activityStatus
)
def
getBreedActivityData
(
breed
):
name
=
breed
breedData
=
Breed
.
objects
.
filter
(
name
=
name
)
serializer
=
BreedSerializer
(
breedData
,
many
=
True
)
for
i
in
range
(
len
(
serializer
.
data
)):
value
=
serializer
.
data
[
i
][
'positionPerDay'
]
return
value
@
api_view
([
"POST"
])
def
compare
(
request
):
printHello
(
schedule
=
10
,
repeat
=
Task
.
DAILY
)
payload
=
json
.
loads
(
request
.
body
)
breed
=
payload
[
'breed'
]
ActivityMinutes
=
payload
[
'time'
]
RestingMinutes
,
breedRestingMinutes
=
0
,
0
activityStatusOfTheDog
=
''
print
(
breed
)
breedRestingMinutes
=
getBreedActivityData
(
breed
)
RestingMinutes
=
ActivityMinutes
halfValue
=
breedRestingMinutes
/
2
if
RestingMinutes
>
breedRestingMinutes
:
print
(
"The actual activity level of the dog is : "
+
str
(
breedRestingMinutes
)
+
" minutes"
)
print
(
"But the current activity level of the dog is "
+
str
(
RestingMinutes
)
+
" minutes"
)
print
(
"Activity level is high"
)
activityStatusOfTheDog
=
'high'
elif
RestingMinutes
<
halfValue
:
print
(
"The actual activity level of the dog is : "
+
str
(
breedRestingMinutes
)
+
" minutes"
)
print
(
"But the current activity level of the dog is "
+
str
(
RestingMinutes
)
+
" minutes"
)
print
(
"Therefore .. Activity level is low"
)
activityStatusOfTheDog
=
'low'
elif
(
RestingMinutes
<=
breedRestingMinutes
)
and
(
RestingMinutes
>=
halfValue
):
print
(
"The actual activity level of the dog is : "
+
str
(
breedRestingMinutes
)
+
" minutes"
)
print
(
"But the current activity level of the dog is "
+
str
(
RestingMinutes
)
+
" minutes"
)
print
(
"Activity level is equal"
)
activityStatusOfTheDog
=
'active'
return
JsonResponse
({
'status'
:
activityStatusOfTheDog
},
safe
=
False
,
status
=
status
.
HTTP_201_CREATED
)
class
Main
:
def
__init__
(
self
,
obj
):
d
=
Data
(
'Readings.csv'
)
data
=
d
.
ReadData
()
i
,
j
=
0
,
0
length
=
len
(
data
)
while
i
<=
length
:
Index
=
[]
count
=
i
+
30
if
j
<
length
:
while
j
<=
count
:
Index
.
append
(
j
)
j
=
j
+
1
#video prediction
videoD
=
restStatePrediction
()
#rest time from video
if
(
videoD
.
prediction
=
1
):
videoRestTime
=
getTotalMinutesPerDay
(
videoD
)
#rest time from sensor
sensorD
=
getSensorRestTime
(
0
)
#find mean rest time
meanRestTime
=
(
videoD
+
sensorD
)
/
2
#update db
calcMeanRestingTime
(
meanRestTime
)
#resting activity change
compare
(
meanRestTime
)
else
:
break
i
=
i
+
30
VideoFrames.py
View file @
c0b2843d
import
os
import
cv2
import
cv2
from
imutils.video
import
FileVideoStream
from
glob
import
glob
# Opens the video file
# Opens the video file
cap
=
cv2
.
VideoCapture
(
'F:/Videos/CUTE GSD PUPPY SLEEPING.mp4'
)
cap
=
cv2
.
VideoCapture
(
'F:/Videos/CUTE GSD PUPPY SLEEPING.mp4'
)
...
@@ -10,4 +13,20 @@ while(cap.isOpened()):
...
@@ -10,4 +13,20 @@ while(cap.isOpened()):
cv2
.
imwrite
(
'kang'
+
str
(
i
)
+
'.jpg'
,
frame
)
cv2
.
imwrite
(
'kang'
+
str
(
i
)
+
'.jpg'
,
frame
)
i
+=
1
i
+=
1
cap
.
release
()
cap
.
release
()
cv2
.
destroyAllWindows
()
cv2
.
destroyAllWindows
()
\ No newline at end of file
# video_dir = 'F:/Datasets/doggy_dataset/testvideos/'
# frame_dir = 'F:/GIT/28_12_2020/2020-045/Resting/ReadingFrames/'
#
# for entry in os.listdir(video_dir):
# if os.path.isfile(os.path.join(video_dir, entry)):
# cap = cv2.VideoCapture(entry)
# i = 0
# while (cap.isOpened()):
# ret, frame = cap.read()
# if ret == False:
# break
# cv2.imwrite(os.path.join(frame_dir, 'kang' + str(i) + '.jpg'), frame)
# i += 1
# cap.release()
# cv2.destroyAllWindows()
\ No newline at end of file
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