Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-ComputingNet
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
Operations
Operations
Metrics
Environments
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
OpenXG
OpenXG-ComputingNet
Commits
4d42d35f
Commit
4d42d35f
authored
Dec 31, 2022
by
Liantao Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
153bbbdf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
0 deletions
+119
-0
cam_single.py
cam_single.py
+119
-0
No files found.
cam_single.py
0 → 100644
View file @
4d42d35f
import
cv2
import
json
from
socket
import
*
from
tool.utils
import
load_class_names
,
plot_boxes_cv2
import
queue
,
_thread
,
threading
,
time
import
numpy
as
np
import
subprocess
def
send_from
(
arr
,
dest
):
view
=
memoryview
(
arr
).
cast
(
'B'
)
while
len
(
view
):
nsent
=
dest
.
send
(
view
)
view
=
view
[
nsent
:]
def
recv_into
(
arr
,
source
):
view
=
memoryview
(
arr
).
cast
(
'B'
)
while
len
(
view
):
nrecv
=
source
.
recv_into
(
view
)
view
=
view
[
nrecv
:]
namesfile
=
'data/coco.names'
class_names
=
load_class_names
(
namesfile
)
img_GPU
=
queue
.
Queue
(
10
)
lock_img_GPU
=
threading
.
Lock
()
def
cam_input
():
# cap = cv2.VideoCapture(0)
cap
=
cv2
.
VideoCapture
(
'rtmp://demo.wangdongdong.xyz/live/skd'
)
flag
=
cap
.
isOpened
()
# print("cap is opened: ", flag)
print
(
"任务生成成功,已成功获取视频流:"
,
flag
)
print
(
"开始单雾节点独立计算"
)
# print("cap flag: ", cap.isOpened())
time
.
sleep
(
1
)
while
True
:
_
,
img
=
cap
.
read
()
img
=
cv2
.
resize
(
img
,
(
640
,
480
))
cnt
=
0
if
img_GPU
.
full
():
cnt
+=
1
else
:
lock_img_GPU
.
acquire
()
img_GPU
.
put
(
img
)
lock_img_GPU
.
release
()
# if img_cor.full():
# cnt += 1
# else:
# lock_2.acquire()
# img_cor.put(img)
# lock_2.release()
cap
.
release
()
fps_GPU
=
0
fps_dis_GPU
=
0
def
fps_GPU_display
():
global
fps_GPU
,
fps_dis_GPU
while
1
:
time
.
sleep
(
10
)
fps_dis_GPU
=
fps_GPU
/
10
print
(
"single fps:"
,
fps_GPU
)
fps_GPU
=
0
def
cam_GPU
():
global
fps_GPU
,
fps_dis_GPU
s_GPU
=
socket
(
AF_INET
,
SOCK_STREAM
)
s_GPU
.
bind
((
''
,
26000
))
s_GPU
.
listen
(
1
)
c_GPU
,
a_GPU
=
s_GPU
.
accept
()
print
(
3
)
while
(
1
):
# get a frame
while
img_GPU
.
empty
():
time
.
sleep
(
0.1
)
lock_img_GPU
.
acquire
()
img
=
img_GPU
.
get
()
lock_img_GPU
.
release
()
# print(111)
send_from
(
img
,
c_GPU
)
# print(222)
lth
=
np
.
zeros
(
1
,
dtype
=
np
.
int64
)
recv_into
(
lth
,
c_GPU
)
if
not
lth
[
0
]
==
0
:
boxes
=
np
.
zeros
((
1
,
lth
[
0
],
7
),
dtype
=
np
.
float32
)
recv_into
(
boxes
,
c_GPU
)
boxes
=
boxes
.
tolist
()
for
i
in
range
(
lth
[
0
]):
boxes
[
0
][
i
][
-
1
]
=
np
.
int64
(
boxes
[
0
][
i
][
-
1
])
img
=
plot_boxes_cv2
(
img
,
boxes
[
0
],
'predictions.jpg'
,
class_names
)
fps_GPU
+=
1
img
=
cv2
.
putText
(
img
,
'FPS: {}'
.
format
(
fps_dis_GPU
),
(
100
,
100
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
2
,
(
0
,
0
,
0
),
2
)
cv2
.
imshow
(
'ONE(GPU):'
,
img
)
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
_thread
.
start_new_thread
(
cam_input
,
())
_thread
.
start_new_thread
(
fps_GPU_display
,
())
_thread
.
start_new_thread
(
cam_GPU
,
())
# _thread.start_new_thread(recv_box, ())
# _thread.start_new_thread(cam_send_cor, ())
while
1
:
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
cv2
.
destroyAllWindows
()
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