Commit 94fdf161 authored by Vladimír Ulman's avatar Vladimír Ulman
Browse files

ADD: processVideo maintains given number of best results

parent 080e6b0b
Loading
Loading
Loading
Loading
+61 −6
Original line number Diff line number Diff line
@@ -2,12 +2,64 @@ import os
import subprocess
import sys

#print("output: "+sys.argv[1])
#print("video: "+sys.argv[2])
#print("timeFrom: "+sys.argv[3])
#print("timeTo: "+sys.argv[4])
#print("TRA here: "+sys.argv[5])

#----------------------------------------------------
# description of one fusion instance
class CombinationDesc:
	inputCombinationNumber = 0
	threshold = 0
	folder = ''

	def __init__(self,inC,T,path):
		self.inputCombinationNumber = inC
		self.threshold = T
		self.folder = path

	def report(self):
		print("combNo="+str(self.inputCombinationNumber)
		      +", thres="+str(self.threshold)
		      +", folder="+self.folder)

#----------------------------------------------------
# maps: SEGvalue = CombinationDesc
mapOfBest = {}
keepNBest = 30


def AddNextResult(SEG,combination):
	# add this reult
	mapOfBest[SEG] = combination

	if (len(mapOfBest) > keepNBest):
		lastKey = sorted( mapOfBest.keys() )[keepNBest]
		lastComb = mapOfBest[lastKey]

		# remove the last/worst one result from the map
		mapOfBest.pop(lastKey)

		# remove its result files
		if (os.path.isdir(lastComb.folder)):
			# remove files inside this folder
			for ff in os.listdir(lastComb.folder):
				os.remove(lastComb.folder+os.sep+ff)

			# remove the folder itself
			os.rmdir(lastComb.folder)
		else:
			print("Strange! Missing folder: "+lastComb.folder)

# example on how to operate the class and this function:
# (it records the result if among 'keepNBest' ones;
#  in any case, it maintains folders of only those in 'mapOfBest')
#
# sample call:
# AddNextResult(0.65,CombinationDesc(6,4,"/tmp/C"))
#                |                   | |
#                SEG                 | threshold used
#                                    |
#                                    combination number

#----------------------------------------------------
# the main script starts here:
if(len(sys.argv.__str__().split()) < 7):	# First parameter calls this function
	sys.exit("There should be at least 6 parameters:\n"
	        +"1. Path Fiji binary\n"
@@ -102,3 +154,6 @@ for j in range(1, 2**N): # examine combination, bit by bit from the right
		logFile = open(outFolder+"/log_3_measurementOutput.txt","w")
		logFile.write(perfMsg.stdout)
		logFile.close()

		# catalogues the result (while maintaining files of only fixed number of best results)
		AddNextResult(val, CombinationDesc(j,T,outFolder))