代码拉取完成,页面将自动刷新
from main_yolov3 import *
import requests
import time
import threading
# url = "http://192.168.0.100:8081"
# 打开网络摄像头
# cap = cv2.VideoCapture(url)
# cap = cv.VideoCapture("http://127.0.0.1:8080/?action=stream")
# cap = cv.VideoCapture("http://127.0.0.1:8080/?action=stream")
cap = cv.VideoCapture('xbd.mp4')
# 创建可以调节大小的窗口
# cv.namedWindow("video",0)
# cap = cv.VideoCapture(0)
# cap.set(cv.CAP_PROP_BUFFERSIZE, 3)
cap.set(cv.CAP_PROP_FPS, 60)
# cap.set(3, 320)
# cap.set(4, 320)
def get(url):
header = {'Content-Type':'application/json'}
response = requests.get(url,header)
return response.json()
RTip = True
def read_frame():
global frame, RTip, cap
while RTip:
_, frame = cap.read()
th1 = threading.Thread(target=read_frame, name='Thread_1')
th1.start()
time.sleep(3)
while(1):
global frame
net = cv.dnn.readNetFromDarknet(modelConfiguration, modelWeights)
net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
blob = cv.dnn.blobFromImage(frame, 1/255.0, (inpWidth, inpHeight), [0, 0, 0], swapRB=False, crop=False)
net.setInput(blob)
outs = net.forward(getOutputsNames(net))
postprocess(frame, outs)
t, _ = net.getPerfProfile()
label = 'Inference time: %.2f ms' % (t * 1000.0 / cv.getTickFrequency())
cv.putText(frame, label, (0, 15), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255))
cv.imshow("video",frame)
if (cv.waitKey(1) & 0xFF == ord('q') ):
break
cap.release()
cv.destroyAllWindows()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。