部署环境
由于实验室只有无线网没有有线网,在这里依靠wifi路由器做出一个有线网。
wifi路由器根据wifi配置有线网
ip 192.168.113.17
掩码 255.255.255.0
网关192.168.113.254
DNS 8.8.8.8
在这里是网络已经可以联通。
此时摄像头默认的ip地址是192.168.1.64,我自己将其该为192.168.114.64,这里其实可以不改
修改本地网口ip使其在一个网段,但不要用64
此时上面为wifi路由器提供的网,下面为摄像头的网,如果把wifi路由器网关闭,处于断网状态,运行下方代码
运行代码
import cv2
import time
import numpy as np
user, pwd, ip, channel = "admin", "passward", "192.168.114.64", 1
video_stream_path = "rtsp://%s:%s@%s//Streaming/Channels/%d" % (user, pwd, ip, channel) # HIKIVISION new version 2017
video = cv2.VideoCapture(video_stream_path)
l_used_time = []
fps = 0
while True:
s = time.time()
ret, frame = video.read()
# print(ret)
# image = cv2.resize(frame, (416, 416))
# image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# cv2.imshow("results", image)
cv2.putText(frame, text='FPS: {}'.format(fps), org=(3, 15), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
fontScale=0.50, color=(255, 0, 0), thickness=2)
cv2.imshow("results", frame)
cv2.waitKey(5)
used_time = time.time() - s
l_used_time.append(used_time)
if len(l_used_time) > 10:
l_used_time.pop(0)
fps = int(1 / np.mean(l_used_time))
可以跑通,但网线连上后就不能正常运行,这是由于连上路由器后会从路由器搜寻局域网内的ip而不是本地的。
如果要想联网还可以运行,可以把网线接入wifi路由器,此时要修改摄像头ip地址与路由器一个网段。
import cv2
import time
import numpy as np
user, pwd, ip, channel = "admin", "passward", "192.168.113.64", 1
video_stream_path = "rtsp://%s:%s@%s//Streaming/Channels/%d" % (user, pwd, ip, channel) # HIKIVISION new version 2017
video = cv2.VideoCapture(video_stream_path)
l_used_time = []
fps = 0
while True:
s = time.time()
ret, frame = video.read()
# print(ret)
# image = cv2.resize(frame, (416, 416))
# image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# cv2.imshow("results", image)
cv2.putText(frame, text='FPS: {}'.format(fps), org=(3, 15), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
fontScale=0.50, color=(255, 0, 0), thickness=2)
cv2.imshow("results", frame)
cv2.waitKey(5)
used_time = time.time() - s
l_used_time.append(used_time)
if len(l_used_time) > 10:
l_used_time.pop(0)
fps = int(1 / np.mean(l_used_time))