def __init__(self, path): """You provide the path of the dataset and then the input to channel 0 is the background subtraction mask.""" self.path = path # Open the region of interest and convert it into a mask we can use... roi = cv.LoadImage(os.path.join(path, 'ROI.bmp')) self.roi = (cv2array(roi)!=0).astype(numpy.uint8) if len(self.roi.shape)==3: self.roi = self.roi[:,:,0] # Get the temporal range of the frames we are to analyse... data = open(os.path.join(path, 'temporalROI.txt'), 'r').read() tokens = data.split() assert(len(tokens)==2) self.start = int(tokens[0]) self.end = int(tokens[1]) # Note that these are inclusive. # Confusion matrix - first index is truth, second guess, bg=0, fg=1... self.con = numpy.zeros((2,2), dtype=numpy.int32) # Shadow matrix - for all pixels that are in shadow records how many are background (0) and how many are foreground (1)... self.shadow = numpy.zeros(2, dtype=numpy.int32) # Basic stuff... self.frame = 0 self.video = None self.channel = 0
def nextFrame(self): self.frame = cv.QueryFrame(self.vid) if self.frame==None: return False self.frameNP = cv2array(self.frame)[:,:,::-1].astype(numpy.float32)/255.0 return True
def nextFrame(self): self.frame = cv.QueryFrame(self.vid) if self.frame == None: return False self.frameNP = cv2array(self.frame)[:, :, ::-1].astype( numpy.float32) / 255.0 return True
def nextFrame(self): if self.index<len(self.files): try: img = cv.LoadImage(self.files[self.index]) #print img.nChannels, img.width, img.height, img.depth, img.origin self.frame = cv2array(img)[:,:,::-1].astype(numpy.float32)/255.0 except: print 'Frame #%i with filename %s failed to load.'%(self.index,self.files[self.index]) self.index += 1 else: self.frame = None return self.frame!=None
def nextFrame(self): if self.index < len(self.files): try: img = cv.LoadImage(self.files[self.index]) #print img.nChannels, img.width, img.height, img.depth, img.origin self.frame = cv2array(img)[:, :, ::-1].astype( numpy.float32) / 255.0 except: print 'Frame #%i with filename %s failed to load.' % ( self.index, self.files[self.index]) self.index += 1 else: self.frame = None return self.frame != None
def nextFrame(self): # Increase frame number - need to be 1 based for this... self.frame += 1 if self.frame>=self.start and self.frame<=self.end: # Fetch the provided mask... mask = self.video.fetch(self.channel) # Load the ground truth file... fn = os.path.join(self.path, 'groundtruth/gt%06i.png'%self.frame) gt = cv2array(cv.LoadImage(fn)) gt = gt.astype(numpy.uint8) if len(gt.shape)==3: gt = gt[:,:,0] # Loop the pixels and analyse each one, summing into the confusion matrix... code = start_cpp() + """ for (int y=0; y<Ngt[0]; y++) { for (int x=0; x<Ngt[1]; x++) { if ((ROI2(y,x)!=0)&&(GT2(y,x)!=170)) { int t = (GT2(y,x)==255)?1:0; int g = (MASK2(y,x)!=0)?1:0; CON2(t,g) += 1; if (GT2(y,x)==50) { SHADOW1(g) += 1; } } } } """ roi = self.roi con = self.con shadow = self.shadow weave.inline(code, ['mask', 'gt', 'roi', 'con', 'shadow']) return self.frame<=self.end