コード例 #1
0
ファイル: EasyTest.py プロジェクト: permikomnaskaltara/CVAC
    def isProperDetector(self,
                         configString,
                         detectorData=None,
                         detectorProperties=None):
        '''Try to create or use the specified detector.
        Create a test runset and call the detector with it.
        Check for proper handling of intentional problems.
        '''
        detector = easy.getDetector(configString)
        if not detector:
            print("cannot find or connect to detector")
            return False

        # make a runset including erroneous files
        rs = cvac.RunSet()
        file_normal = easy.getLabelable("testImg/italia.jpg")
        file_notexist = easy.getLabelable("testImg/doesnotexist.jpg")
        file_notconvertible = easy.getLabelable("testImg/notconvertible.xxx")
        easy.addToRunSet(rs, file_normal,
                         cvac.Purpose(cvac.PurposeType.UNPURPOSED, -1))
        easy.addToRunSet(rs, file_notexist,
                         cvac.Purpose(cvac.PurposeType.UNPURPOSED, -1))
        easy.addToRunSet(rs, file_notconvertible,
                         cvac.Purpose(cvac.PurposeType.UNPURPOSED, -1))
        results = easy.detect(detector, detectorData, rs, detectorProperties)

        # check for number of results: must be the same as runset length
        nRunset = 0
        for pur in rs.purposedLists:
            nRunset += len(pur.labeledArtifacts)
        if len(results) != nRunset:
            print("incorrect result set size")
            return False

        # check that the doesnotexist file caused hasLabel==False
        found = False
        for lbl in results:
            # for an erroneous file
            if lbl.original.sub == img_notexist.sub or lbl.original.sub == img_notconvertible.sub:
                for foundlbl in lbl.foundLabels:
                    if foundlbl.lab.hasLabel:
                        print(
                            "Incorrectly assigned label for an erroneous file."
                        )
                        return False
            else:  #for a normal file
                for foundlbl in lbl.foundLabels:
                    # confidence 0..1
                    if not 0.0 <= foundlbl.confidence and foundlbl.confidence <= 1.0:
                        print("Label confidence out of bounds ({0}).".format(
                            foundlbl.confidence))
                        return False
                    # check that either this was not assigned a label, or the
                    # assigned label is of proper syntax
                    if foundlbl.lab.hasLabel:
                        if not isinstance(foundlbl.lab.name, str):
                            print("Label name must be of string type.")
                            return False
        return True
コード例 #2
0
ファイル: EasyTest.py プロジェクト: AlgorithemJourney/CVAC
 def isProperDetector( self, configString, detectorData=None, detectorProperties=None ):
     '''Try to create or use the specified detector.
     Create a test runset and call the detector with it.
     Check for proper handling of intentional problems.
     '''
     detector = easy.getDetector( configString )
     if not detector:
         print("cannot find or connect to detector")
         return False
     
     # make a runset including erroneous files
     rs = cvac.RunSet()
     file_normal = easy.getLabelable( "testImg/italia.jpg" )
     file_notexist = easy.getLabelable( "testImg/doesnotexist.jpg" )
     file_notconvertible = easy.getLabelable( "testImg/notconvertible.xxx")
     easy.addToRunSet( rs, file_normal, cvac.Purpose( cvac.PurposeType.UNPURPOSED, -1 ))
     easy.addToRunSet( rs, file_notexist, cvac.Purpose( cvac.PurposeType.UNPURPOSED, -1 ))
     easy.addToRunSet( rs, file_notconvertible, cvac.Purpose( cvac.PurposeType.UNPURPOSED, -1 ) )
     results = easy.detect( detector, detectorData, rs, detectorProperties )
     
     # check for number of results: must be the same as runset length
     nRunset = 0 
     for pur in rs.purposedLists:
         nRunset += len(pur.labeledArtifacts)
     if len(results)!=nRunset:
         print("incorrect result set size")
         return False
     
     # check that the doesnotexist file caused hasLabel==False
     found=False
     for lbl in results:
         # for an erroneous file
         if lbl.original.sub==img_notexist.sub or lbl.original.sub==img_notconvertible.sub:
             for foundlbl in lbl.foundLabels:
                 if foundlbl.lab.hasLabel:
                     print("Incorrectly assigned label for an erroneous file.")
                     return False
         else:   #for a normal file
             for foundlbl in lbl.foundLabels:
                 # confidence 0..1
                 if not 0.0<=foundlbl.confidence and foundlbl.confidence<=1.0:
                     print("Label confidence out of bounds ({0}).".format(foundlbl.confidence))
                     return False
                 # check that either this was not assigned a label, or the
                 # assigned label is of proper syntax
                 if foundlbl.lab.hasLabel:
                     if not isinstance(foundlbl.lab.name, str):
                         print("Label name must be of string type.")
                         return False
     return True
コード例 #3
0
ファイル: gui.py プロジェクト: permikomnaskaltara/CVAC
 def verifyProxies(self, proxies):
     ''' Take as input dictionary of {name:proxystring} and verify that
         we can communicate with the server (by getting the detector or trainer).
         Return a dictionary with 'detector running' or 'trainer running' if running 
         and 'configured' if not. Also print now so with long config files user
         sees output.
     '''
     res = {}
     for key, value in proxies.iteritems():
         # add short timeout
         value = value + ' -t 100'
         try:
             detector = easy.getDetector(value)
             res[key] = 'detector running'
             print("{0} {1}".format(key, res[key]))
             continue
         except:
             pass
         try:
             trainer = easy.getTrainer(value)
             res[key] = 'trainer running'
             print("{0} {1}".format(key, res[key]))
             continue
         except:
             pass
         try:
             trainer = easy.getFileServer(value)
             res[key] = 'FileServer running'
             print("{0} {1}".format(key, res[key]))
             continue
         except:
             pass
         try:
             trainer = easy.getCorpusServer(value)
             res[key] = 'Corpus running'
             print("{0} {1}".format(key, res[key]))
             continue
         except:
             pass
         res[key] = 'not running'
         print("{0} {1}".format(key, res[key]))
     return res
コード例 #4
0
ファイル: detect.py プロジェクト: ericeckstrand/CVAC
'''
Easy!  mini tutorial
Apply a pre-trained detector to an image
matz 6/17/2013
'''

import easy

# obtain a reference to a Bag of Words (BOW) detector
detector = easy.getDetector( "BOW_Detector" )

# a model for distinguishing Canadian, Korean, and US flags,
# trained previously with a BOW-specific trainer and stored in a file
modelfile = "detectors/bowUSKOCA.zip"

# a test image; the location is relative to the "CVAC.DataDir"
imgfile = "testImg/TestKrFlag.jpg"

# apply the detector type, using the model and testing the imgfile
results = easy.detect( detector, modelfile, imgfile )

# you can print the results with Easy!'s pretty-printer;
# we will explain the meaning of the "unlabeled" and the number
# of the found label later.
# or you can always print variables directly (uncomment the next line):
# print("{0}".format( results ))
print("------- Bag of Words results for flags: -------")
easy.printResults( results )

# let's try a different model, pre-trained not for
# flags but for various corporate logos
コード例 #5
0
ファイル: detect.py プロジェクト: iqbalu/CVAC
'''
Easy!  mini tutorial
Apply a pre-trained detector to an image
matz 6/17/2013
'''

import easy

# obtain a reference to a Bag of Words (BOW) detector
detector = easy.getDetector( "bowTest:default -p 10104" )

# a model for distinguishing Canadian, Korean, and US flags,
# trained previously with a BOW-specific trainer and stored in a file
modelfile = "detectors/bowUSKOCA.zip"

# a test image; the location is relative to the "CVAC.DataDir"
imgfile = "testImg/TestKrFlag.jpg"

# apply the detector type, using the model and testing the imgfile
results = easy.detect( detector, modelfile, imgfile )

# you can print the results with Easy!'s pretty-printer;
# we will explain the meaning of the "unlabeled" and the number
# of the found label later.
# or you can always print variables directly (uncomment the next line):
# print("{0}".format( results ))
print("------- Bag of Words results for flags: -------")
easy.printResults( results )

# let's try a different model, pre-trained not for
# flags but for various corporate logos
コード例 #6
0
ファイル: bowDemo_ROC.py プロジェクト: AlgorithemJourney/CVAC
    for idx in optimalIndices:
        trainer = contenders[idx].getTrainer()
        detectorData = easy.train( trainer, runset, \
                                   trainerProperties=contenders[idx].trainerProps )
        rocData_optimal.append([detectorData,\
                                rocData_full[idx][0],rocData_full[idx][1],\
                                rocData_full[idx][2]])
    '''
    ROC zip
    '''
    rocZip = easy.makeROCdata(rocData_optimal)
    
    '''
    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
    '''
コード例 #7
0
ファイル: evaluation.py プロジェクト: AlgorithemJourney/CVAC
else:
    c = ev.Contender("DPM")
    c.detectorString = "DPM_Detector"
    c.detectorData = "detectors/dpmStarbucksLogo.zip"
    c.foundMap = {'Positive':easy.getPurpose('pos'), 'Negative':easy.getPurpose('neg')}
    contenders.append( c );

# OpenCVCascade, with special settings for anticipated poor performance
if (easy.getTrainer("OpenCVCascadeTrainer")==None):
    print("Cascade service(s) are insufficiently configured, skipping.")
else:
    c = ev.Contender("cascade")
    c.trainerString = "OpenCVCascadeTrainer"
    c.detectorString = "OpenCVCascadeDetector"
    # c.foundMap = {'any':easy.getPurpose('pos')}
    c.foundMap = {'positive':posPurpose, 'negative':negPurpose}
    detector = easy.getDetector(c.detectorString)
    detectorProps = easy.getDetectorProperties(detector)
    c.detectorProps = detectorProps;
    c.detectorProps.props["maxRectangles"] = "200"
    c.detectorProps.minNeighbors = 0; # This prevents hang up in evaluator when training has too few samples
    contenders.append( c );

runset = easy.createRunSet( "trainImg/kr", "pos" )
easy.addToRunSet( runset, "trainImg/ca", "neg" )
easy.printRunSetInfo( runset, printArtifacts=False, printLabels=True )

perfdata = ev.joust( contenders, runset, folds=3 )
ev.printEvaluationResults(perfdata[0])

コード例 #8
0
ファイル: evaluate.py プロジェクト: permikomnaskaltara/CVAC
 def getDetector( self ):
     if not self.detector:
         self.detector = easy.getDetector( self.detectorString )
     return self.detector
コード例 #9
0
    c.detectorData = "detectors/dpmStarbucksLogo.zip"
    c.foundMap = {
        'Positive': easy.getPurpose('pos'),
        'Negative': easy.getPurpose('neg')
    }
    contenders.append(c)

# OpenCVCascade, with special settings for anticipated poor performance
if (easy.getTrainer("OpenCVCascadeTrainer") == None):
    print("Cascade service(s) are insufficiently configured, skipping.")
else:
    c = ev.Contender("cascade")
    c.trainerString = "OpenCVCascadeTrainer"
    c.detectorString = "OpenCVCascadeDetector"
    # c.foundMap = {'any':easy.getPurpose('pos')}
    c.foundMap = {'positive': posPurpose, 'negative': negPurpose}
    detector = easy.getDetector(c.detectorString)
    detectorProps = easy.getDetectorProperties(detector)
    c.detectorProps = detectorProps
    c.detectorProps.props["maxRectangles"] = "200"
    c.detectorProps.minNeighbors = 0
    # This prevents hang up in evaluator when training has too few samples
    contenders.append(c)

runset = easy.createRunSet("trainImg/kr", "pos")
easy.addToRunSet(runset, "trainImg/ca", "neg")
easy.printRunSetInfo(runset, printArtifacts=False, printLabels=True)

perfdata = ev.joust(contenders, runset, folds=3)
ev.printEvaluationResults(perfdata[0])
コード例 #10
0
#
# Make sure all files in the RunSet are available on the remote site;
# it is the client's responsibility to upload them if not.
# The putResult contains information about which files were actually transferred.
#
print("------- Remote detection, local result display: -------")
fileserver = easy.getFileServer("PythonFileService:default -p 10111 " + host)
putResult = easy.putAllFiles(fileserver, rs1)
modelfile = "detectors/haarcascade_frontalface_alt.xml"
if not fileserver.exists(easy.getCvacPath(modelfile)):
    easy.putFile(fileserver, easy.getCvacPath(modelfile))

#
# detect remotely: note the host specification
#
detector = easy.getDetector("OpenCVCascadeDetector:default -p 10102 " + host)
results = easy.detect(detector, modelfile, rs1)
easy.printResults(results)

#
# Example 2:
# Train on a remote machine, obtain the model file, and test locally.
# Assume the files are on the remote machine, or transfer with putAllFiles.
# If no local services are installed, this will be skipped.
#
print("------- Remote training, local detection: -------")
try:
    detector = easy.getDetector(
        "BOW_Detector:default -p 10104")  # local service
    trainer = easy.getTrainer("BOW_Trainer:default -p 10103 " + host)  # remote
    trainset = easy.createRunSet("trainImg")
コード例 #11
0
Note that the particular detectors do not match the data, so the
code is illustrative, but the results are not very interesting.
'''

import easy, cvac
import easy.evaluate as ev

runset = cvac.RunSet()
easy.addToRunSet(runset, "trainImg/ca", "neg")
easy.addToRunSet(runset, "trainImg/kr", "pos")
#easy.printRunSetInfo( runset, printArtifacts=False, printLabels=True )

contenders = []

# Bag of Words
if (easy.getDetector("BOW_Detector") == None):
    print("BOW detector service is insufficiently configured, skipping.")
else:
    c = ev.Contender("BOW")
    c.detectorString = "BOW_Detector"
    c.detectorData = "detectors/bowUSKOCA.zip"
    c.foundMap = {
        'kr': easy.getPurpose('pos'),
        'ca': easy.getPurpose('neg'),
        'us': easy.getPurpose('neg'),
        'unlabeled': easy.getPurpose('neg')
    }
    contenders.append(c)

# OpenCV Cascade detector
if (easy.getDetector("OpenCVCascadeDetector") == None):
コード例 #12
0
ファイル: track_kalman.py プロジェクト: sgsun9/matlab-bridge
'''
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
#
runset = easy.createRunSet( "singleball.avi" )

#
# evaluate your tracking algorithm with a common match scoring method
#
tracker = easy.getDetector( "KalmanTracker:default -p 20133" )
results = easy.detect( tracker, None, runset )
easy.printResults( results )
コード例 #13
0
Note that the particular detectors do not match the data, so the
code is illustrative, but the results are not very interesting.
'''

import easy, cvac
import easy.evaluate as ev

runset = cvac.RunSet()
easy.addToRunSet( runset, "trainImg/ca", "neg" )
easy.addToRunSet( runset, "trainImg/kr", "pos" )
#easy.printRunSetInfo( runset, printArtifacts=False, printLabels=True )

contenders = []

# Bag of Words
if (easy.getDetector("BOW_Detector")==None):
    print("BOW detector service is insufficiently configured, skipping.")
else:
    c = ev.Contender("BOW")
    c.detectorString = "BOW_Detector"
    c.detectorData = "detectors/bowUSKOCA.zip"
    c.foundMap = { 'kr':easy.getPurpose('pos'),
                   'ca':easy.getPurpose('neg'),
                   'us':easy.getPurpose('neg'),
                   'unlabeled':easy.getPurpose('neg')}
    contenders.append( c );

# OpenCV Cascade detector
if (easy.getDetector("OpenCVCascadeDetector")==None):
    print("OpenCVCascadeDetector service is insufficiently configured, skipping.")
else:
コード例 #14
0
# Ex. for image files in a directory 
tFileSuffixes = ["jpg","bmp"]
directory_images = cvac.PurposedDirectory(cvac.Purpose(cvac.PurposeType.MULTICLASS,1),
                                          cvac.DirectoryPath("testImg"),
                                          tFileSuffixes,
                                          1)
runset.purposedLists.append(directory_images)
 

#===============================================================================
# # If you have video files, you may comment out this part for testing the video files
# # Ex. for video files in a directory 
# tFileSuffixes = ["mpg","mpeg","avi"]
# directory_videos = cvac.PurposedDirectory(cvac.Purpose(cvac.PurposeType.MULTICLASS,1),
#                                           cvac.DirectoryPath("trainVideo"),
#                                           tFileSuffixes,
#                                           1)
# runset.purposedLists.append(directory_videos)
#===============================================================================
 
host = "-h localhost"
detector = easy.getDetector( "RSItrTest_Detector:default -p 10109 " + host )
modelfile = ''  #empty detectorData only for testing
results = easy.detect( detector, modelfile, runset )
#results = easy.detect( detector, trainedModel, runset )
#easy.printResults( results, foundMap=classmap )
easy.printResults( results)

quit()
コード例 #15
0
# pick a subset: all license plates
license_plates = categories['license plate']
print("There are {0} license plate labels.".format(len(license_plates)))

# another subset: all labels starting with "car"
cars = []
for key in categories.keys():
    if key.startswith("car"):
        cars.append(categories[key])
print("There are {0} car-related labels.".format(len(cars)))

# Note that Labels are cached in the CorpusServer, but the corpus currently
# needs to re-mirror if the CorpusServer is restarted because Labels are
# not stored to disk.  Images are stored to disk.

quit()  # done for now

# Train a detector on license plates
trainer = easy.getTrainer("BOW_Trainer:default -p 10103 ")
trainset = easy.createRunSet(license_plates, "pos")
easy.printRunSetInfo(trainset)
licenseplateModel = easy.train(trainer, trainset)

# test the license plate detector on the known locations of cars;
# this will only try to detect within the boundaries of cars.
testset = easy.createRunSet(cars, "unpurposed")
detector = easy.getDetector("BOW_Detector:default -p 10104")
results = easy.detect(detector, licenseplateModel, testset)

printResults(results)
コード例 #16
0
    0, 0)
singleImages.labeledArtifacts.append(cvac.Labelable(0, tlab, tsub))

# Ex. for image files in a directory
tFileSuffixes = ["jpg", "bmp"]
directory_images = cvac.PurposedDirectory(
    cvac.Purpose(cvac.PurposeType.MULTICLASS, 1),
    cvac.DirectoryPath("testImg"), tFileSuffixes, 1)
runset.purposedLists.append(directory_images)

#===============================================================================
# # If you have video files, you may comment out this part for testing the video files
# # Ex. for video files in a directory
# tFileSuffixes = ["mpg","mpeg","avi"]
# directory_videos = cvac.PurposedDirectory(cvac.Purpose(cvac.PurposeType.MULTICLASS,1),
#                                           cvac.DirectoryPath("trainVideo"),
#                                           tFileSuffixes,
#                                           1)
# runset.purposedLists.append(directory_videos)
#===============================================================================

host = "-h localhost"
detector = easy.getDetector("RSItrTest_Detector:default -p 10109 " + host)
modelfile = ''  #empty detectorData only for testing
results = easy.detect(detector, modelfile, runset)
#results = easy.detect( detector, trainedModel, runset )
#easy.printResults( results, foundMap=classmap )
easy.printResults(results)

quit()
コード例 #17
0
ファイル: EasyTest.py プロジェクト: AlgorithemJourney/CVAC
    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")
コード例 #18
0
ファイル: EasyTest.py プロジェクト: permikomnaskaltara/CVAC
    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")
コード例 #19
0
ファイル: labelme_corpus.py プロジェクト: ericeckstrand/CVAC
# pick a subset: all license plates
license_plates = categories['license plate']
print("There are {0} license plate labels.".format( len(license_plates) ))

# another subset: all labels starting with "car"
cars = []
for key in categories.keys():
    if key.startswith("car"):
        cars.append( categories[key] )
print("There are {0} car-related labels.".format( len(cars) ))

# Note that Labels are cached in the CorpusServer, but the corpus currently
# needs to re-mirror if the CorpusServer is restarted because Labels are
# not stored to disk.  Images are stored to disk.

quit()  # done for now

# Train a detector on license plates
trainer = easy.getTrainer( "BOW_Trainer:default -p 10103 ")
trainset = easy.createRunSet( license_plates, "pos" )
easy.printRunSetInfo( trainset )
licenseplateModel = easy.train( trainer, trainset )

# test the license plate detector on the known locations of cars;
# this will only try to detect within the boundaries of cars.
testset = easy.createRunSet( cars, "unpurposed" )
detector = easy.getDetector( "BOW_Detector:default -p 10104" )
results = easy.detect( detector, licenseplateModel, testset )

printResults( results )
コード例 #20
0
'''
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 )
コード例 #21
0
ファイル: training.py プロジェクト: permikomnaskaltara/CVAC
#
# Connect to the trainer for a Bag of Words algorithm, then
# train with the given runset
#
print("starting training, this might take a few minutes...")
trainer = easy.getTrainer("BOW_Trainer")
trainedModel = easy.train(trainer, trainset)

#
# Display information about the file in which the model is stored;
# this is generally no concern to algorithm users and only of
# interest to algorithm developers since it is algorithm-specific
#
zipfname = easy.getFSPath(trainedModel)
print("{0}".format(zipfname))
zipf = zipfile.ZipFile(zipfname)
print("Training model stored in file {0}".format(zipfname))
# print("file contents:\n{0}".format(zipf.namelist()))

#
# test the trained model on a separate set of images
#
print("==== Test runset: ====")
testset = easy.createRunSet("testImg")
easy.printRunSetInfo(testset, printLabels=True)
detector = easy.getDetector("BOW_Detector")
results = easy.detect(detector, trainedModel, testset)
print("==== Results: ====")
easy.printResults(results)
コード例 #22
0
ファイル: full_image_corpus.py プロジェクト: iqbalu/CVAC
# Note how both corpora contain flag images, but they have different
# labels.  To use them for evaluation, let's assign the same purpose
# to syntactically different but semantically identical labels.
# 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( "bowTest:default -p 10104" )
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"
コード例 #23
0
ファイル: remote_services.py プロジェクト: iqbalu/CVAC
#
# Make sure all files in the RunSet are available on the remote site;
# it is the client's responsibility to upload them if not.
# The putResult contains information about which files were actually transferred.
#
fileserver = easy.getFileServer( "FileService:default -p 10110 " + host )
putResult = easy.putAllFiles( fileserver, rs1 )
modelfile = "detectors/haarcascade_frontalface_alt.xml"
if not fileserver.exists( easy.getCvacPath(modelfile) ):
    easy.putFile( fileserver, easy.getCvacPath(modelfile) )

#
# detect remotely: note the host specification
#
print("------- Remote detection, local result display: -------")
detector = easy.getDetector( "OpenCVCascadeDetector:default -p 10102 "+host )
results = easy.detect( detector, modelfile, rs1 )
easy.printResults( results )

#
# Example 2:
# Train on a remote machine, obtain the model file, and test locally.
# Assume the files are on the remote machine, or transfer with putAllFiles.
#
trainer = easy.getTrainer( "bowTrain:default -p 10103 "+ host) # remote
trainset = easy.createRunSet( "trainImg" );
trainedModel = easy.train( trainer, trainset )
easy.getFile( fileserver, trainedModel.file )  # downloads the model from remote
print("{0}".format(trainedModel))
detector = easy.getDetector( "bowTest:default -p 10104" ) # local service
testset = easy.createRunSet("testImg","UNPURPOSED"  )
コード例 #24
0
'''
Easy!  mini tutorial
Apply a pre-trained detector to an image
matz 6/17/2013
'''

import easy

# obtain a reference to a Bag of Words (BOW) detector
detector = easy.getDetector( "BOW_Detector" )

# a model for distinguishing Canadian, Korean, and US flags,
# trained previously with a BOW-specific trainer and stored in a file
modelfile = "detectors/bowUSKOCA.zip"

# a test image; the location is relative to the "CVAC.DataDir"
imgfile = "testImg/TestKrFlag.jpg"

# apply the detector type, using the model and testing the imgfile
results = easy.detect( detector, modelfile, imgfile )

# you can print the results with Easy!'s pretty-printer;
# we will explain the meaning of the "unlabeled" and the number
# of the found label later.
# or you can always print variables directly (uncomment the next line):
# print("{0}".format( results ))
print("------- Bag of Words results for flags: -------")
easy.printResults( results )

# let's try a different model, pre-trained not for
# flags but for various corporate logos
コード例 #25
0
# Note how both corpora contain flag images, but they have different
# labels.  To use them for evaluation, let's assign the same purpose
# to syntactically different but semantically identical labels.
# 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"
コード例 #26
0
'''
Easy!  Demo for struck tracker.  We run the demo twice.  The first time is 
with just displaying the results at the end of the run.  This is the
simplest way to run the demo.  In the next run we create a callback handler
that takes the output from the tracker and displays the results on the images.
'''
import Ice
import easy
import cvac
import sys
import thread
import cv2

# obtain a reference to Struck Tracker detector
detector = easy.getDetector( "StruckTracker" )

# a test video; the location is relative to the "CVAC.DataDir"
vfile = "tracks/VTS_01_2.mpg"
runset = cvac.RunSet()

# The tracker needs a labeled location that defines the location
# within the first frame of the video  of the item we want to track.
# In this we define a bounding box around the toy soldiers initial location.
vlab = easy.getLabelable( vfile, labelText="car" )
labloc = cvac.BBox(290, 280,60,30)
lab = cvac.LabeledLocation()
lab.loc = labloc
lab.confidence = 0
lab.sub = vlab.sub
easy.addToRunSet(runset, lab, easy.getPurpose('pos'))
# Setting the verbosity level gives us some feedback while the tracking is done.
コード例 #27
0
'''
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)
コード例 #28
0
    rocData_optimal = []
    for idx in optimalIndices:
        trainer = contenders[idx].getTrainer()
        detectorData = easy.train( trainer, runset, \
                                   trainerProperties=contenders[idx].trainerProps )
        rocData_optimal.append([detectorData,\
                                rocData_full[idx][0],rocData_full[idx][1],\
                                rocData_full[idx][2]])
    '''
    ROC zip
    '''
    rocZip = easy.makeROCdata(rocData_optimal)
    '''
    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: