im0 = annotator.result()
if view_img:
if platform.system() == "Linux" and p not in windows:
windows.append(p)
cv2.namedWindow(str(p), cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO) # allow window resize (Linux)
cv2.resizeWindow(str(p), im0.shape[1], im0.shape[0])
cv2.imshow(str(p), im0)
if cv2.waitKey(1) == ord("q"): # 1 millisecond
exit()
# Save results (image with detections)
if save_img:
if dataset.mode == "image":
cv2.imwrite(save_path, im0)
else: # 'video' or 'stream'
frame_count += 1 # Increment frame count
# Check if we need to start a new video
if frame_count % 300 == 0:
chunk_number += 1
if isinstance(vid_writer[i], cv2.VideoWriter):
vid_writer[i].release() # release previous video writer
save_path = str(Path(save_dir) / f"chunk_{chunk_number}.mp4")
fps, w, h = 30, im0.shape[1], im0.shape[0]
vid_writer[i] = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
if isinstance(vid_writer[i], cv2.VideoWriter):
vid_writer[i].write(im0)
if rtsp_writer is None:
rtsp_writer = cv2.VideoWriter(rtsp_url, cv2.VideoWriter_fourcc(*"H264"), 20,
(im0.shape[1], im0.shape[0]))
rtsp_writer.write(im0)
有人知道如何解决yolo检测输出的是一个不可读取的MP4文件 可以直接转成流