-
Notifications
You must be signed in to change notification settings - Fork 88
/
image_generate.py
36 lines (32 loc) · 1.01 KB
/
image_generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import cv2
import numpy as np
from lib.image_generator import *
print("loading image generator...")
input_width = 448
input_height = 448
item_path = "./items"
background_path = "./backgrounds"
generator = ImageGenerator(item_path, background_path)
# generate random sample
x, t = generator.generate_samples(
n_samples=64,
n_items=3,
crop_width=input_width,
crop_height=input_height,
min_item_scale=0.5,
max_item_scale=2,
rand_angle=30,
minimum_crop=0.85,
delta_hue=0.01,
delta_sat_scale=0.5,
delta_val_scale=0.5
)
for i, image in enumerate(x):
image = np.transpose(image, (1, 2, 0)).copy()
width, height, _ = image.shape
for truth_box in t[i]:
box_x, box_y, box_w, box_h = truth_box['x']*width, truth_box['y']*height, truth_box['w']*width, truth_box['h']*height
image = cv2.rectangle(image.copy(), (int(box_x-box_w/2), int(box_y-box_h/2)), (int(box_x+box_w/2), int(box_y+box_h/2)), (0, 0, 255), 3)
print(t[i])
cv2.imshow("w", image)
cv2.waitKey(500)