예제 #1
0
파일: TLD.py 프로젝트: wangjuenew/pyOpenTLD
 def initialLearning(self):
     print "initialLearning"
     #raw_input()
     self.learning = True
     self.detectionResult = self.detectorCascade.detectionResult
     self.detectorCascade.detect(self.currImg)
     
     patch = NormalizedPatch()
     patch.values = tldExtractNormalizedPatchRect(self.currImg, self.currBB)
     patch.positive = 1
     
     initVar = tldCalcVariance(patch.values)
     self.detectorCascade.varianceFilter.minVar = initVar/2
     
     overlap = tldOverlapRect(self.detectorCascade.windows, self.detectorCascade.numWindows, self.currBB)
     #print overlap
     #raw_input()
     
     positiveIndices = []
     negativeIndices = []
     
     for i in xrange(len(overlap)):
         if overlap[i] > 0.6:
             positiveIndices.append((i,overlap[i]))
         if overlap[i] < 0.2:
             variance = self.detectionResult.variances[i]
             if not self.detectorCascade.varianceFilter.enabled or variance > self.detectorCascade.varianceFilter.minVar:
                 negativeIndices.append(i)
     
     positiveIndices.sort(key=lambda p:p[1])
     
     patches = []
     patches.append(patch)
     
     numIterations = min(len(positiveIndices), 10)
     for i in xrange(numIterations):
         print "self.detectorCascade.ensembleClassifier.learn"
         raw_input()
         idx = positiveIndices[i][0]
         self.detectorCascade.ensembleClassifier.learn(self.currImg, 
                      self.detectorCascade.windows[TLD_WINDOW_SIZE*idx:], 
                      True, 
                      self.detectionResult.featureVectors[self.detectorCascade.numTrees*idx:])
     
     shuffle(negativeIndices)
     for i in xrange(min(100,len(negativeIndices))):
         idx = negativeIndices[i]
         patch = NormalizedPatch()
         patch.values = tldExtractNormalizedPatchBB(self.currImg, self.detectorCascade.windows[TLD_WINDOW_SIZE*idx:])
         patches.append(patch)
     
     self.detectorCascade.nnClassifier.learn(patches)
예제 #2
0
파일: TLD.py 프로젝트: wangjuenew/pyOpenTLD
 def learn(self):
     print self.learningEnabled, self.valid, self.detectorEnabled
     if not self.learningEnabled or not self.valid or not self.detectorEnabled:
         self.learning = False
         print "not learning"
         return
     self.learning = True
     
     detectionResult = self.detectorCascade.detectionResult
     if not detectionResult.containsValidData:
         self.detectorCascade.detect(self.currImg)
     
     patch = NormalizedPatch()
     patch.values = tldExtractNormalizedPatchRect(self.currImg, self.currBB)
     #print patch.values
     print "self.detectorCascade.numWindows",
     print self.detectorCascade.numWindows
     overlap = tldOverlapRect(self.detectorCascade.windows, self.detectorCascade.numWindows, self.currBB)
     #print overlap,
     #print "overlap"
     
     positiveIndices = []
     negativeIndices = []
     negativeIndicesForNN = []
     
     for i in xrange(len(overlap)):
         if overlap[i] > 0.6:
             positiveIndices.append([i,overlap[i]])
         if overlap[i] < 0.2:
             if not self.detectorCascade.ensembleClassifier.enabled or self.detectionResult.posteriors[i] > 0.1:
                 negativeIndices.append(i)
             if not self.detectorCascade.ensembleClassifier.enabled or self.detectionResult.posteriors[i] > 0.5:
                 negativeIndicesForNN.append(i)
                 
     positiveIndices.sort(key = lambda p:p[1])
     patches = []
     patch.positive = 1
     patches.append(patch)
     
     numIterations = min(len(positiveIndices), 10)
     
     for i in xrange(len(negativeIndices)):
         idx = negativeIndices[i]
         self.detectorCascade.ensembleClassifier.learn(self.currImg, 
                         self.detectorCascade.windows[TLD_WINDOW_SIZE*idx:],
                         False, 
                         self.detectionResult.featureVectors[self.detectorCascade.numTrees*idx:])
     
     for i in xrange(numIterations):
         idx = positiveIndices[i][0]
         self.detectorCascade.ensembleClassifier.learn(self.currImg,
                         self.detectorCascade.windows[TLD_WINDOW_SIZE*idx:],
                         True,
                         self.detectionResult.featureVectors[self.detectorCascade.numTrees*idx:])
                         
     for i in xrange(len(negativeIndicesForNN)):
         idx = negativeIndiceForNN[i]
         patch = NormalizedPatch()
         patch.values = tldExtractNormalizedPatchBB(self.currImg, self.detectorCascade.windows[TLD_WINDOW_SIZE*idx:])
         patch.positive = 0
         patches.append(patch)
         
     self.detectorCascade.nnClassifier.learn(patches)