def get_features(self, frame, target_points):
     sd = starfeature.star_detector(frame.size[0], frame.size[1], 5,
                                    self.thresh, self.line_thresh)
     by_response = sorted(sd.detect(frame.rawdata),
                          key=lambda x: (abs(x[3]), x[0], x[1]),
                          reverse=True)
     return [(x, y) for (x, y, s, r) in by_response]
Esempio n. 2
0
    def get_features_new(self, frame, target_points, rect, extra_incr):

        if DEBUG:
            print "Features from rect ", rect

        full = Image.fromstring("L", frame.size, frame.rawdata)
        (x, y, w, h) = (int(rect[0]), int(rect[1]), int(rect[2]), int(rect[3]))
        innerbox = [max(0, x - extra_incr), max(0, y - extra_incr)]
        innerbox += [
            min(full.width, x + w + extra_incr),
            min(full.height, y + h + extra_incr)
        ]
        incr = 16
        outerbox = [max(0, innerbox[0] - incr), max(0, innerbox[1] - incr)]
        outerbox += [
            min(full.width, innerbox[2] + incr),
            min(full.height, innerbox[3] + incr)
        ]
        subim = full.crop(outerbox)

        sd = starfeature.star_detector(outerbox[2] - outerbox[0] + 1,
                                       outerbox[3] - outerbox[1] + 1,
                                       self.num_scales,
                                       self.feature_detector.thresh,
                                       self.line_thresh)
        results = [(x1, y1)
                   for (x1, y1, s1, r1) in sd.detect(subim.tostring())]
        real_incr = [abs(i1 - o1) for (i1, o1) in zip(innerbox, outerbox)]
        return [(x1 - real_incr[0] + 1, y1 - real_incr[1] + 1)
                for (x1, y1) in results
                if (real_incr[0] < x1) and (real_incr[1] < y1) and (
                    x1 < outerbox[2] - real_incr[2]) and (
                        y1 < outerbox[3] - real_incr[3])]
Esempio n. 3
0
    def test_order_invariance(self):
        """ Check that output is independent of presentation order """
        def runone(sd, im):
            kp = sd.detect(im.tostring())
            return [
                i[1] for i in sorted([(abs(response), (x, y, s, response))
                                      for (x, y, s, response) in kp])
            ]

        pool = [self.im640.resize((256, 256))]

        pool += [Image.new("L", (256, 256), c) for c in [0, 101, 255]]
        pool += [
            Image.fromstring(
                "L", (256, 256), "".join(
                    [chr(random.randrange(0, 256)) for i in range(256 * 256)]))
            for j in range(5)
        ]

        random.seed(0)
        random.shuffle(pool)

        ref = [simple(im) for im in pool]

        sd = L.star_detector(256, 256)

        for order in [pool, pool[::-1]]:
            result = [runone(sd, s) for s in pool]
            self.assertEqual(sorted(ref), sorted(result))
Esempio n. 4
0
def simple(im,
           scales=7,
           threshold=30.0,
           line_threshold=10.0,
           line_threshold_bin=8.0):
    sd = L.star_detector(im.size[0], im.size[1], scales, threshold,
                         line_threshold, line_threshold_bin)
    return detect(sd, im)
Esempio n. 5
0
def simple(im, scales=7, threshold=30.0, line_threshold=10.0):
    sd = L.star_detector(im.size[0], im.size[1], scales, threshold,
                         line_threshold)
    kp = sd.detect(im.tostring())
    return [
        i[1] for i in sorted([(abs(response), (x, y, s, response))
                              for (x, y, s, response) in kp])
    ]
  def get_features(self, frame, target_points, rect2d, censize3d):
    
    if DEBUG:
      print "Features from rect ", rect2d
    
    # Clear out all of the match info since it's not valid anymore.
    frame.matches = []
    frame.desc_diffs = []
    frame.good_matches = []

    # Extract 2d keypoints and get their disparities
    full = Image.fromstring("L",frame.size,frame.rawdata)
    (x,y,w,h) = (int(rect2d[0]), int(rect2d[1]), int(rect2d[2]), int(rect2d[3]))
    incr = 16
    subim = full.crop((x-incr,y-incr,x+w+incr,y+h+incr))
    
    sd = starfeature.star_detector(w+2*incr, h+2*incr, self.num_scales, self.feature_detector.thresh, self.line_thresh)
    results = [ (x1,y1) for (x1,y1,s1,r1) in sd.detect(subim.tostring()) ]
    frame.kp2d = [(x-incr+x1,y-incr+y1) for (x1,y1) in results if (incr<x1) and (incr<y1) and (x1<w+incr) and (y1<h+incr)]
    if not frame.kp2d:
      frame.kp2d = []
      frame.kp = []
      frame.avgd = -1.0
      print "No features"
      return

    self.vo.find_disparities(frame)

    # Convert to 3d keypoints and remove entries with invalid depths. I'm going to limit it to faces that are within a max dist as well.
    frame.kp = [kp for kp in frame.kp if 0.0<kp[2]]
    if not frame.kp:
      frame.kp2d = []
      frame.kp = []
      frame.avgd = -1.0
      print "no features"
      return
      
    frame.kp3d = [self.cam.pix2cam(kp[0],kp[1],kp[2]) for kp in frame.kp]
    to_remove = [kp3d[2]>self.max_face_dist or kp3d[2]<censize3d[2]-censize3d[3] or kp3d[2]>censize3d[2]+censize3d[3] for kp3d in frame.kp3d]
    # But only remove the entries if there are a few left. Otherwise, leave them all.
    if True: # sum(to_remove)<len(frame.kp)-2:
      #for k in [frame.kp, frame.kp3d]:
      frame.kp = [kp for (kp,remove) in zip(frame.kp,to_remove) if not remove]
      frame.kp3d = [kp for (kp,remove) in zip(frame.kp3d,to_remove) if not remove]
    if frame.kp:
      print len(frame.kp)
    else:
      print "0"
    # Enforce that kp2d and kp are the same. I would remove kp2d altogether except the stereo code uses it.
    frame.kp2d = [[kp[0],kp[1]] for kp in frame.kp]
    if frame.kp:
      frame.avgd = sum([kp[2] for kp in frame.kp])/len(frame.kp)
    else:
      frame.avgd = -1.0
Esempio n. 7
0
 def xtest_z_perf(self):
     sd = L.star_detector(self.im640.size[0], self.im640.size[1])
     s = self.im640.tostring()
     niter = 100
     started = time.time()
     for i in range(niter):
         kp = sd.detect(s)
     took = time.time() - started
     print
     print
     print "%.1f ms/frame" % (1e3 * took / niter)
     print
     print
Esempio n. 8
0
 def test_face(self):
     im = Image.open("face1.png").convert("L")
     # (114, 114, 5, 3, 10.0)
     sd = L.star_detector(im.size[0], im.size[1], 5, 3.0, 999.0)
     kp = sd.detect(im.tostring())
     for (x,y,s,r) in kp:
         if r < 0:
             color = 0
         else:
             color = 255
         circle(im, x, y, s, color)
     comp = Image.new("L", (im.size[0] * 2, im.size[1]))
     comp.paste(Image.open("face1.png").convert("L"), (0,0))
     comp.paste(im, (im.size[0], 0))
     comp.save("out.png")
Esempio n. 9
0
 def perftest(self):
     print
     print
     for size in [ (512,384), (640,480) ]:
       im = self.im640.resize(size)
       sd = L.star_detector(im.size[0], im.size[1])
       s = im.tostring()
       niter = 400
       started = time.time()
       for i in range(niter):
         kp = sd.detect(s)
       took = time.time() - started
       print "%16s: %.1f ms/frame" % (str(size), 1e3 * took / niter)
     print
     print
 def get_features_new(self, frame, target_points, rect, extra_incr):
   
   if DEBUG:
     print "Features from rect ", rect
   
   full = Image.fromstring("L",frame.size,frame.rawdata)
   (x,y,w,h) = (int(rect[0]), int(rect[1]), int(rect[2]), int(rect[3]))
   innerbox = [max(0,x-extra_incr), max(0,y-extra_incr)]
   innerbox += [min(full.width, x+w+extra_incr), min(full.height, y+h+extra_incr)]
   incr = 16
   outerbox = [max(0,innerbox[0]-incr), max(0,innerbox[1]-incr)]
   outerbox += [min(full.width, innerbox[2]+incr), min(full.height, innerbox[3]+incr)] 
   subim = full.crop(outerbox)
   
   sd = starfeature.star_detector(outerbox[2]-outerbox[0]+1, outerbox[3]-outerbox[1]+1, self.num_scales, self.feature_detector.thresh, self.line_thresh)
   results = [ (x1,y1) for (x1,y1,s1,r1) in sd.detect(subim.tostring()) ]
   real_incr = [abs(i1-o1) for (i1,o1) in zip(innerbox,outerbox)]
   return [(x1-real_incr[0]+1,y1-real_incr[1]+1) for (x1,y1) in results if (real_incr[0]<x1) and (real_incr[1]<y1) and (x1<outerbox[2]-real_incr[2]) and (y1<outerbox[3]-real_incr[3])]
Esempio n. 11
0
 def test_parameters(self):
     """ Change scales and thresholds """
     results = [
         simple(self.im640, 7, 30.0, 10.0, 8.0),
         simple(self.im640, 5, 30.0, 10.0, 8.0),
         simple(self.im640, 5, 25.0, 10.0, 8.0),
         simple(self.im640, 5, 25.0, 7.0, 8.0),
         simple(self.im640, 5, 25.0, 7.0, 4.0)
     ]
     # All should have different lengths
     self.assert_(len(set([ len(i) for i in results ])) == len(results))
     im = self.im640
     sd = L.star_detector(im.size[0], im.size[1], 7, 30.0, 10.0, 8.0)
     self.assert_(detect(sd, im) == results[0])
     sd.setScales(5)
     self.assert_(detect(sd, im) == results[1])
     sd.setResponseThreshold(25.0)
     self.assert_(detect(sd, im) == results[2])
     sd.setProjectedThreshold(7.0)
     self.assert_(detect(sd, im) == results[3])
     sd.setBinarizedThreshold(4.0)
     self.assert_(detect(sd, im) == results[4])
Esempio n. 12
0
    def test_order_invariance(self):
        """ Check that output is independent of presentation order """

        def runone(sd, im):
            kp = sd.detect(im.tostring())
            return [ i[1] for i in sorted([ (abs(response), (x, y, s, response)) for (x, y, s, response) in kp])]

        pool = [ self.im640.resize((256, 256)) ]

        pool += [ Image.new("L", (256, 256), c) for c in [0, 101, 255] ]
        pool += [Image.fromstring("L", (256,256), "".join([ chr(random.randrange(0, 256)) for i in range(256 * 256)])) for j in range(5)]

        random.seed(0)
        random.shuffle(pool)

        ref = [ simple(im) for im in pool ]

        sd = L.star_detector(256,256)

        for order in [ pool, pool[::-1] ]:
            result = [runone(sd, s) for s in pool]
            self.assertEqual(sorted(ref), sorted(result))
Esempio n. 13
0
 def test_parameters(self):
     """ Change scales and thresholds """
     results = [
         simple(self.im640, 7, 30.0, 10.0, 8.0),
         simple(self.im640, 5, 30.0, 10.0, 8.0),
         simple(self.im640, 5, 25.0, 10.0, 8.0),
         simple(self.im640, 5, 25.0, 7.0, 8.0),
         simple(self.im640, 5, 25.0, 7.0, 4.0)
     ]
     # All should have different lengths
     self.assert_(len(set([len(i) for i in results])) == len(results))
     im = self.im640
     sd = L.star_detector(im.size[0], im.size[1], 7, 30.0, 10.0, 8.0)
     self.assert_(detect(sd, im) == results[0])
     sd.setScales(5)
     self.assert_(detect(sd, im) == results[1])
     sd.setResponseThreshold(25.0)
     self.assert_(detect(sd, im) == results[2])
     sd.setProjectedThreshold(7.0)
     self.assert_(detect(sd, im) == results[3])
     sd.setBinarizedThreshold(4.0)
     self.assert_(detect(sd, im) == results[4])
Esempio n. 14
0
def simple(im, scales = 7, threshold = 30.0, line_threshold = 10.0, line_threshold_bin = 8.0):
    sd = L.star_detector(im.size[0], im.size[1], scales, threshold, line_threshold, line_threshold_bin)
    kp = sd.detect(im.tostring())
    return [ i[1] for i in sorted([ (abs(response), (x, y, s, response)) for (x, y, s, response) in kp])]
Esempio n. 15
0
def simple(im, scales = 7, threshold = 30.0, line_threshold = 10.0, line_threshold_bin = 8.0):
    sd = L.star_detector(im.size[0], im.size[1], scales, threshold, line_threshold, line_threshold_bin)
    return detect(sd, im)
Esempio n. 16
0
    def get_features(self, frame, target_points, rect2d, censize3d):

        if DEBUG:
            print "Features from rect ", rect2d

        # Clear out all of the match info since it's not valid anymore.
        frame.matches = []
        frame.desc_diffs = []
        frame.good_matches = []

        # Extract 2d keypoints and get their disparities
        full = Image.fromstring("L", frame.size, frame.rawdata)
        (x, y, w, h) = (int(rect2d[0]), int(rect2d[1]), int(rect2d[2]),
                        int(rect2d[3]))
        incr = 16
        subim = full.crop((x - incr, y - incr, x + w + incr, y + h + incr))

        sd = starfeature.star_detector(w + 2 * incr, h + 2 * incr,
                                       self.num_scales,
                                       self.feature_detector.thresh,
                                       self.line_thresh)
        results = [(x1, y1)
                   for (x1, y1, s1, r1) in sd.detect(subim.tostring())]
        frame.kp2d = [(x - incr + x1, y - incr + y1) for (x1, y1) in results
                      if (incr < x1) and (incr < y1) and (x1 < w + incr) and (
                          y1 < h + incr)]
        if not frame.kp2d:
            frame.kp2d = []
            frame.kp = []
            frame.avgd = -1.0
            print "No features"
            return

        self.vo.find_disparities(frame)

        # Convert to 3d keypoints and remove entries with invalid depths. I'm going to limit it to faces that are within a max dist as well.
        frame.kp = [kp for kp in frame.kp if 0.0 < kp[2]]
        if not frame.kp:
            frame.kp2d = []
            frame.kp = []
            frame.avgd = -1.0
            print "no features"
            return

        frame.kp3d = [self.cam.pix2cam(kp[0], kp[1], kp[2]) for kp in frame.kp]
        to_remove = [
            kp3d[2] > self.max_face_dist
            or kp3d[2] < censize3d[2] - censize3d[3]
            or kp3d[2] > censize3d[2] + censize3d[3] for kp3d in frame.kp3d
        ]
        # But only remove the entries if there are a few left. Otherwise, leave them all.
        if True:  # sum(to_remove)<len(frame.kp)-2:
            #for k in [frame.kp, frame.kp3d]:
            frame.kp = [
                kp for (kp, remove) in zip(frame.kp, to_remove) if not remove
            ]
            frame.kp3d = [
                kp for (kp, remove) in zip(frame.kp3d, to_remove) if not remove
            ]
        if frame.kp:
            print len(frame.kp)
        else:
            print "0"
        # Enforce that kp2d and kp are the same. I would remove kp2d altogether except the stereo code uses it.
        frame.kp2d = [[kp[0], kp[1]] for kp in frame.kp]
        if frame.kp:
            frame.avgd = sum([kp[2] for kp in frame.kp]) / len(frame.kp)
        else:
            frame.avgd = -1.0
Esempio n. 17
0
 def get_features(self, frame, target_points):
     sd = starfeature.star_detector(frame.size[0], frame.size[1], 5,
                                    self.thresh, self.line_thresh)
     return [(x, y) for (x, y, s, r) in sd.detect(frame.rawdata)]
Esempio n. 18
0
 def get_features(self, frame, target_points):
   sd = starfeature.star_detector(frame.size[0], frame.size[1], 5, self.thresh, self.line_thresh)
   return [ (x,y) for (x,y,s,r) in sd.detect(frame.rawdata) ]