Example #1
0
    def update():
        x,y,c = databuff[CNT]

        scores, thetas, matches = zip(*dollar.query(x,y,scale,N,templates_fh))
        print
        for m,r,s in zip(matches,thetas,scores):
            print "'%s': %f (%f)" % (m,s,r*180/np.pi)

        for ax in axes.values(): ax.cla()

        axes['query'].plot(x,y,'-o')
        axes['query'].set_title("Test sample from class '%s'" % c)

        x,y = dollar.preprocess(x,y,scale,N)
        axes['transform'].plot(x,y,'-o')
        axes['transform'].set_title("Transformed query")

        for i in range(3):
            ds = templates_fh[matches[i]][0]
            x_r,y_r = dollar.rotate(x,y,thetas[i])
            axes['match_'+str(i)].plot(ds['x'],ds['y'],'-o',color='b')
            axes['match_'+str(i)].plot(x_r,y_r,'-o',color='g')
            axes['match_'+str(i)].set_title("'%s' (%.2f)" % (matches[i],scores[i]))
        
        fig.canvas.draw()
Example #2
0
    def Track(self, img):
        mask = self.segmenter.segment(img)

        if self.segmenter.moseg.bbox is not None:
            x, y, w, h = self.segmenter.moseg.bbox
            mask.fill(0)
            mask[y:y + h, x:x + w] = True

            x, y, w, h = self.tracker.track(
                self.segmenter.coseg.converted_image, mask)

            # it's possible that there is still motion but that tracking failed
            # so make sure backprojection is not all zeros
            if self.tracker.backprojection.any():
                bbox, (xc, yc) = findBBoxCoM(self.tracker.backprojection)
                self.waypts.append((int(xc), int(yc)))
                return  # success! keep tracking...

        # if we got to this point then tracking has failed
        if len(self.waypts) > MINWAYPTS and self.callback is not None:
            # Find best gesture match
            x, y = zip(*[(self.imshape[1] - x, self.imshape[0] - y)
                         for x, y in self.waypts])
            matches = dollar.query(x, y, scale, samplesize, self.template_ds)
            score, theta, clsid = matches[0]

            if score > self.match_threshold:
                ds = self.template_ds[clsid][0]
                self.callback((x, y), (ds['x'], ds['y']), score, theta, clsid)

        self.waypts = []
        return self.Wait
Example #3
0
    def update():
        x, y, c = databuff[CNT]

        scores, thetas, matches = zip(
            *dollar.query(x, y, scale, N, templates_fh))
        print
        for m, r, s in zip(matches, thetas, scores):
            print "'%s': %f (%f)" % (m, s, r * 180 / np.pi)

        for ax in axes.values():
            ax.cla()

        axes['query'].plot(x, y, '-o')
        axes['query'].set_title("Test sample from class '%s'" % c)

        x, y = dollar.preprocess(x, y, scale, N)
        axes['transform'].plot(x, y, '-o')
        axes['transform'].set_title("Transformed query")

        for i in range(3):
            ds = templates_fh[matches[i]][0]
            x_r, y_r = dollar.rotate(x, y, thetas[i])
            axes['match_' + str(i)].plot(ds['x'], ds['y'], '-o', color='b')
            axes['match_' + str(i)].plot(x_r, y_r, '-o', color='g')
            axes['match_' + str(i)].set_title("'%s' (%.2f)" %
                                              (matches[i], scores[i]))

        fig.canvas.draw()
Example #4
0
    def Track(self,img):
        mask = self.segmenter.segment(img)

        if self.segmenter.moseg.bbox is not None:
            x,y,w,h = self.segmenter.moseg.bbox
            mask.fill(0)
            mask[y:y+h,x:x+w] = True

            x,y,w,h = self.tracker.track(self.segmenter.coseg.converted_image,mask)

            # it's possible that there is still motion but that tracking failed
            # so make sure backprojection is not all zeros
            if self.tracker.backprojection.any():
                bbox,(xc,yc) = findBBoxCoM(self.tracker.backprojection)
                self.waypts.append((int(xc),int(yc)))
                return # success! keep tracking...

        # if we got to this point then tracking has failed
        if len(self.waypts) > MINWAYPTS and self.callback is not None:
            # Find best gesture match
            x,y = zip(*[(self.imshape[1]-x,self.imshape[0]-y) for x,y in self.waypts])
            matches = dollar.query(x,y,scale,samplesize,self.template_ds)
            score,theta,clsid = matches[0]

            if score > self.match_threshold:
                ds = self.template_ds[clsid][0]
                self.callback((x,y),(ds['x'],ds['y']),score,theta,clsid)

        self.waypts = []
        return self.Wait