Beispiel #1
0
 def frameExportImport(self):
     videoname = VIDEO_EXAMPLE_PATH.format(self.videoname)
     video = Video(videoname)
     success, frame = video.read()
     video.release()
     filename = VIDEO_EXAMPLE_PATH.format("frameMatrix.pk")
     ObjectPickler.save(frame, filename)
     frame2 = ObjectPickler.load(Frame, filename)
     self.assertEqual(frame,
                      frame2,
                      msg="Readed frame different of ground truth")
Beispiel #2
0
 def runTest(self):
     frame = ObjectPickler.load(Frame,
                                VIDEO_EXAMPLE_PATH.format("frameMatrix.pk"))
     success, desc = self.featureController.getFeatures(frame)
     desc = desc.next()
     if createGroundTruths:
         gtfile = GROUNDTRUTH_FEATURE_PATH.format(self.feature)
         print "[Feature Creator] Ground Truth Created"
         print gtfile
         if not os.path.exists(os.path.split(gtfile)[0]):
             os.makedirs(os.path.split(gtfile)[0])
         ObjectPickler.save(desc, gtfile)
     self.assertIsInstance(desc, numpy.ndarray)
     desc2 = ObjectPickler.load(
         Feature, GROUNDTRUTH_FEATURE_PATH.format(self.feature))
     numpy.testing.assert_equal(desc, desc2)
Beispiel #3
0
 def runTest(self):
     mask = DATASET_MASKS_PATH.format(dataset, trainingVideo) + trainingMask
     gtfile = DATASET_HSDATAMANAGER_GT_PATH.format(dataset, trainingVideo,
                                                   trainingMask,
                                                   self.feature)
     dm = MaskBasedDataManager()
     dm.readDataset([mask], 200, "LAB")
     if createGroundTruths:
         print "[Feature Creator] Ground Truth Created"
         print gtfile
         if not os.path.exists(os.path.split(gtfile)[0]):
             os.makedirs(os.path.split(gtfile)[0])
         ObjectPickler.save(dm, gtfile)
     dm2 = ObjectPickler.load(MaskBasedDataManager, gtfile)
     numpy.testing.assert_equal(dm.attributes, dm2.attributes)
     self.assertIsInstance(
         dm.attributes,
         numpy.ndarray,
         msg="New HandDetectionDataManager does not guarantee ndarray")
     self.assertIsInstance(dm2.attributes,
                           numpy.ndarray,
                           msg="GroundTruth is not ndarray")
Beispiel #4
0
    def testVideoFeatureCreator(self):
        from datetime import datetime
        outputfile = GROUNDTRUTH_VIDEOFEATURE_PATH.format(
            self.videoname, self.feature)
        videoname = VIDEO_EXAMPLE_PATH.format("".join(
            [self.videoname, self.extension]))
        video = Video(videoname)
        success, featureVideo = self.featureController.getFeatures(video)
        self.assertTrue(success, msg="Impossible to process the features")
        self.assertIsInstance(
            featureVideo.features,
            numpy.ndarray,
            msg="The video reader is not returning an ndarray")

        if createGroundTruths:
            print "[Feature Creator] Ground Truth Created"
            print outputfile
            if not os.path.exists(os.path.split(outputfile)[0]):
                os.makedirs(os.path.split(outputfile)[0])
            success = ObjectPickler.save(featureVideo, outputfile)
            self.assertTrue(success, msg="Impossible to save the features")
    def testDataManager(self):
        datasetFolder = DATASET_PATH.format(self.dataset)
        if os.path.exists(datasetFolder):
            dm = HandDetectionDataManager()
            dm.readDataset(datasetFolder,180,feature=self.feature)
            if createGroundTruths:
                print "[Hand Detection Data Manager] Ground Truth Created"
                gtfile = DATASET_DATAMANAGER_GT_PATH.format(self.dataset,self.feature)
                print gtfile
                if not os.path.exists(os.path.split(gtfile)[0]):
                    os.makedirs(os.path.split(gtfile)[0])
                success = ObjectPickler.save(dm, gtfile)    

            dm2 = ObjectPickler.load(HandDetectionDataManager, DATASET_DATAMANAGER_GT_PATH.format(self.dataset,self.feature))
            numpy.testing.assert_equal(dm.attributes,dm2.attributes)
            self.assertIsInstance(dm.attributes, numpy.ndarray,
                                  msg="New HandDetectionDataManager does not guarantee ndarray")
            self.assertIsInstance(dm2.attributes, numpy.ndarray,
                                  msg="GroundTruth is not ndarray")
        else:
            raise os.error("The dataset does not exists")
    def testTrainingDetector(self):
        datasetFolder = DATASET_DATAMANAGER_GT_PATH.format(self.dataset,self.feature)
        dm = ObjectPickler.load(HandDetectionDataManager, datasetFolder)
        self.handDetector.trainClassifier(dm)
        handDetectorFile = DATASET_HANDDETECTOR_GT_PATH.format(self.dataset,
                                                               self.feature,
                                                               self.classifier,
                                                               self.dynamic)
        if createGroundTruths:
            print "[Hand Detector] Ground Truth Created"
            print handDetectorFile
            if not os.path.exists(os.path.split(handDetectorFile)[0]):
                os.makedirs(os.path.split(handDetectorFile)[0])
            success = ObjectPickler.save(self.handDetector, gtfile)    

        if self.dynamic == "":
            hd = ObjectPickler.load(HandDetector, handDetectorFile)
        else:
            hd = ObjectPickler.load(DynamicHandDetector, handDetectorFile)
            hd.setOptimalParameters(50.0)

        featureVideoPath = GROUNDTRUTH_VIDEOFEATURE_PATH.format(self.videotest, self.feature)
        featureVideo = ObjectPickler.load(FeatureVideo, featureVideoPath)
        featureVideo.features = featureVideo.features[:500]
        r1 = self.handDetector.classifyFeatureVideo(featureVideo,dtype="integer")
        r2 = hd.classifyFeatureVideo(featureVideo,dtype="integer")
        numpy.testing.assert_array_almost_equal(r1,r2,)
        if self.classifier == "SVM":
            if self.dynamic == "_dynamic": #restart the dynamic properties
                self.handDetector = DynamicHandDetector(self.feature, 180,"SVM")
                self.handDetector.trainClassifier(dm)
            r3 = self.handDetector.classifyFeatureVideo(featureVideo,dtype='float')
            r4 = self.handDetector.binarizeDetections(r3,th=0)
            numpy.testing.assert_array_almost_equal(r1,r4)
        self.assertIsInstance(r1, numpy.ndarray,
                              msg="Trained Hand detector is not returning arrays")
        self.assertIsInstance(r2, numpy.ndarray,
                              msg="Ground truth Hand detector is not returning arrays")