YOLOv5读取摄像头实时检测目标并将裁剪后的部分保存

1.输入usb相机实时拍摄视频

1.在datasets.py文件中,按住Ctrl+F查找www.youtubo.com,把这个if语句模块注释掉;

2.在detect.py文件中,将默认参数default改为0,parser.add_argument( ‘–source’, type=str, default=‘0’, help=‘’)

3.此时的im0 = annotator.result()为裁剪后的图片。可以作为后续模型的输入使用。

2.保存裁剪图片

在detect.py文件中找到如下代码

if save_crop:
	save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{
      
      p.stem}.jpg', BGR=True)

改为如下代码:

if save_crop:
	crop_img = crop_one_box(xyxy, imc, BGR = True)
	save_one_box(xyxy, crop_img , file=save_dir / 'crops' / names[c] / f'{
      
      p.stem}.jpg', BGR=True)

猜你喜欢

转载自blog.csdn.net/weixin_41837701/article/details/127452514