Created
April 1, 2019 09:12
-
-
Save toshihiroryuu/4dadf00da9032594a2cc6bd519c3ed5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import cv2 | |
import os | |
import csv | |
from skimage.draw import random_shapes | |
PATH='/home/generated_shapes' | |
# result = random_shapes((128, 128), max_shapes=1, shape='rectangle', | |
# multichannel=False) | |
# # We get back a tuple consisting of (1) the image with the generated shapes | |
# # and (2) a list of label tuples with the kind of shape (e.g. circle, | |
# # rectangle) and ((r0, r1), (c0, c1)) coordinates. | |
# image, labels = result | |
# print('Image shape: {}\nLabels: {}'.format(image.shape, labels)) | |
# image, labels = random_shapes((128, 128), min_shapes=5, max_shapes=10, | |
# min_size=20, allow_overlap=True) | |
headerr= [['Image_Name','Shape','r0','r1','c0','c1']] | |
with open('/home/generated_shapes/shapes.csv','w') as f: | |
writer=csv.writer(f) | |
writer.writerows(headerr) | |
print("Header row created") | |
for i in range(10): | |
image, labels = random_shapes((128, 128), min_shapes=2, max_shapes=5, | |
min_size=20) | |
cv2.imwrite(os.path.join(PATH+'/'+str(i)+'.jpg'),image) | |
for label in labels: | |
print(label[0]) | |
#for shapes in label: | |
#print(shapes) | |
#print('Image shape: {}\nLabels: {}'.format(image.shape, labels)) | |
# | |
# for label in labels: | |
# for shape in range(5): | |
# for pair in range(2): | |
# for r in range(2): | |
# for c in range(2): | |
# row=label[shape][pair][r][c] | |
# print(row) | |
# with open('/home/generated_shapes/shapes.csv','w') as f: | |
# writer=csv.writer(f) | |
# writer.writerows(row) | |
print("label {}".format(labels[0][1][1][1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment