''' Extract only optimal ROC points ''' detector = easy.getDetector( strDetector ) detectorProps = easy.getDetectorProperties(detector) #specify either a desired falseAlarmRate or recall, but not both: priority = "recall" if priority=="falseAlarmRate": detectorProps.falseAlarmRate = 0.01 #x-axis print("falseAlarmRate = {0}".format(detectorProps.falseAlarmRate)) else: detectorProps.recall = 0.90 #y-axis print("recall = {0}".format(detectorProps.recall)) results = easy.detect( detector, rocZip, runset, detectorProperties = detectorProps) easy.printResults( results ) else: ############################################################### # Without background data ''' Execute jousting for generating ROC points ''' contenders = [] for nWord in list_nWord: c1 = evaluate.Contender("bowROC_oneclass_"+str(nWord)) c1.trainerString = strTrainer c1.detectorString = strDetector trainer = easy.getTrainer(c1.trainerString) trainerProps = easy.getTrainerProperties(trainer) trainerProps.props["RejectClassStrategy"] = "ignore" trainerProps.props["NumWords"] = str(nWord)
''' Easy! mini tutorial Kalman tracker via Matlab Bridge matz 10/2014 ''' import easy # # create a test set as in the Matlab sample at # http://www.mathworks.com/help/vision/ug/object-tracking.html # You need to have the Matlab vision toolbox installed. The # singleball.avi movie is here: # YourMatlabProgramPath/toolbox/vision/visiondemos/singleball.avi # You should move it to the Easy! data directory for the demo # runset = easy.createRunSet("singleball.avi") # Optionally, specify a folder that contains a sequence of the video's # frames as image files # runset = easy.createRunSet( "singleball.avi_frames" ) # # evaluate your tracking algorithm with a common match scoring method # tracker = easy.getDetector("KalmanTracker") results = easy.detect(tracker, None, runset) easy.printResults(results) easy.printLabeledTrack(results)
# Because we don't specify it, this guesses the specific Purpose that # is assigned to the labels. # Also obtain this mapping from Purpose to label name, called "classmap." rs1 = easy.createRunSet( categories1['CA_flag']+categories2['ca'], "0" ) easy.addToRunSet( rs1, categories1['KO_flag']+categories2['kr'], "1" ) easy.addToRunSet( rs1, categories1['US_flag']+categories2['us'], "2" ) print("\n=== The Corpora combined into one RunSet: ==="); easy.printRunSetInfo( rs1 ) # A runset can be used for training or for testing print("------- Bag of Words results for corporate logos: -------") detector = easy.getDetector( "BOW_Detector" ) modelfile = "detectors/bowUSKOCA.zip" results1 = easy.detect( detector, modelfile, rs1 ) print("Note that both original and found labels are printed:") easy.printResults( results1 ) # Print again, this time replacing the found labels with a double # mapping from foundLabel -> guessed Purpose -> classmap label; # Note that this fails if multiple original labels mapped to the same # Purpose. wait() print("------- Same results, but found labels replaced with guessed original labels: -------") easy.printResults( results1, foundMap=rs1['classmap'], inverseMap=True ) # Print again, this time replacing all labels with their assigned # purposes, bot original and found labels. Note the "identical label" # matches. wait() print("------- Same results, but labels replaced with purposes: -------") easy.printResults( results1, origMap=rs1['classmap'], foundMap=rs1['classmap'] )
def test_cvacdatadir(self): print("testing cvac data dir") if sys.platform == 'win32': datadir = os.getenv("CVAC_DATADIR", None) datadir = datadir.replace("/", "\\") easy.CVAC_DataDir = datadir print("Testing using back slashes") print("Using CVAC_DATADIR as " + datadir) testset = [] easy.misc.searchDir(testset, datadir + '\\testImg', recursive=True, video=False, image=True) runset = cvac.RunSet() easy.addToRunSet(runset, testset, 'pos') modelfile = 'detectors/bowUSKOCA.zip' detector = easy.getDetector("BOW_Detector") props = easy.getDetectorProperties(detector) props.verbosity = 3 results = easy.detect(detector, modelfile, runset, detectorProperties=props) easy.printResults(results) else: print("Skipping back slash test on this platform") #run it again with all forward slashes datadir = os.getenv("CVAC_DATADIR", None) datadir = datadir.replace("\\", "/") print("Testing using all forward slashes") print("Using CVAC_DATADIR as " + datadir) easy.CVAC_DataDir = datadir testset = [] easy.misc.searchDir(testset, datadir + '/testImg', recursive=True, video=False, image=True) runset = cvac.RunSet() easy.addToRunSet(runset, testset, 'pos') modelfile = 'detectors/bowUSKOCA.zip' detector = easy.getDetector("BOW_Detector") props = easy.getDetectorProperties(detector) props.verbosity = 3 results = easy.detect(detector, modelfile, runset, detectorProperties=props) easy.printResults(results) #run it for forward slashes and relative path origDir = datadir curDir = os.getcwd() curDir = curDir.replace("\\", "/") datadir = datadir.replace("\\", "/") print("using relative paths for " + curDir + " in data dir " + datadir) if datadir.startswith(curDir): datadir = datadir[len(curDir)+1:] easy.CVAC_DataDir = datadir print("Using CVAC_DataDir as " + datadir) testset = [] easy.misc.searchDir(testset, origDir + '/testImg', recursive=True, video=False, image=True) runset = cvac.RunSet() easy.addToRunSet(runset, testset, 'pos') modelfile = origDir + '/detectors/bowUSKOCA.zip' detector = easy.getDetector("BOW_Detector") props = easy.getDetectorProperties(detector) props.verbosity = 3 results = easy.detect(detector, modelfile, runset, detectorProperties=props) easy.printResults(results) else: RuntimeError("Bad datadir")
def test_cvacdatadir(self): print("testing cvac data dir") if sys.platform == 'win32': datadir = os.getenv("CVAC_DATADIR", None) datadir = datadir.replace("/", "\\") easy.CVAC_DataDir = datadir print("Testing using back slashes") print("Using CVAC_DATADIR as " + datadir) testset = [] easy.misc.searchDir(testset, datadir + '\\testImg', recursive=True, video=False, image=True) runset = cvac.RunSet() easy.addToRunSet(runset, testset, 'pos') modelfile = 'detectors/bowUSKOCA.zip' detector = easy.getDetector("BOW_Detector") props = easy.getDetectorProperties(detector) props.verbosity = 3 results = easy.detect(detector, modelfile, runset, detectorProperties=props) easy.printResults(results) else: print("Skipping back slash test on this platform") #run it again with all forward slashes datadir = os.getenv("CVAC_DATADIR", None) datadir = datadir.replace("\\", "/") print("Testing using all forward slashes") print("Using CVAC_DATADIR as " + datadir) easy.CVAC_DataDir = datadir testset = [] easy.misc.searchDir(testset, datadir + '/testImg', recursive=True, video=False, image=True) runset = cvac.RunSet() easy.addToRunSet(runset, testset, 'pos') modelfile = 'detectors/bowUSKOCA.zip' detector = easy.getDetector("BOW_Detector") props = easy.getDetectorProperties(detector) props.verbosity = 3 results = easy.detect(detector, modelfile, runset, detectorProperties=props) easy.printResults(results) #run it for forward slashes and relative path origDir = datadir curDir = os.getcwd() curDir = curDir.replace("\\", "/") datadir = datadir.replace("\\", "/") print("using relative paths for " + curDir + " in data dir " + datadir) if datadir.startswith(curDir): datadir = datadir[len(curDir) + 1:] easy.CVAC_DataDir = datadir print("Using CVAC_DataDir as " + datadir) testset = [] easy.misc.searchDir(testset, origDir + '/testImg', recursive=True, video=False, image=True) runset = cvac.RunSet() easy.addToRunSet(runset, testset, 'pos') modelfile = origDir + '/detectors/bowUSKOCA.zip' detector = easy.getDetector("BOW_Detector") props = easy.getDetectorProperties(detector) props.verbosity = 3 results = easy.detect(detector, modelfile, runset, detectorProperties=props) easy.printResults(results) else: RuntimeError("Bad datadir")
thisPath = os.path.dirname(os.path.abspath(__file__)) srcPath = os.path.abspath(thisPath+"/../../lib/python") sys.path.append(srcPath) import paths import cvac import easy # # First, a teaser for detection: # detector = easy.getDetector( "bowTest:default -p 10104" ) results = easy.detect( detector, "detectors/bowUSKOCA.zip", "testImg/TestCaFlag.jpg" ) easy.printResults( results ) # # Second, a quick way to train a detector. The resulting model # can be used in place of the detector above. # # TODO: currently breaks because Caltech101 doesn't get extracted as expected #categories, lablist = easy.getDataSet( "corpus/CvacCorpusTest" ) # categories, lablist = easy.getDataSet( "corpus/Caltech101.properties", createMirror=False ) #easy.printCategoryInfo( categories ) #runset = easy.createRunSet( categories["car_side"] ) #trainer = easy.getTrainer( "bowTrain:default -p 10103" ) #carSideModel = easy.train( trainer, runset ) # # Third, a slower walk-through of functionality that digs a bit deeper. All
# Because we don't specify it, this guesses the specific Purpose that # is assigned to the labels. # Also obtain this mapping from Purpose to label name, called "classmap." rs1 = easy.createRunSet(categories1['CA_flag'] + categories2['ca'], "0") easy.addToRunSet(rs1, categories1['KO_flag'] + categories2['kr'], "1") easy.addToRunSet(rs1, categories1['US_flag'] + categories2['us'], "2") print("\n=== The Corpora combined into one RunSet: ===") easy.printRunSetInfo(rs1) # A runset can be used for training or for testing print("------- Bag of Words results for corporate logos: -------") detector = easy.getDetector("BOW_Detector") modelfile = "detectors/bowUSKOCA.zip" results1 = easy.detect(detector, modelfile, rs1) print("Note that both original and found labels are printed:") easy.printResults(results1) # Print again, this time replacing the found labels with a double # mapping from foundLabel -> guessed Purpose -> classmap label; # Note that this fails if multiple original labels mapped to the same # Purpose. wait() print( "------- Same results, but found labels replaced with guessed original labels: -------" ) easy.printResults(results1, foundMap=rs1['classmap'], inverseMap=True) # Print again, this time replacing all labels with their assigned # purposes, bot original and found labels. Note the "identical label" # matches. wait()