def run(self, img, features, bboxes):
   boxSet = bboxes
   areas = [det.area(b) for b in boxSet]
   rank = np.argsort(areas)[::-1]
   rankedBoxes = [boxSet[i].tolist() for i in rank[0:self.maxTime]]
   scores = [features[i,self.categoryIndex].tolist() for i in rank[0:maxTime]]
   return (img, rankedBoxes, scores, range(len(rankedBoxes)))
Example #2
0
 def run(self, img, features, bboxes):
     boxSet = bboxes
     areas = [det.area(b) for b in boxSet]
     rank = np.argsort(areas)[::-1]
     rankedBoxes = [boxSet[i].tolist() for i in rank[0:self.maxTime]]
     scores = [
         features[i, self.categoryIndex].tolist() for i in rank[0:maxTime]
     ]
     return (img, rankedBoxes, scores, range(len(rankedBoxes)))
 def loadGroundTruth(self, imageName):
   try:
     gt = self.groundTruth[imageName]
   except:
     gt = []
   if self.image != imageName:
     self.displayEpisodePerformance()
     self.image = imageName
     self.boxes = [b[:] for b in gt]
     self.centers = [center(b) for b in gt]
     self.areas = [det.area(b) for b in gt]
     self.control = {'IOU': [0.0 for b in gt], 'DONE': [False for b in gt], 
                     'SKIP': [False for b in gt]} 
   return gt
Example #4
0
def loadFilteredFeaturesAndIndex(img, content, index):
    import libDetection as det
    import numpy as np
    MAX_BOXES = 1000
    m, l = loadFeaturesAndIndex(img, content, index)
    if len(l) > MAX_BOXES:
        limit = max(len(l) - MAX_BOXES, 0)
        areas = [det.area(map(float, b[1:])) for b in l]
        areasIdx = np.argsort(areas)
        candidates = np.asarray([i >= limit for i in areasIdx])
        boxes = [l[i] for i in areasIdx if i >= limit]
        return (m[candidates].astype(floatType), boxes)
    else:
        return m, l
def loadFilteredFeaturesAndIndex(img,content,index):
  import libDetection as det
  import numpy as np
  MAX_BOXES = 1000
  m,l = loadFeaturesAndIndex(img,content,index)
  if len(l) > MAX_BOXES:
    limit = max(len(l)-MAX_BOXES,0)
    areas = [ det.area(map(float,b[1:])) for b in l]
    areasIdx = np.argsort(areas)
    candidates = np.asarray([i >= limit for i in areasIdx])
    boxes = [l[i] for i in areasIdx if i >= limit]
    return (m[candidates].astype(floatType),boxes)
  else:
    return m,l
Example #6
0
 def loadGroundTruth(self, imageName):
     try:
         gt = self.groundTruth[imageName]
     except:
         gt = []
     if self.image != imageName:
         self.displayEpisodePerformance()
         self.image = imageName
         self.boxes = [b[:] for b in gt]
         self.centers = [center(b) for b in gt]
         self.areas = [det.area(b) for b in gt]
         self.control = {
             'IOU': [0.0 for b in gt],
             'DONE': [False for b in gt],
             'SKIP': [False for b in gt]
         }
     return gt
 def __init__(self, box, id):
   self.id = id
   self.box = box
   self.area = det.area(box)
def selectProposalsByArea(proposals,minArea,maxArea):
    areas = [det.area(box) for box in proposals]
    proposals = [[0]+proposals[i] for i in range(len(areas)) if areas[i] >= minArea and areas[i] < maxArea]
    return proposals
Example #9
0
import os,sys
import libDetection as det
import masks as mk

if len(sys.argv) < 3:
  print 'Use: filterDPMBoxes.py input output'
  sys.exit()


boxes = mk.loadBoxIndexFile(sys.argv[1])
totalBoxes = 0
keptBoxes = 0
out = open(sys.argv[2],'w')
for img in boxes.keys():
  unique = set([':'.join(map(str,map(int,x))) for x in boxes[img]])
  for b in boxes[img]:
    boxHash = ':'.join(map(str,map(int,b)))
    if boxHash in unique:
      unique.remove(boxHash)
    else:
      continue
    totalBoxes += 1
    a = det.area(b)
    w,h = b[2]-b[0],b[3]-b[1]
    if a > 400 and w > 0 and h > 0:
      out.write(img + ' ' + ' '.join(map(str,map(int,b))) + '\n' )
      keptBoxes += 1

print 'Total boxes:',totalBoxes,'Filtered:',totalBoxes-keptBoxes,'Final Boxes:',keptBoxes
out.close()
Example #10
0
def selectProposalsByArea(proposals, minArea, maxArea):
    areas = [det.area(box) for box in proposals]
    proposals = [[0] + proposals[i] for i in range(len(areas))
                 if areas[i] >= minArea and areas[i] < maxArea]
    return proposals
Example #11
0
 def __init__(self, box, id):
   self.id = id
   self.box = box
   self.area = det.area(box)
Example #12
0
import os,sys
import utils as cu
import libDetection as det
import numpy as np

if __name__ == "__main__":
  params = cu.loadParams('boxesFile minSize outputFile')
  boxes = [x.split() for x in open(params['boxesFile'])]
  minA = float(params['minSize'])**2
  images = {}
  found = set()
  for box in boxes:
    a = det.area( map(int,box[1:]) )
    if a >= minA:
      try:
        images[ box[0] ].append(box[1:])
      except:
        images[ box[0] ] = [box[1:]]
    found.add(box[0])
  # Add records for images that do not have enough area to comply with the filter      
  missing = found.symmetric_difference( images.keys() )
  missing = [b for b in boxes if b[0] in missing]
  allAreas = {}
  for m in missing:
      img = m[0]
      try:
          allAreas[img]['box'].append( m[1:] )
          allAreas[img]['area'].append( det.area( map(int,m[1:]) ) )
      except:
          allAreas[img] = { 'box':[m[1:]], 'area':[det.area( map(int,m[1:]) )] }
  for img in allAreas.keys():