예제 #1
0
    def testClassificationFrame(self):
        handDetectorFile = DATASET_HANDDETECTOR_GT_PATH.format(self.dataset,
                                                               self.feature,
                                                               self.classifier,
                                                               self.dynamic)
        if self.dynamic == "":
            self.handDetector = ObjectPickler.load(HandDetector, handDetectorFile)
        else:
            self.handDetector = ObjectPickler.load(DynamicHandDetector, handDetectorFile)
            self.handDetector.setOptimalParameters(50.0)
        frame = ObjectPickler.load(Frame, VIDEO_EXAMPLE_PATH.format("frameMatrix.pk"))
        hands = self.handDetector.classifyFrame(frame,dtype="integer")
        self.assertIsInstance(hands, numpy.ndarray,
                              msg="Hand detector is not returning arrays")
        self.assertEqual(hands.size, 1,
                              msg="Hand detector is not returning arrays of size 1")
        self.assertIsInstance(hands[0], int,
                              msg="Hand detector is not returning arrays of size 1 with an integer")

        hands = self.handDetector.classifyFrame(frame,dtype="float")
        self.assertIsInstance(hands, numpy.ndarray,
                              msg="Hand detector is not returning arrays")
        self.assertEqual(hands.size, 1,
                              msg="Hand detector is not returning arrays of size 1")
        self.assertIsInstance(hands[0], float,
                              msg="Hand detector is not returning arrays of size 1 with a float")
예제 #2
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")
예제 #3
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)
예제 #4
0
 def testClassificationVideo(self):
     handDetectorFile = DATASET_HANDDETECTOR_GT_PATH.format(self.dataset,
                                                            self.feature,
                                                            self.classifier,
                                                            self.dynamic)
     self.handDetector = ObjectPickler.load(HandDetector, handDetectorFile)
     video = Video(VIDEO_EXAMPLE_PATH.format("BENCHTEST.MP4"))
     hands = self.handDetector.classifyVideo(video,dtype="integer")
     self.assertIsInstance(hands, numpy.ndarray,
                           msg="Hand detector is not returning arrays")
     video.release()
예제 #5
0
    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")
예제 #6
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")
예제 #7
0
    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")
예제 #8
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")
예제 #9
0
 def testVideoFeatureLoader(self):
     pickleName = GROUNDTRUTH_VIDEOFEATURE_PATH.format(
         self.videoname, self.feature)
     featureVideo = ObjectPickler.load(FeatureVideo, pickleName)
     self.assertIsInstance(featureVideo.features, numpy.ndarray)