dx2 = None Xs = None #plt.imshow(inf) lastClick = 0.0 while 1: start = time.time() im2 = get_screenshot(640, 480).astype('double')[:360, :640] / 255.0 if im != None: dx2 = im - im2 if dx2 != None: dx2 = numpy.linalg.norm(features.rgbhist(dx2, 16), axis = 2) if Xs == None: Xs, Ys = numpy.meshgrid(numpy.arange(dx2.shape[1]), numpy.arange(dx2.shape[0])) Rs = (Xs - dx2.shape[1] / 2)**2 / 2.0 + (Ys - dx2.shape[0] / 2)**2 Rs2 = (Xs - dx2.shape[1] / 2)**2 / 1.5 + (Ys - dx2.shape[0] / 2)**2 / 2.0 inf = numpy.exp(-Rs / 100.0) - numpy.exp(-Rs2 / 5.0) if dx == None: dx = dx2 else: dx = 0.5 * dx + 0.5 * dx2 if dx != None: probs = (inf * dx).flatten()
for k, frame in enumerate(frames[0:100:10]): im = frame[:360].astype('double') / 255.0 #im = skimage.color.rgb2hsv((im * 255).astype('uint8')) #plt.imshow(im[:, :, 0], interpolation = 'NONE', cmap = plt.cm.hsv); #plt.colorbar() #plt.show() #plt.imshow(im[:, :, 1], interpolation = 'NONE', cmap = plt.cm.hsv); #plt.colorbar() #plt.show() #plt.imshow(im[:, :, 2], interpolation = 'NONE', cmap = plt.cm.hsv); #plt.colorbar() #plt.show() tmp = time.time() hog = features.hogpad(features.hog(im, b)) rgb = features.rgbhist(im, b) print time.time() - tmp #plt.imshow(im, interpolation = 'NONE') #plt.show() #plt.imshow(skimage.color.rgb2gray(im), interpolation = 'NONE', cmap = plt.cm.gray) #plt.imshow(rgb, interpolation = 'NONE') #plt.show() Y = rgb.shape[0] X = rgb.shape[1] rgbf = numpy.zeros((rgb.shape[0], rgb.shape[1], sy * sx * rgb.shape[2])) indices[k] = [] descs[k] = []
#%% codes = os.listdir('filtered_sprites_160x160') Xs = [] Xsb = [] labels = [] for code in codes: images = numpy.load('filtered_sprites_160x160/{0}'.format(code)).astype('double')[:, 40:120, 40:120, :4] labels.extend(images.shape[0] * [int(code)]) images2 = [] for image in images: images2.append(features.rgbhist(image[:, :, :3] / 255.0, 4)) Xs.append(images2) backgroundSample = backgrounds[1][20:100, 20:100] images3 = [] for image in images: mask = (image[:, :, 3] > 254.5) image2 = numpy.array(image).copy() image2[:, :, 0] += mask * backgroundSample[:, :, 0].astype('double') image2[:, :, 1] += mask * backgroundSample[:, :, 1].astype('double') image2[:, :, 2] += mask * backgroundSample[:, :, 2].astype('double') images3.append(features.rgbhist(image2[:, :, :3] / 255.0, 4)) Xsb.append(images3)
#plt.imshow(im3) #plt.show() #plt.imshow(backgroundSample) #plt.show() im4 = im3[:, :, :3] / 255.0 eimages.append(im4) idx += 1 #1/0 print i images = numpy.array(eimages) #%% images = [] for image in eimages: images.append(features.rgbhist(image, 8)) images = numpy.array(images) #%% del eimages #%% #features = numpy.array([(feature - mean) for feature in features]) i2l = list(enumerate(list(set(labels)))) l2i = dict([(l, i) for i, l in i2l]) def one(N, i): a = numpy.zeros(N) a[i] = 1.0 return a lref = numpy.array([one(len(i2l), l2i[l]) for l in labels])