|
7#
楼主 |
发表于 2023-3-22 09:58:44
|
只看该作者
本帖最后由 sdp 于 2023-3-23 08:14 编辑
if __name__ == '__main__':
# Create RKNN object
host_name = get_host()
if host_name == 'RK3588':
rknn_model = RKNN_MODEL
else:
print("This demo cannot run on the current platform: {}".format(host_name))
exit(-1)
rknn = RKNNLite()
# load RKNN model
print('--> Load RKNN model')
ret = rknn.load_rknn(rknn_model)
if ret != 0:
print('Load RKNN model failed')
exit(ret)
print('done')
# init runtime environment
print('--> Init runtime environment')
# run on RK356x/RK3588 with Debian OS, do not need specify target.
if host_name == 'RK3588':
ret = rknn.init_runtime(core_mask=RKNNLite.NPU_CORE_0_1_2)
#ret = rknn.init_runtime()
print("use npu!")
else:
ret = rknn.init_runtime()
if ret != 0:
print('Init runtime environment failed')
exit(ret)
print('done')
videopath = 'data/video/' + 'test1' + '.mp4' #WORK_MODEL
#capture=cv2.VideoCapture(videopath) # test.mp4
#capture=cv2.VideoCapture(41)
#capture=cv2.VideoCapture('rtsp://admin:admin@192.168.1.64:554/h264/ch1/main/av_stream')
#rtspcap = toy.RtspCapture(url='rtsp://admin:admin@192.168.1.64:554/h264/ch1/main/av_stream', user='admin', password='admin', use_tcp=False)
rtspcap = toy.RtspCapture(url='rtsp://192.168.1.64:554/h264/ch1/main/av_stream', user='admin', password='admin', use_tcp=False)
#ISPcap = toy.CameraCapture(41, 1920, 1080)
font = cv2.FONT_HERSHEY_SIMPLEX
accum_time=0
curr_fps=0
prev_time=timer()
Obj="Objects:"
fps="FPS:"
flag=0
savepath = 'data/video/' + '111' + '.mp4' #WORK_MODEL
vid_writer = cv2.VideoWriter(savepath, cv2.VideoWriter_fourcc(*'mp4v'), 30, (IMG_SIZE, IMG_SIZE))
rtsps = toy.RtspWriter("/live", encoder=toy.FMT_H264, port=8554)
# rtsp://127.0.0.1:8554/live
try:
while(True):
#ret1, img=capture.read()
ret1, img = rtspcap.read(width=1920, height=1080, gformat=toy.FMT_RGB888)
#ret1, img = ISPcap.read(1920, 1080)
if ret1 == True:
flag+=1
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (IMG_SIZE, IMG_SIZE))
cv2.imshow("res", img)
cv2.waitKey(1)
else:
break
except KeyboardInterrupt:
cv2.destroyAllWindows()
rknn.release()
vid_writer.release()
|
|