Exemplo de como desenhar

In [1]:
import numpy as np
%matplotlib notebook
from matplotlib import pyplot as plt
In [2]:
from skimage.feature import hog
In [3]:
import cPickle as pickle

Carregar base de dados

In [4]:
pkl_file = open('../data/guaspari/2017-04-27/grape_dataset_1313.pickle', 'r')
grape_dataset = pickle.load(pkl_file)
pkl_file.close()
In [6]:
from skimage.draw import circle_perimeter, circle_perimeter_aa
In [7]:
import cv2
In [8]:
x = grape_dataset['data'][0]
plt.imshow(x.reshape(32,32), cmap=plt.cm.gray, interpolation='nearest')
plt.axis('off')
Out[8]:
(-0.5, 31.5, 31.5, -0.5)
In [22]:
from sklearn.preprocessing import MinMaxScaler
In [24]:
scaler = MinMaxScaler((0,255))
In [48]:
x = scaler.fit_transform(grape_dataset['data'][0].copy().reshape(32,32))
x = np.dstack(3 * [np.array(x, dtype=np.uint8)])
rr, cc, = circle_perimeter(16, 16, 13)
x[rr, cc] = (255, 0, 0)
plt.imshow(x, interpolation='nearest')
plt.axis('off')
Out[48]:
(-0.5, 31.5, 31.5, -0.5)
In [57]:
x = scaler.fit_transform(grape_dataset['data'][0].copy().reshape(32,32))
x = np.dstack(3 * [np.array(x, dtype=np.uint8)])
rr, cc, val = circle_perimeter_aa(16, 16, 13)
x[rr, cc, 0] = val * 255
plt.imshow(x, interpolation='nearest')
plt.axis('off')
Out[57]:
(-0.5, 31.5, 31.5, -0.5)
In [59]:
x = scaler.fit_transform(grape_dataset['data'][0].copy().reshape(32,32))
x = np.dstack(3 * [np.array(x, dtype=np.uint8)])
cv2.circle(x, (16,16), 13, (255,0,0), thickness=1, lineType=cv2.LINE_AA)
plt.imshow(x, interpolation='nearest')
plt.axis('off')
Out[59]:
(-0.5, 31.5, 31.5, -0.5)