Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
face_detect
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiajunjie
face_detect
Commits
0a7abc2c
Commit
0a7abc2c
authored
Jan 22, 2021
by
jack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
15f161fe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
testcamera.py
examples/python/hatdet/testcamera.py
+61
-0
No files found.
examples/python/hatdet/testcamera.py
0 → 100644
View file @
0a7abc2c
#--utf8--
import
time
import
cv2
from
queue
import
Queue
from
threading
import
Thread
class
Camera
:
def
__init__
(
self
,
device_id
,
frame_queue
):
self
.
device_id
=
device_id
self
.
cam
=
cv2
.
VideoCapture
(
self
.
device_id
)
self
.
frame_queue
=
frame_queue
self
.
is_running
=
False
self
.
fps
=
0.0
self
.
_t_last
=
time
.
time
()
*
1000
self
.
_data
=
{}
def
capture_queue
(
self
):
self
.
_t_last
=
time
.
time
()
*
1000
while
self
.
is_running
and
self
.
cam
.
isOpened
():
ret
,
frame
=
self
.
cam
.
read
()
if
not
ret
:
break
if
self
.
frame_queue
.
qsize
()
<
1
:
t
=
time
.
time
()
*
1000
t_span
=
t
-
self
.
_t_last
self
.
fps
=
int
(
1000.0
/
t_span
)
self
.
_data
[
"image"
]
=
frame
.
copy
()
self
.
_data
[
"fps"
]
=
self
.
fps
self
.
frame_queue
.
put
(
self
.
_data
)
self
.
_t_last
=
t
def
run
(
self
):
self
.
is_running
=
True
self
.
thread_capture
=
Thread
(
target
=
self
.
capture_queue
)
self
.
thread_capture
.
start
()
def
stop
(
self
):
self
.
is_running
=
False
self
.
cam
.
release
()
def
show_frame
(
frame
):
while
True
:
data
=
frame
.
get
()
image
=
data
[
"image"
]
cv2
.
putText
(
image
,
"fps:{fps}"
.
format
(
fps
=
data
[
"fps"
]),
(
10
,
20
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
255
,
0
,
0
))
cv2
.
namedWindow
(
"camera"
,
cv2
.
WINDOW_AUTOSIZE
)
cv2
.
imshow
(
"camera"
,
image
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
frame_queue
.
task_done
()
if
__name__
==
"__main__"
:
frame_queue
=
Queue
()
cam
=
Camera
(
"rtsp://admin:admin12345@192.168.77.19:554/h264/ch1/main/av_stream"
,
frame_queue
)
cam
.
run
()
thread_show
=
Thread
(
target
=
show_frame
,
args
=
(
frame_queue
,))
thread_show
.
start
()
time
.
sleep
(
60
)
cam
.
stop
()
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