Exemple #1
0
    def xtest_createLocalMirror(self):
        print('createLocalMirror')
        dataRoot = cvac.DirectoryPath( "corpus" );
        corpusConfigFile = cvac.FilePath( dataRoot, "CvacCorpusTest.properties" )
        corpus = self.cs.openCorpus( corpusConfigFile )
        if not corpus:
            raise RuntimeError("could not open corpus from config file at '"
                               +dataRoot.relativePath+"/"+corpusConfigFile.filename+"'")

        adapter = self.ic.createObjectAdapter("")
        ident = Ice.Identity()
        ident.name = IcePy.generateUUID()
        ident.category = ""
#        adapter.add( self, ident )
        adapter.add( TestCorpusCallback(), ident )
        adapter.activate()
#        adapter = self.ic.createObjectAdapter("CorpusServer")
#        adapter.add( TestCorpusCallback(), ic.stringToIdentity("CorpusServer:default -p 10011"))
#        adapter.activate()
#        receiver = cvac.CorpusCallbackPrx.uncheckedCast(
#            adapter.createProxy( self.ic.stringToIdentity("callbackReceiver")))
        
        self.cs.createLocalMirror( corpus, ident )
        if not self.cs.localMirrorExists( corpus ):
            raise RuntimeError( "could not create local mirror for",
                                corpusConfigFile.filename )
Exemple #2
0
def parseFolder(localDir, lmAnnotations, lmImages, lmFolder, CVAC_DataDir):
    '''Parse all XML files in the specified folder and
    return all found labels.
    (this currently only works locally on the file system)
    lmAnnotations is equivalent to HOMEANNOTATIONS in the Matlab LabelMeToolbox:
    it is the path to the Annotation root folder on the file system, 
    or the LabelMe server's Annotation folder http address.
    lmFolder is the equivalent to HOMEIMAGESin the Matlab LabelMeToolbox.
    Both lmAnnotations and lmFolder are assumed to be in localDir
    '''

    labels = []
    fsAnnotPath = os.path.join(CVAC_DataDir, localDir, lmAnnotations, lmFolder) \
                  + '/*.xml'

    for fsAnnotFullpath in glob.glob(fsAnnotPath):
        # parse the XML file on the file system
        tree = et.parse(fsAnnotFullpath)
        root = tree.getroot()
        # find out image name, prepend image path
        cvacDir = cvac.DirectoryPath(os.path.join(localDir, lmImages,
                                                  lmFolder))
        felem = root.find('filename')
        if felem == None:
            print('Annotation file ' + fsAnnotFullpath + \
                  ' does not have filename element')
            continue
        else:
            imgFname = felem.text.encode(
                'utf-8').strip()  # strip any leading or trailing white space

        cvacFp = cvac.FilePath(cvacDir, imgFname)
        substrate = cvac.Substrate(True, False, cvacFp, -1, -1)
        labels = labels + parseLabeledObjects(root, substrate)
    return labels
Exemple #3
0
 def xtest_openCorpus(self):
     print('openCorpus')
     dataRoot = cvac.DirectoryPath( "corpus" );
     corpusConfigFile = cvac.FilePath( dataRoot, "Caltech101.properties" )
     corpus2 = self.cs.openCorpus( corpusConfigFile )
     if not corpus2:
         raise RuntimeError("could not open corpus from config file at '"
                            +dataRoot.relativePath+"/"+corpusConfigFile.filename+"'")
Exemple #4
0
    def xtest_getDataSetRequiresLocalMirror(self):
        print('getDataSetRequiresLocalMirror')
        # try with one where we do expect it:
        dataRoot = cvac.DirectoryPath( "corpus" );
        corpusConfigFile1 = cvac.FilePath( dataRoot, "Caltech101.properties" )
        corpus1 = self.cs.openCorpus( corpusConfigFile1 )
        required = self.cs.getDataSetRequiresLocalMirror( corpus1 )
        if not required:
            raise RuntimeError("Corpus", corpusConfigFile1.filename,
                               "is expected to require a local mirror for data access, but it does not")

        # now try with one that should not require it
        corpusTestDir = cvac.DirectoryPath( "corpusTestDir" );
        corpus2 = self.cs.createCorpus( corpusTestDir )
        required = self.cs.getDataSetRequiresLocalMirror( corpus2 )
        if required:
            raise RuntimeError("Corpus at", corpusTestDir.relativePath,
                               "is expected to not require a local mirror for data access, but it does")
Exemple #5
0
 def xtest_createCorpus(self):
     print('createCorpus')
     corpusTestDir = cvac.DirectoryPath( "easyTestData" );
     corpus3 = self.cs.createCorpus( corpusTestDir )
     if not corpus3:
         raise RuntimeError("could not create corpus from path '"
                            +corpusTestDir.relativePath+"/"+corpusTestDir+"'")
     labels = self.cs.getDataSet(corpus3)
     if not labels or len(labels) == 0:
         raise RuntimeError("no labels back from createCorpus(easyTestData)")
 def test_exists(self):
     testDir = cvac.DirectoryPath("testImg")
     existingFile = cvac.FilePath(testDir, "TestUsFlag.jpg")
     noFile = cvac.FilePath(testDir, "NonExistentFile.jpg")
     if not self.fs.exists(existingFile):
         raise RuntimeError("This file should exist: " +
                            self.getFSPath(existingFile))
     if self.fs.exists(noFile):
         raise RuntimeError("This file should not exist: " +
                            self.getFSPath(noFile))
Exemple #7
0
def addFileToLabelableSet(lset, ldir, lfile, video=True, image=True):
    isVideo = False
    isImage = False
    if '.' not in lfile:
        return  # No extension so don't add it
    #see if we have a video or image file if not just skip it
    name, ext = lfile.rsplit('.', 1)
    extLower = ext.lower()
    if extLower in getVideoExtensions():
        isVideo = True
    elif extLower in getImageExtensions():
        isImage = True
    else:
        return
    if isVideo and video == False:
        return
    if isImage and image == False:
        return
    # strip off cvac data dir
    ldir = stripCVAC_DataDir(ldir)

    props = {}
    # last directory is the label name
    ldir = os.path.normpath(ldir)
    ldir = ldir.rstrip('\\')
    ldir = ldir.rstrip('/')
    labelName = os.path.basename(ldir)
    # FIll in props with each directory
    nextDir = os.path.dirname(ldir)
    while nextDir != None and nextDir != "":
        nextProp = os.path.basename(nextDir)
        if nextProp != None and nextProp != "":
            props[nextProp] = ""
        nextd = os.path.dirname(nextDir)
        if nextd == nextDir:
            break
        else:
            nextDir = nextd
    dirpath = cvac.DirectoryPath(ldir)
    fpath = cvac.FilePath(dirpath, lfile)
    if isVideo == True:
        sub = cvac.VideoSubstrate()
        sub.width = 0
        sub.height = 0
        sub.videopath = fpath
    else:
        sub = cvac.ImageSubstrate()
        sub.width = 0
        sub.height = 0
        sub.path = fpath
    lab = cvac.Label(True, labelName, props, cvac.Semantics(""))
    lset.append(cvac.Labelable(0.0, lab, sub))
Exemple #8
0
 def xtest_localMirrorExists(self):
     print('localMirrorExists')
     # try with one where we expect the mirror to exist already,
     # mainly because test_createLocalMirror has been called already
     dataRoot = cvac.DirectoryPath( "corpus" );
     corpusConfigFile = cvac.FilePath( dataRoot, "CvacCorpusTest.properties" )
     corpus = self.cs.openCorpus( corpusConfigFile )
     if not corpus:
         raise RuntimeError("could not open corpus from config file at '"
                            +dataRoot.relativePath+"/"+corpusConfigFile.filename+"'")
     exists = self.cs.localMirrorExists( corpus )
     if not exists:
         raise RuntimeError("expected corpus to already have a local mirror")
    def test_putFile(self):
        print('putFile')
        # read the bytes from TestKrFlag.jpg
        testDir = cvac.DirectoryPath("testImg")
        origFilePath = cvac.FilePath(testDir, "TestKrFlag.jpg")
        origFS = self.dataDir + "/" + self.getFSPath(origFilePath)
        if not os.path.exists(origFS):
            raise RuntimeError("Cannot obtain FS path to original file,",
                               "see comments. file: " + origFS)
        forig = open(origFS, 'rb')
        bytes = bytearray(forig.read())

        # "put" the file's bytes as a different file which must not exist,
        # and compare the result via file system access
        putFilePath = cvac.FilePath(testDir, "TargetFilename.jpg")
        putFS = self.dataDir + "/" + self.getFSPath(putFilePath)
        try:
            self.fs.putFile(putFilePath, bytes)
        except cvac.FileServiceException as ex:
            print(
                "if you do not have 'put' permissions, " +
                "was the file deleted properly in a prior test run?\nfile: " +
                putFS)
            raise ex
        forig.close()
        if not os.path.exists(putFS):
            raise RuntimeError(
                "Cannot obtain path to the just-'put' file",
                "on the file system, see comments. file: " + putFS)
        if not self.filesAreEqual(origFS, putFS):
            raise RuntimeError("file was not 'put' correctly to " + putFS)

        # try to "put" an existing file; this should fail
        permitted = True
        try:
            self.fs.putFile(origFilePath, bytes)
        except cvac.FileServiceException:
            permitted = False
        if permitted:
            raise RuntimeError("should not have permission to put this file")

        # delete the "put" file on the server
        print('deleteFile')
        self.fs.deleteFile(putFilePath)
        if os.path.exists(putFS):
            raise RuntimeError("FileServer did not delete 'put' file: " +
                               putFS)
def parseSamples( root, CVAC_DataDir ):
    ''' for each catalog file, 
    collect all samples including videos files and their annotation files
    then, each segment information is converted to cvac.LabeledVideoSegment    
    '''
    dirCommon = ''
    dir = root.find('directory')
    if dir != None:
        dirCommon = dir.text    
    
    labels = []
    for sample in root.findall('sample'):
        media = sample.find('media')
        mediaLocal = media.find('local')
        mediaDir = dirCommon        
        if mediaLocal.find('relativePath') != None:
            mediaDir=os.path.join(mediaDir,mediaLocal.find('relativePath').text)
        mediaName = mediaLocal.find('filename').text
        mediaFilepath = cvac.FilePath(cvac.DirectoryPath(mediaDir),mediaName)
        
        annot = sample.find('annotation')
        annotLocal = annot.find('local')
        annotDir = dirCommon        
        if annotLocal.find('relativePath') != None:
            annotDir=os.path.join(annotDir,annotLocal.find('relativePath').text)
        annotName = annotLocal.find('filename').text
        
        
        annotObj = TRECVIDAnnotaitonParser(os.path.join(CVAC_DataDir,\
                                                        annotDir,annotName))
        #print(os.path.join(CVAC_DataDir,annotDir,annotName))
        bndFrms = annotObj.getCutAll() 
        #annotObj.getCutHard() for HardCuts
        #annotObj.getCutSoft() for SoftCuts        
        for frm in bndFrms:
            label = cvac.LabeledVideoSegment()
            label.confidence = 1.0
            label.lab = cvac.Label(True,os.path.join(mediaDir,mediaName))        
            label.sub = cvac.Substrate(False,True,mediaFilepath,long(-1),long(-1))
            label.start = cvac.VideoSeekTime(long(frm[0]),long(-1))
            label.last = cvac.VideoSeekTime(long(frm[1]),long(-1))
            label.startAfterTx = cvac.VideoSeekTime(long(-1),long(-1))
            label.lastBeforeTx = cvac.VideoSeekTime(long(-1),long(-1))
            label.loc = cvac.Location()
            labels = labels + [label]
            
    return labels
Exemple #11
0
    def xtest_getDataSet(self):
        print('getDataSet')
        dataRoot = cvac.DirectoryPath( "corpus" );
        corpusConfigFile1 = cvac.FilePath( dataRoot, "CvacCorpusTest.properties" )
        corpus1 = self.cs.openCorpus( corpusConfigFile1 )
        if not corpus1:
            raise RuntimeError("Could not open CvacCorpusTest corpus")
        try:
            labels = self.cs.getDataSet( corpus1 )
            raise RuntimeError("the CorpusServer should not be able to get the data",
                               "without creating a local mirror")
        except RuntimeError:
            # we expect this error: "could not obtain labels from Corpus..."
            pass

        # this time we expect to be able to access the labels
        corpusConfigFile2 = cvac.FilePath( dataRoot, "CvacCorpusTest.properties" )
        corpus2 = self.cs.openCorpus( corpusConfigFile2 )
        labels = self.cs.getDataSet( corpus2 )
        if not labels:
            raise RuntimeError("could not obtain labels from Corpus '"
                               +corpus2.name+"'")
Exemple #12
0
    def xtest_openCorpusLabelMe(self):
        print('openCorpusLabelMe')
        dataRoot = cvac.DirectoryPath( "corpus" );
        corpusConfigFile = cvac.FilePath( dataRoot, "LabelMeCarsTest.properties" )
#        corpusConfigFile = cvac.FilePath( dataRoot, "NpsVisionLabelMe.properties" )
        corpus = self.cs.openCorpus( corpusConfigFile )
        if not corpus:
            raise RuntimeError("could not open corpus from config file at '"
                               +dataRoot.relativePath+"/"+corpusConfigFile.filename+"'"+"\n"
                               +"Did you build CVAC with BUILD_LABELME_CORPUS=ON?")
        adapter = self.ic.createObjectAdapter("")
        ident = Ice.Identity()
        ident.name = IcePy.generateUUID()
        ident.category = ""
        adapter.add( TestCorpusCallback(), ident )
        adapter.activate()
        
        self.cs.createLocalMirror( corpus, ident )

        labels = self.cs.getDataSet( corpus )
        if not labels:
            raise RuntimeError("could not obtain labels from Corpus '"
                               +corpus.name+"'")
Exemple #13
0
srcPath = os.path.abspath(thisPath + "/../../lib/python")
sys.path.append(srcPath)

import cvac
import easy

runset = cvac.RunSet([])

singleImages = cvac.PurposedLabelableSeq(
    cvac.Purpose(cvac.PurposeType.MULTICLASS, 1))
singleImages.labeledArtifacts = []
runset.purposedLists.append(singleImages)

tlab = cvac.Label(False, '')
tsub = cvac.Substrate(
    True, False, cvac.FilePath(cvac.DirectoryPath("trainImg/us"), "US001.jpg"),
    0, 0)
singleImages.labeledArtifacts.append(cvac.Labelable(0, tlab, tsub))

tlab = cvac.Label(False, '')
tsub = cvac.Substrate(
    True, False, cvac.FilePath(cvac.DirectoryPath("trainImg/kr"), "Kr001.jpg"),
    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)
Exemple #14
0
def to_CVAC_ResultSet(protobuf_matlab_bridge_msg):
    rslt_set = []
    for ridx, rslt in enumerate(protobuf_matlab_bridge_msg.res.results.rslt):
        # set original label for each result
        '''
          Note: All the fields should be checked with HasField, but for some reason
          some of the field checks fail with an exception with HasField.  But in the
          case of vidSub and imgSub, if we just check for field not null it does not work
          and we have to use HasField.
        '''
        if (protobuf_matlab_bridge_msg.res.results.rslt[ridx].original.
                HasField('vidSub')):  # VideoSubstrate
            # todo: copy the framepaths
            opath = cvac.FilePath(
                directory=cvac.DirectoryPath(
                    relativePath=protobuf_matlab_bridge_msg.res.results.
                    rslt[ridx].original.vidSub.videopath.directory.
                    relativePath.encode('utf-8')),
                filename=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                original.vidSub.videopath.filename.encode('utf-8'))
            osub = cvac.VideoSubstrate(
                videopath=opath,
                width=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                original.vidSub.width,
                height=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                original.vidSub.height)
        elif (protobuf_matlab_bridge_msg.res.results.rslt[ridx].original.
              HasField('imgSub')):  # ImageSubstrate
            opath = cvac.FilePath(directory=cvac.DirectoryPath(
                relativePath=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                original.imgSub.path.directory.relativePath.encode('utf-8')),
                                  filename=protobuf_matlab_bridge_msg.res.
                                  results.rslt[ridx].original.imgSub.path.
                                  filename.encode('utf-8'))
            osub = cvac.ImageSubstrate(
                path=opath,
                width=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                original.imgSub.width,
                height=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                original.imgSub.height)
        else:
            print "error: unsupported Labelable (original) substrate"
        olab = cvac.Label(
            hasLabel=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
            original.lab.hasLabel,
            name=protobuf_matlab_bridge_msg.res.results.rslt[ridx].original.
            lab.name.encode('utf-8'),
            semantix=cvac.Semantics(url=protobuf_matlab_bridge_msg.res.results.
                                    rslt[ridx].original.lab.semantix.url))
        olabelable = cvac.Labelable(confidence=protobuf_matlab_bridge_msg.res.
                                    results.rslt[ridx].original.confidence,
                                    lab=olab,
                                    sub=osub)

        # set found label for each result
        #   Labelable case
        flabelable = []

        if (protobuf_matlab_bridge_msg.res.results.rslt[ridx].foundLabels.
                labelable):
            if (protobuf_matlab_bridge_msg.res.results.rslt[ridx].foundLabels.
                    labelable[0].vidSub):  # VideoSubstrate
                fpath = cvac.FilePath(
                    directory=cvac.DirectoryPath(
                        relativePath=protobuf_matlab_bridge_msg.res.results.
                        rslt[ridx].foundLabels.labelable[0].vidSub.videopath.
                        directory.relativePath.encode('utf-8')),
                    filename=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.vidSub.videopath.filename.encode('utf-8'))
                fsub = cvac.VideoSubstrate(
                    videopath=fpath,
                    width=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.vidSub.width,
                    height=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.vidSub.height)
            elif (protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                  foundLabels.labelable[0].imgSub):  # ImageSubstrate
                fpath = cvac.FilePath(
                    directory=cvac.DirectoryPath(
                        relativePath=protobuf_matlab_bridge_msg.res.results.
                        rslt[ridx].foundLabels.labelable[0].imgSub.path.
                        directory.relativePath.encode('utf-8')),
                    filename=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.imgSub.path.filename.encode('utf-8'))
                fsub = cvac.ImageSubstrate(
                    path=fpath,
                    width=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.imgSub.width,
                    height=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.imgSub.height)
            else:
                print "error: unsupported Labelable (found) substrate"
            flab = cvac.Label(
                hasLabel=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                foundLabels.labelable[0].lab.hasLabel,
                name=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                foundLabels.labelable[0].lab.name.encode('utf-8'),
                semantix=cvac.Semantics(
                    url=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    foundLabels.labelable[0].lab.semantix.url))
            if (protobuf_matlab_bridge_msg.res.results.rslt[ridx].foundLabels.
                    labelable[0].vidSub):  # VideoSubstrate
                flabelable = cvac.Labelable(
                    confidence=protobuf_matlab_bridge_msg.res.results.
                    rslt[ridx].foundLabels.labelable[0].confidence,
                    lab=flab,
                    sub=fsub)

            else:  # ImageSubstrate
                flabelable = cvac.Labelable(
                    confidence=protobuf_matlab_bridge_msg.res.results.
                    rslt[ridx].foundLabels.labelable[0].confidence,
                    lab=flab,
                    sub=fsub)

        #   LabeledTrack case
        ftlabelable = []  # If we have video tracks
        locLabelable = []  # If we have location Labelabables
        if (protobuf_matlab_bridge_msg.res.results.rslt[ridx].foundLabels.
                labeledTrack):

            if (protobuf_matlab_bridge_msg.res.results.rslt[ridx].foundLabels.
                    labeledTrack[0].vidSub):  # VideoSubstrate
                ftpath = cvac.FilePath(
                    directory=cvac.DirectoryPath(
                        relativePath=protobuf_matlab_bridge_msg.res.results.
                        rslt[ridx].foundLabels.labeledTrack[0].vidSub.
                        videopath.directory.relativePath.encode('utf-8')),
                    filename=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.vidSub.videopath.filename.encode('utf-8'))
                ftsub = cvac.VideoSubstrate(
                    videopath=ftpath,
                    width=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.vidSub.width,
                    height=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.vidSub.height)
            elif (protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                  foundLabels.labeledTrack[0].imgSub):  # ImageSubstrate
                ftpath = cvac.FilePath(
                    directory=cvac.DirectoryPath(
                        relativePath=protobuf_matlab_bridge_msg.res.results.
                        rslt[ridx].foundLabels.labeledTrack[0].imgSub.path.
                        directory.relativePath.encode('utf-8')),
                    filename=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.imgSub.path.filename.encode('utf-8'))
                ftsub = cvac.ImageSubstrate(
                    path=ftpath,
                    width=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.imgSub.width,
                    height=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.imgSub.height)
            else:
                print "error: unsupported LabeledLocation (found) substrate"
            ftlab = cvac.Label(
                hasLabel=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                foundLabels.labeledTrack[0].lab.hasLabel,
                name=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                foundLabels.labeledTrack[0].lab.name.encode('utf-8'),
                semantix=cvac.Semantics(
                    url=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    foundLabels.labeledTrack[0].lab.semantix.url))
            track = []
            for fidx, frm in enumerate(protobuf_matlab_bridge_msg.res.results.
                                       rslt[ridx].foundLabels.labeledTrack[0].
                                       keyframesLocations.framelocation):
                vst = cvac.VideoSeekTime(time=frm.frame.time,
                                         framecnt=frm.frame.framecnt)
                # '-1' is used to flag locations that are not of a particular type
                if frm.loc.x != -1 and frm.loc.y != -1:
                    pt2d = cvac.Point2D(x=frm.loc.x, y=frm.loc.y)
                elif frm.locPrecise.x != -1 and frm.locPrecise.y != -1:
                    pt2d = cvac.PreciseLocation(
                        centerX=round(frm.locPrecise.x, 1),
                        centerY=round(frm.locPrecise.y, 1))
                else:
                    print "error: unsupported location type"
                frmLoc = cvac.FrameLocation(frame=vst,
                                            loc=pt2d,
                                            occluded=frm.occluded,
                                            outOfFrame=frm.outOfFrame)
                track.append(frmLoc)
            if (protobuf_matlab_bridge_msg.res.results.rslt[ridx].foundLabels.
                    labeledTrack[0].interp == 0):
                interpol = cvac.Interpolation.DISCRETE
            elif (protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                  foundLabels.labeledTrack[0].interp == 1):
                interpol = cvac.Interpolation.LINEAR
            elif (protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                  foundLabels.labeledTrack[0].interp == 2):
                interpol = cvac.Interpolation.POLYNOMIAL
            else:
                print "error: interpolation type not supported"
            if (protobuf_matlab_bridge_msg.res.results.rslt[ridx].foundLabels.
                    labeledTrack[0].vidSub):  # VideoSubstrate
                ftlabelable = cvac.LabeledTrack(
                    confidence=protobuf_matlab_bridge_msg.res.results.
                    rslt[ridx].foundLabels.labeledTrack[0].confidence,
                    lab=ftlab,
                    sub=ftsub,
                    keyframesLocations=track,
                    interp=interpol)
            else:  # ImageSubstrate
                ftlabelable = cvac.LabeledTrack(
                    confidence=protobuf_matlab_bridge_msg.res.results.
                    rslt[ridx].foundLabels.labeledTrack[0].confidence,
                    lab=ftlab,
                    sub=ftsub,
                    keyframesLocations=track,
                    interp=interpol)
        elif (protobuf_matlab_bridge_msg.res.results.rslt[ridx].foundLabels.
              labeledLocation):
            if (protobuf_matlab_bridge_msg.res.results.rslt[ridx].foundLabels.
                    labeledLocation[0].vidSub):  # VideoSubstrate
                ftpath = cvac.FilePath(
                    directory=cvac.DirectoryPath(
                        relativePath=protobuf_matlab_bridge_msg.res.results.
                        rslt[ridx].foundLabels.labeledLocation[0].vidSub.
                        videopath.directory.relativePath.encode('utf-8')),
                    filename=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.vidSub.videopath.filename.encode('utf-8'))
                ftsub = cvac.VideoSubstrate(
                    videopath=ftpath,
                    width=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.vidSub.width,
                    height=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.vidSub.height)
            elif (protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                  foundLabels.labeledLocation[0].imgSub):  # ImageSubstrate
                ftpath = cvac.FilePath(
                    directory=cvac.DirectoryPath(
                        relativePath=protobuf_matlab_bridge_msg.res.results.
                        rslt[ridx].foundLabels.labeledLocation[0].imgSub.path.
                        directory.relativePath),
                    filename=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.imgSub.path.filename)
                ftsub = cvac.ImageSubstrate(
                    path=ftpath,
                    width=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.imgSub.width,
                    height=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                    original.imgSub.height)
            else:
                print "error: unsupported LabeledTrack (found) substrate"
            hasLabel = protobuf_matlab_bridge_msg.res.results.rslt[
                ridx].foundLabels.labeledLocation[0].lab.hasLabel
            name = protobuf_matlab_bridge_msg.res.results.rslt[
                ridx].foundLabels.labeledLocation[0].lab.name.encode('utf-8')
            semantix = cvac.Semantics(
                url=protobuf_matlab_bridge_msg.res.results.rslt[ridx].
                foundLabels.labeledLocation[0].lab.semantix.url)
            ftlab = cvac.Label(hasLabel=hasLabel, name=name, semantix=semantix)
            for lidx, loc in enumerate(protobuf_matlab_bridge_msg.res.results.
                                       rslt[ridx].foundLabels.labeledLocation):
                ftbox = cvac.BBox()
                ftbox.x = protobuf_matlab_bridge_msg.res.results.rslt[
                    ridx].foundLabels.labeledLocation[lidx].loc.x
                ftbox.y = protobuf_matlab_bridge_msg.res.results.rslt[
                    ridx].foundLabels.labeledLocation[lidx].loc.y
                ftbox.width = protobuf_matlab_bridge_msg.res.results.rslt[
                    ridx].foundLabels.labeledLocation[lidx].loc.width
                ftbox.height = protobuf_matlab_bridge_msg.res.results.rslt[
                    ridx].foundLabels.labeledLocation[lidx].loc.height
                confidence = protobuf_matlab_bridge_msg.res.results.rslt[
                    ridx].foundLabels.labeledLocation[lidx].confidence
                locLabelable.append(
                    cvac.LabeledLocation(confidence=confidence,
                                         lab=ftlab,
                                         sub=ftsub,
                                         loc=ftbox))
        # append result
        if flabelable and ftlabelable:
            rslt_set.append(cvac.Result(olabelable, [flabelable, ftlabelable]))
        elif flabelable:
            rslt_set.append(cvac.Result(olabelable, [flabelable]))
        elif ftlabelable:
            rslt_set.append(cvac.Result(olabelable, [ftlabelable]))
        elif locLabelable:
            rslt_set.append(cvac.Result(olabelable, locLabelable))
        else:
            print "debug: didn't find a label, so setting an empty one"
            rslt_set.append(cvac.Result(olabelable, [cvac.Labelable()]))

    resultset = cvac.ResultSet(rslt_set)

    return resultset
    def test_remotePutGetDelete(self):
        print('putFile remote')
        properties = self.ic.getProperties()
        proxyStr = properties.getProperty('PythonFileService.Proxy')
        #need to get the server host to connect to
        remoteHost = os.getenv('CVAC_REMOTE_TEST_SERVER')
        if remoteHost:
            proxyStr = proxyStr + " -h " + remoteHost
        base = self.ic.stringToProxy(proxyStr)
        #configStr = "FileService:default -h vision.nps.edu -p 10110"
        baser = self.ic.stringToProxy(proxyStr)
        if not baser:
            raise RuntimeError("Unknown service?", proxyStr)
        fsr = cvac.FileServicePrx.checkedCast(baser)
        if not fsr:
            raise RuntimeError("Invalid proxy:", proxyStr)

        # read the bytes from TestUsFlag.jpg
        testDir = cvac.DirectoryPath("testImg")
        origFilePath = cvac.FilePath(testDir, "TestUsFlag.jpg")
        origFS = self.dataDir + "/" + self.getFSPath(origFilePath)
        if not os.path.exists(origFS):
            raise RuntimeError("Cannot obtain FS path to original file,",
                               "see comments. file: " + origFS)
        forig = open(origFS, 'rb')
        bytes = bytearray(forig.read())

        # "put" the file's bytes as a different file which must not exist
        #  if the file exists output an error.
        putFilePath = cvac.FilePath(testDir, "TargetFilename.jpg")
        if fsr.exists(putFilePath):
            raise RuntimeError("File " + putFilePath.filename +
                               " exists on remote host " + proxyStr +
                               " remove and rerun test.")

        try:
            fsr.putFile(putFilePath, bytes)
        except cvac.FileServiceException as ex:
            print(
                "if you do not have 'put' permissions, " +
                "was the file deleted properly in a prior test run?\nfile: " +
                putFilePath.filename)
            raise ex
        forig.close()

        # "get" the bytes again from the same name that we used for putting,
        # store them in a file on the local file system with the same name,
        # and compare the obtained file to the original one
        print('getFile remote')
        getFS = self.dataDir + "/" + self.getFSPath(putFilePath)
        if os.path.exists(getFS):
            print("Local file exists already - cannot getFile remote. file: " +
                  getFS)
        else:
            fgetFS = open(getFS, 'wb')
            recvbytes = fsr.getFile(putFilePath)
            fgetFS.write(recvbytes)
            fgetFS.close()

            # now compare the results and delete the local file
            if not self.filesAreEqual(origFS, getFS):
                raise RuntimeError(
                    "File was not 'put' or subsequently 'get' correctly to.",
                    "Please check, then remove manually: " + getFS)
            os.remove(getFS)

        # delete the file on the remote side and check that it's gone
        print('deleteFile remote')
        fsr.deleteFile(putFilePath)
        try:
            dummy = fsr.getFile(putFilePath)
            raise RuntimeError("File was not deleted on remote FileServer:",
                               putFilePath)
        except:
            # we expect the except
            pass
Exemple #16
0
def parse(CVAC_DataDir, localDir, vidfile, framefolder, annotfile):
    print('vatic.parse called with: {0}, {1}, {2}'.format(
        vidfile, framefolder, annotfile))

    # what's the file name, where is it located?  both on file
    # system as well as in CVAC terms:
    cvacDir = cvac.DirectoryPath(localDir)
    cvacFp = cvac.FilePath(cvacDir, vidfile)
    substrate = cvac.Substrate(False, True, cvacFp, -1, -1)
    fsPath = CVAC_DataDir + '/' + localDir + '/' + annotfile
    af = open(fsPath, 'r')

    # parse line by line and assemble lines with the same
    # trackID into a CVAC LabeledTrack.  Some checks are performed
    # to see whether the output format is what we expect.
    labels = []
    paths = {}
    lastTrackID = -1
    lbltrack = None
    for line in af:
        cols = line.strip().split(' ')  # line has \n - remove it
        trackID = int(cols[0])
        xmin = int(cols[1])
        ymin = int(cols[2])
        xmax = int(cols[3])
        ymax = int(cols[4])
        frame = int(cols[5])
        lost = cols[6]
        occluded = cols[7]
        generated = cols[8]
        labelname = cols[9].strip('"')  # single label, enclosed in ""
        attributes = cols[10:]  # attribute columns, if any
        # print trackID, xmin, ymin, labelname, attributes

        # ignore lost and occluded labels
        if lost == "1":
            isLost = True
        else:
            isLost = False
        if occluded == "1":
            isOccluded = True
        else:
            isOccluded = False

        # format consistency checks
        if trackID == -1 or trackID < lastTrackID or trackID > lastTrackID + 1:
            raise RuntimeError("unexpected trackID: {0} (was {1}).".format(
                trackID, lastTrackID))

        # new track or continuation of previous track?
        if trackID == lastTrackID:
            # make sure labels haven't changed
            if lbltrack.lab.name != labelname:
                raise RuntimeError(
                    "in trackID {0}, expected identical labels ({0} vs {1})".
                    format(lbltrack.lab.name, labelname))
        else:
            lbltrack = cvac.LabeledTrack()
            labels = labels + [lbltrack]
            lastTrackID = trackID

            lbltrack.confidence = 1.0
            properties = {}
            for attrib in attributes:
                properties[attrib.text] = ''
            lbltrack.lab = cvac.Label(True, labelname, properties,
                                      cvac.Semantics())
            lbltrack.sub = substrate
            lbltrack.keyframesLocations = []
            lbltrack.interp = cvac.Interpolation.DISCRETE

        vst = cvac.VideoSeekTime(-1, frame)  # no time, but frame number
        loc = cvac.BBox(xmin, ymin, xmax - xmin, ymax - ymin)
        frameloc = cvac.FrameLocation(vst, loc, isOccluded, isLost)
        lbltrack.keyframesLocations.append(frameloc)

    return labels
 def test_getFile(self):
     print('getFile')
     # test with a small file for now
     testDir = cvac.DirectoryPath("testImg")
     filePath = cvac.FilePath(testDir, "TestUsFlag.jpg")
     self.getFileAndCompare(filePath)