Commit 4d42d35f authored by Liantao Wu's avatar Liantao Wu

Upload New File

parent 153bbbdf
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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment