67 lines
1.9 KiB
Markdown
67 lines
1.9 KiB
Markdown
## 下载环境
|
||
|
||
```bash
|
||
pip install ultralytics
|
||
pip install opencv-python pycocotools matplotlib onnxruntime onnx torch torchvision
|
||
```
|
||
|
||
## 权重文件
|
||
|
||
* https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth SAM的权重文件,放入 `segment-anything-main`目录下
|
||
* https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x.pt yolo11的权重文件,放入`ultralytics-main`目录下
|
||
|
||
## 运行流程
|
||
|
||
### 1. 用yolo11跑出汽车框作为prompt
|
||
|
||
将汽车图片放入 `ultralytics-main/input下`
|
||
|
||
```
|
||
input/
|
||
├── 00060.jpg
|
||
├── 00213.jpg
|
||
├── ...
|
||
├── 00600.jpg
|
||
```
|
||
|
||
运行 `python3 test.py`
|
||
|
||
生成`output/exp` 保存框出来的汽车和 `output/car_boxes.txt` 保存每个图片框的左上和右下坐标
|
||
|
||
### 2. 将框的prompt和图片一起输入SAM模型
|
||
|
||
进入`segment-anything-main`文件夹
|
||
|
||
运行 `python test_box.py --checkpoint sam_vit_h_4b8939.pth --model-type vit_h --input ../ultralytics-main/input --output ./output --box-file ../ultralytics-main/output/car_boxes.txt`
|
||
|
||
在 `segment-anything-main/output` 可看到汽车显著图
|
||
|
||
### 3. 将显著图进行外接矩形和关键点检测
|
||
|
||
进入`demo`文件夹,修改`main`函数里所需要的图片路径,如下
|
||
|
||
```python
|
||
side_mask = '../segment-anything-main/output/2_mask.png'
|
||
side_rgb = '../ultralytics-main/input/2.png'
|
||
out_dir = './result'
|
||
process_side(side_mask, side_rgb, out_dir)
|
||
```
|
||
|
||
运行 `python3 point.py`
|
||
|
||
## 修改侧面关键点检测效果图
|
||
|
||
<img src="img\1.png" alt="1" style="zoom:80%;" />
|
||
|
||
<img src="img\2.png" alt="2" style="zoom:80%;" />
|
||
|
||
<img src="img\3.png" alt="3" style="zoom:80%;" />
|
||
|
||
<img src="img\4.png" alt="4" style="zoom:80%;" />
|
||
|
||
<img src="img\5.png" alt="5" style="zoom:80%;" />
|
||
|
||
有个检测不出来的原因是汽车拍出来颜色和背景颜色几乎一样,无法检测出。
|
||
|
||
还有一个是斜侧面,轴心检测还存在问题。
|