from SimpleCV import Camera, Image, Color, TemporalColorTracker, ROI, Display import matplotlib.pyplot as plt cam = Camera(1) tct = TemporalColorTracker() img = cam.getImage() roi = ROI(img.width * 0.45, img.height * 0.45, img.width * 0.1, img.height * 0.1, img) tct.train(cam, roi=roi, maxFrames=250, pkWndw=20) # Matplot Lib example plotting plotc = {'r': 'r', 'g': 'g', 'b': 'b', 'i': 'm', 'h': 'y'} for key in list(tct.data.keys()): plt.plot(tct.data[key], plotc[key]) for pt in tct.peaks[key]: plt.plot(pt[0], pt[1], 'r*') for pt in tct.valleys[key]: plt.plot(pt[0], pt[1], 'b*') plt.grid() plt.show() disp = Display((800, 600)) while disp.isNotDone(): img = cam.getImage() result = tct.recognize(img) plt.plot(tct._rtData, 'r-') plt.grid() plt.savefig('temp.png') plt.clf() plotImg = Image('temp.png')
if not os.path.exists(negdir): os.mkdir(negdir) disp = Display() iset = ImageSet('data') for img in iset: img.save(disp) face = img.findHaarFeatures('face.xml') if (face is not None and len(face) > 0): face[-1].draw(width=3) img.applyLayers().save(disp) fname = outdir + 'Face' + str(count) + '.png' face[-1].crop().resize(sz, sz).toGray().save(fname) print "Saving: " + fname count = count + 1 ncount = 0 while ncount < negcount: pt = 256 * np.random.rand(1, 2) roi = ROI( np.round((img.width - sz) * np.random.rand(1))[0], np.round((img.height - sz) * np.random.rand(1))[0], sz, sz, img) #print roi.toXYWH() if (not face[-1].overlaps(roi)): #roi.draw(width=3) #img.applyLayers().save(disp) fname = negdir + "Neg" + str(negTotal) + ".png" roi.crop().toGray().save(fname) ncount += 1 negTotal += 1