Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Smart E- Learn Tracer
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
23_22 - J 01
Smart E- Learn Tracer
Commits
f370bf69
Commit
f370bf69
authored
Jan 31, 2023
by
Shenthuri Vimaleshwaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
f99df194
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
mobile.py
mobile.py
+49
-0
No files found.
mobile.py
0 → 100644
View file @
f370bf69
import
cv2
# Load the pre-trained model
net
=
cv2
.
dnn
.
readNetFromCaffe
(
"mobilenet_iter_73000.caffemodel"
)
# Load the video
cap
=
cv2
.
VideoCapture
(
0
)
while
True
:
# Read the frame
_
,
frame
=
cap
.
read
()
# Get the dimensions of the frame
height
,
width
=
frame
.
shape
[:
2
]
# Create a blob from the frame
blob
=
cv2
.
dnn
.
blobFromImage
(
frame
,
0.007843
,
(
width
,
height
),
(
127.5
,
127.5
,
127.5
),
False
)
# Pass the blob through the model
net
.
setInput
(
blob
)
detections
=
net
.
forward
()
# Loop over the detections
for
i
in
range
(
detections
.
shape
[
2
]):
# Get the confidence of the detection
confidence
=
detections
[
0
,
0
,
i
,
2
]
# Filter out weak detections
if
confidence
>
0.5
:
# Get the class label of the detection
class_id
=
int
(
detections
[
0
,
0
,
i
,
1
])
# Check if the class label is a mobile phone
if
class_id
==
7
:
# Get the bounding box of the detection
x1
=
int
(
detections
[
0
,
0
,
i
,
3
]
*
width
)
y1
=
int
(
detections
[
0
,
0
,
i
,
4
]
*
height
)
x2
=
int
(
detections
[
0
,
0
,
i
,
5
]
*
width
)
y2
=
int
(
detections
[
0
,
0
,
i
,
6
]
*
height
)
# Draw a rectangle around the detection
cv2
.
rectangle
(
frame
,
(
x1
,
y1
),
(
x2
,
y2
),
(
0
,
0
,
255
),
2
)
# Show the frame
cv2
.
imshow
(
"Mobile Phone Detection"
,
frame
)
# Exit if the user presses 'q'
if
cv2
.
waitKey
(
1
)
==
ord
(
'q'
):
break
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