赞
踩
#识别图片 model = YOLO('yolov8n-seg'); results = model("your_image_path") #关键在于将Masks 转换为 ndarray mask_raw = results[0].masks[0].cpu().data.numpy().transpose(1,2,0) cv2.imshow("result",mask_raw); #=======================分割线========================================= #识别视频流 sourse = "./list.streams" #list.streams文件,用来存放流媒体地址,如rstp://localhost/test results = model(sourse,stream=True) for result in results: if result.mask is not None: mask_raw = result.masks[0].cpu().data.numpy().transpose(1,2,0) for mask in result.masks: mask_raw += mask.cpu().data.numpy().transpose(1,2,0) cv2.imshow("result",mask_raw)
效果如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。