-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_images.py
53 lines (40 loc) · 1.23 KB
/
create_images.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import random
import cv2
import numpy as np
# Module to create random images
# It is called by training, drawing and the flask api
IMAGE_SIZE = 200
def create_sample():
canvas = np.ones((IMAGE_SIZE, IMAGE_SIZE, 3)) * 255
# If there is object
pc = random.randint(0, 1)
# Circle position and dimension
radius = int(random.randint(0, IMAGE_SIZE) / 2)
radius = max(int(IMAGE_SIZE*0.05), radius)
radius = min(int(IMAGE_SIZE*0.4), radius)
center_x = random.randint(0, IMAGE_SIZE)
center_x = max(center_x, radius)
center_x = min(center_x, (IMAGE_SIZE-radius))
center_y = random.randint(0, IMAGE_SIZE)
center_y = max(center_y, radius)
center_y = min(center_y, (IMAGE_SIZE-radius))
if pc == 1:
cv2.circle(
canvas,
(center_x, center_y),
radius,
(0,0,0),
-1
)
sample = {
"params": [pc, pc*center_x, pc*center_y, pc*radius*2, pc*radius*2],
#"params": [center_x, center_y, radius*2, radius*2],
"image": canvas,
}
return sample
def create_images(sample_size):
images = []
for i in range(sample_size):
sample = create_sample()
images.append(sample)
return images