Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 18
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
22_23-J 18
22_23-J 18
Commits
47db272d
Commit
47db272d
authored
Feb 02, 2023
by
Esala Senarathna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding detection models
parent
c145782c
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3412 additions
and
0 deletions
+3412
-0
IT19142838/Facial_parts_detection.ipynb
IT19142838/Facial_parts_detection.ipynb
+1557
-0
IT19142838/OneshotLearning.ipynb
IT19142838/OneshotLearning.ipynb
+1749
-0
IT19142838/realtime_detection2.py
IT19142838/realtime_detection2.py
+106
-0
No files found.
IT19142838/Facial_parts_detection.ipynb
0 → 100644
View file @
47db272d
This source diff could not be displayed because it is too large. You can
view the blob
instead.
IT19142838/OneshotLearning.ipynb
0 → 100644
View file @
47db272d
This diff is collapsed.
Click to expand it.
IT19142838/realtime_detection2.py
0 → 100644
View file @
47db272d
import
cv2
import
torch
from
tracker
import
*
import
numpy
as
np
from
shapely.geometry
import
Polygon
model
=
torch
.
hub
.
load
(
'ultralytics/yolov5'
,
'yolov5s'
,
pretrained
=
True
)
# model = torch.hub.load('.', 'custom', path='best.pt', source='local')
cap
=
cv2
.
VideoCapture
(
'sample_video.mp4'
)
# cap = cv2.VideoCapture(0)
def
POINTS
(
event
,
x
,
y
,
flags
,
param
):
if
event
==
cv2
.
EVENT_MOUSEMOVE
:
colorsBGR
=
[
x
,
y
]
print
(
colorsBGR
)
def
get_iou
(
box1
,
box2
):
y11
,
x11
,
y21
,
x21
=
box1
y12
,
x12
,
y22
,
x22
=
box2
yi1
=
max
(
y11
,
y12
)
xi1
=
max
(
x11
,
x12
)
yi2
=
min
(
y21
,
y22
)
xi2
=
min
(
x21
,
x22
)
inter_area
=
max
(((
xi2
-
xi1
)
*
(
yi2
-
yi1
)),
0
)
# Calculate the Union area by using Formula: Union(A,B) = A + B - Inter(A,B)
box1_area
=
(
x21
-
x11
)
*
(
y21
-
y11
)
box2_area
=
(
x22
-
x12
)
*
(
y22
-
y12
)
print
(
"box1_area: "
,
box1_area
)
union_area
=
box1_area
+
box2_area
-
inter_area
# compute the IoU
iou
=
inter_area
/
union_area
return
iou
cv2
.
namedWindow
(
'FRAME'
)
cv2
.
setMouseCallback
(
'FRAME'
,
POINTS
)
tracker
=
Tracker
()
countingRegion
=
[(
151
,
159
),(
933
,
173
),(
933
,
437
),
(
127
,
413
)]
objectCountSet
=
set
()
while
True
:
ret
,
frame
=
cap
.
read
()
frame
=
cv2
.
resize
(
frame
,(
1020
,
500
))
cv2
.
polylines
(
frame
,
[
np
.
array
(
countingRegion
,
np
.
int32
)],
True
,
(
0
,
255
,
0
),
2
)
# Make detections
results
=
model
(
frame
)
# a = results.pandas().xyxy[0]
# print(a)
# creating a tracker list
trackerList
=
[]
iterateCounter
,
overCrowdCounter
=
0
,
0
for
index
,
row
in
results
.
pandas
()
.
xyxy
[
0
]
.
iterrows
():
x1
=
int
(
row
[
'xmin'
])
y1
=
int
(
row
[
'ymin'
])
x2
=
int
(
row
[
'xmax'
])
y2
=
int
(
row
[
'ymax'
])
objectName
=
str
(
row
[
'name'
])
# print("trackerlist: ",trackerList)
# tracking overlapping bounding boxes
if
len
(
trackerList
)
==
0
:
trackerList
.
append
([
x1
,
y1
,
x2
,
y2
])
else
:
for
i
in
trackerList
:
value
=
get_iou
([
x1
,
y1
,
x2
,
y2
],
i
)
if
value
>
0.8
:
print
(
"the iou value: "
,
value
)
trackerList
.
remove
(
i
)
else
:
trackerList
.
append
([
x1
,
y1
,
x2
,
y2
])
# creating box id
boxIds
=
tracker
.
update
(
trackerList
)
# print("boxids: ",boxIds)
print
(
"Object name: "
,
objectName
)
print
(
"points: ["
,
x1
,
y1
,
x2
,
y2
,
"]"
)
for
id
in
boxIds
:
x
,
y
,
w
,
h
,
id
=
id
cv2
.
rectangle
(
frame
,
(
x
,
y
),
(
w
,
h
),
(
0
,
0
,
0
),
2
)
cv2
.
putText
(
frame
,
str
(
row
[
'name'
]),
(
x
,
y
),
cv2
.
FONT_HERSHEY_PLAIN
,
1
,
(
255
,
255
,
255
))
count
=
cv2
.
pointPolygonTest
(
np
.
array
(
countingRegion
,
np
.
int32
),
(
int
(
w
),
int
(
h
)),
False
)
if
count
>
0
:
objectCountSet
.
add
(
id
)
# print(len(objectCountSet))
cv2
.
putText
(
frame
,
str
(
objectCountSet
),
(
78
,
52
),
cv2
.
FONT_HERSHEY_PLAIN
,
2
,
(
255
,
0
,
0
))
if
len
(
objectCountSet
)
>
5
:
cv2
.
putText
(
frame
,
"Too many objects"
,
(
78
,
52
),
cv2
.
FONT_HERSHEY_PLAIN
,
2
,
(
255
,
0
,
0
))
print
(
"Too many objects"
)
overCrowdCounter
+=
1
if
overCrowdCounter
>
5
:
cv2
.
putText
(
frame
,
"Over Crowded too long"
,
(
78
,
90
),
cv2
.
FONT_HERSHEY_PLAIN
,
2
,
(
255
,
0
,
0
))
print
(
"Over Crowded too long"
)
objectCountSet
=
set
()
# cv2.rectangle(frame, (x1,y1), (x2,y2), (0,0,0),2)
# cv2.putText(frame, objectName, (x1,y1), cv2.FONT_HERSHEY_PLAIN,1, (255,255,255))
cv2
.
imshow
(
'FRAME'
,
frame
)
if
cv2
.
waitKey
(
10
)
&
0xFF
==
ord
(
'q'
):
break
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