yolo detect 无法保存图片

yolo detect不保存图片

我的问题是,我的目录中带中文,所以这个很好理解,根源就是在opencv上
所以解决办法:
找到save_img变量,只要带save_img的地方都去看一下

第一个地方:

                    if save_img or save_crop or view_img:  # Add bbox to image
                        c = int(cls)  # integer class
                        label = None if hide_labels else (names[c] if hide_conf else f'{names[c]} {conf:.2f}')
                        annotator.box_label(xyxy, label, color=colors(c, True))
                        if save_crop:
                            save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)

这里的save_one_box是保存目标截图的,在general.py中,原代码是

cv2.imwrite(str(increment_path(file, mkdir=True).with_suffix('.jpg')), crop)

替换成

cv2.imencode('.jpg',crop)[1].tofile(str(increment_path(file, mkdir=True).with_suffix('.jpg')))

第二个地方

这个在230行

cv2.imwrite(save_path, im0)

修改成:

cv2.imencode('.jpg', im0)[1].tofile(save_path)

此时应该就没有问题了,就能正常保存所有路径情况下了

你可能感兴趣的:(python,yolo,python,开发语言)