Skip to content

Commit

Permalink
docs(transform): 随机水平翻转
Browse files Browse the repository at this point in the history
  • Loading branch information
zjZSTU committed May 10, 2020
1 parent cfb0fb1 commit 66c2aaa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Binary file added docs/data/transforms/imgs/random_mirror.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions docs/data/transforms/随机镜像.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# 随机镜像

* `py/ssd/data/transforms/random_mirror.py`

水平翻转图像

## 示例

![](./imgs/random_mirror.png)
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ nav:
- 格式转换: data/transforms/格式转换.md
- 光度扭曲: data/transforms/光度扭曲.md
- 图像扩展: data/transforms/图像扩展.md
- 随机裁剪: data/transforms/随机裁剪.md
- 随机裁剪: data/transforms/随机裁剪.md
- 随机镜像: data/transforms/随机镜像.md
30 changes: 30 additions & 0 deletions py/ssd/data/transforms/random_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,33 @@ def __call__(self, image, boxes, classes):
boxes = boxes.copy()
boxes[:, 0::2] = width - boxes[:, 2::-2]
return image, boxes, classes


if __name__ == '__main__':
import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('../../../datasets/003123.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
boxes = np.array([[33, 44, 123, 210]])
labels = np.array([3])

model = RandomMirror()

f = plt.figure()
rows = 3
cols = 3

plt.subplot(rows, cols, 1)
plt.title('src')
plt.imshow(img), plt.axis('off')
for i in range(rows):
for j in range(cols):
if i == 0 and j == 0:
continue
plt.subplot(rows, cols, i * cols + j + 1)
res, res_boxes, _ = model(img.astype(np.float32), boxes, labels)
plt.imshow(res.astype(np.uint8)), plt.axis('off')
print('{}-{} : {} - {}'.format(i, j, res_boxes, labels))
plt.show()

0 comments on commit 66c2aaa

Please sign in to comment.