可视化anchor的代码
时间: 2024-05-06 15:03:25 浏览: 5
以下是可视化anchor的Python代码,使用了Matplotlib库:
```python
import numpy as np
import matplotlib.pyplot as plt
def visualize_anchors(anchors, image_size):
"""Visualize anchors on an image of given size."""
# Create a blank image
img = np.zeros((image_size, image_size))
# Plot each anchor as a rectangle
for anchor in anchors:
x1, y1, x2, y2 = anchor
plt.plot([x1, x1, x2, x2, x1], [y1, y2, y2, y1, y1], 'r')
# Show the image with anchors
plt.imshow(img, cmap='gray')
plt.show()
# Example usage
anchors = [[50, 50, 100, 100], [75, 75, 125, 125], [100, 100, 150, 150]]
visualize_anchors(anchors, 200)
```
这个函数接受两个参数:anchors和image_size。anchors是一个包含多个anchor的列表,每个anchor用四个值表示(左上角和右下角的x、y坐标)。image_size是要在其上可视化anchor的图像大小。
函数使用Matplotlib库来创建一个空白图像,然后在其上绘制每个anchor的矩形。最后,函数显示包含anchor的图像。