Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Autonomous_Vehicles_with_embedded_intelligence
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kpp55
Autonomous_Vehicles_with_embedded_intelligence
Commits
e19345b0
Commit
e19345b0
authored
6 years ago
by
kpp55
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
05cd5c23
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
fps_demo.py
+78
-0
78 additions, 0 deletions
fps_demo.py
with
78 additions
and
0 deletions
fps_demo.py
0 → 100644
+
78
−
0
View file @
e19345b0
# USAGE
# python fps_demo.py
# python fps_demo.py --display 1
# import the necessary packages
from
__future__
import
print_function
from
imutils.video
import
WebcamVideoStream
from
imutils.video
import
FPS
import
argparse
import
imutils
import
cv2
# construct the argument parse and parse the arguments
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
"
-n
"
,
"
--num-frames
"
,
type
=
int
,
default
=
100
,
help
=
"
# of frames to loop over for FPS test
"
)
ap
.
add_argument
(
"
-d
"
,
"
--display
"
,
type
=
int
,
default
=-
1
,
help
=
"
Whether or not frames should be displayed
"
)
args
=
vars
(
ap
.
parse_args
())
# grab a pointer to the video stream and initialize the FPS counter
print
(
"
[INFO] sampling frames from webcam...
"
)
stream
=
cv2
.
VideoCapture
(
0
)
fps
=
FPS
().
start
()
# loop over some frames
while
fps
.
_numFrames
<
args
[
"
num_frames
"
]:
# grab the frame from the stream and resize it to have a maximum
# width of 400 pixels
(
grabbed
,
frame
)
=
stream
.
read
()
frame
=
imutils
.
resize
(
frame
,
width
=
400
)
# check to see if the frame should be displayed to our screen
if
args
[
"
display
"
]
>
0
:
cv2
.
imshow
(
"
Frame
"
,
frame
)
key
=
cv2
.
waitKey
(
1
)
&
0xFF
# update the FPS counter
fps
.
update
()
# stop the timer and display FPS information
fps
.
stop
()
print
(
"
[INFO] elasped time: {:.2f}
"
.
format
(
fps
.
elapsed
()))
print
(
"
[INFO] approx. FPS: {:.2f}
"
.
format
(
fps
.
fps
()))
# do a bit of cleanup
stream
.
release
()
cv2
.
destroyAllWindows
()
# created a *threaded *video stream, allow the camera senor to warmup,
# and start the FPS counter
print
(
"
[INFO] sampling THREADED frames from webcam...
"
)
vs
=
WebcamVideoStream
(
src
=
0
).
start
()
fps
=
FPS
().
start
()
# loop over some frames...this time using the threaded stream
while
fps
.
_numFrames
<
args
[
"
num_frames
"
]:
# grab the frame from the threaded video stream and resize it
# to have a maximum width of 400 pixels
frame
=
vs
.
read
()
frame
=
imutils
.
resize
(
frame
,
width
=
400
)
# check to see if the frame should be displayed to our screen
if
args
[
"
display
"
]
>
0
:
cv2
.
imshow
(
"
Frame
"
,
frame
)
key
=
cv2
.
waitKey
(
1
)
&
0xFF
# update the FPS counter
fps
.
update
()
# stop the timer and display FPS information
fps
.
stop
()
print
(
"
[INFO] elasped time: {:.2f}
"
.
format
(
fps
.
elapsed
()))
print
(
"
[INFO] approx. FPS: {:.2f}
"
.
format
(
fps
.
fps
()))
# do a bit of cleanup
cv2
.
destroyAllWindows
()
vs
.
stop
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment