Пример #1
0
import vidfeat
import imfeat
import sklearn.svm
from vidfeat.models.synthetic_bovw_clusters import clusters
#import kernels
HOG = imfeat.HOGLatent(8, 2)


class FenceFrameFeature(vidfeat.ClassifierFrameFeature):
    #feature = imfeat.MetaFeature(imfeat.GradientHistogram(), imfeat.Histogram('lab'))
    feature = imfeat.MetaFeature(imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3))
    
    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(FenceFrameFeature, self).__init__(classifier=classifier,
                                                    *args, **kw)

    def _feature(self, image):
        import time
        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out

if __name__ == '__main__':
    vidfeat._frame_feature_main('fence', vidfeat.FenceFrameFeature)

Пример #2
0
import vidfeat
import imfeat
import sklearn.svm
from vidfeat.models.screenshot_bovw_clusters import clusters
#import kernels

HOG = imfeat.HOGLatent(8, 2)


class ScreenshotFrameFeature(vidfeat.ClassifierFrameFeature):
    #feature = imfeat.MetaFeature(imfeat.GradientHistogram(), imfeat.Histogram('lab'))
    feature = imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3)
    
    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(ScreenshotFrameFeature, self).__init__(classifier=classifier,
                                                    *args, **kw)

    def _feature(self, image):
        import time
        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out
        

if __name__ == '__main__':
    vidfeat._frame_feature_main('screenshot', vidfeat.ScreenshotFrameFeature)
Пример #3
0
import vidfeat
import imfeat
import sklearn.svm


class BlankFrameFeature(vidfeat.ClassifierFrameFeature):
    feature = imfeat.BlackBars()
    
    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(BlankFrameFeature, self).__init__(classifier=classifier, *args, **kw)

    def _feature(self, image):
        return self.feature(image)

    def predict(self, frame):
        if not frame.size:
            return 0 if self._invert else 1
        else:
            return super(BlankFrameFeature, self).predict(frame)

if __name__ == '__main__':
    vidfeat._frame_feature_main('blank', vidfeat.BlankFrameFeature, remove_bars=False)
    
Пример #4
0
import vidfeat
import imfeat
import sklearn.svm
from vidfeat.models.snow_bovw_clusters import clusters
HOG = imfeat.HOGLatent(8, 2)



class RoadFrameFeature(vidfeat.ClassifierFrameFeature):
    #feature = imfeat.PyramidHistogram('lab')
    feature = imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3)

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(RoadFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)

    def _feature(self, image):
        import time
        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out

if __name__ == '__main__':
    vidfeat._frame_feature_main('road', vidfeat.RoadFrameFeature)
Пример #5
0
import vidfeat
import imfeat
import sklearn.svm
from vidfeat.models.person_bovw_clusters import clusters
HOG = imfeat.HOGLatent(8, 2)



class PersonFrameFeature(vidfeat.ClassifierFrameFeature):
    #feature = imfeat.PyramidHistogram('lab')
    feature = imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3)

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(PersonFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)

    def _feature(self, image):
        import time
        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out

if __name__ == '__main__':
    vidfeat._frame_feature_main('person', vidfeat.PersonFrameFeature)
Пример #6
0
import vidfeat
import imfeat
import sklearn.svm


class UnderwaterFrameFeature(vidfeat.ClassifierFrameFeature):
    feature = imfeat.MetaFeature(imfeat.Histogram('lab'), imfeat.GIST(), max_side=128)

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(UnderwaterFrameFeature, self).__init__(classifier=classifier,
                                                     *args, **kw)
    
    def _feature(self, image):
        return self.feature(image)


if __name__ == '__main__':
    vidfeat._frame_feature_main('underwater', vidfeat.UnderwaterFrameFeature)
Пример #7
0
import vidfeat
import imfeat
import sklearn.svm
from vidfeat.models.person_bovw_clusters import clusters
HOG = imfeat.HOGLatent(8, 2)


class PersonHandFrameFeature(vidfeat.ClassifierFrameFeature):
    #feature = imfeat.PyramidHistogram('lab')
    feature = imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3)

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(PersonHandFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)

    def _feature(self, image):
        import time
        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out

if __name__ == '__main__':
    vidfeat._frame_feature_main('person_hand', vidfeat.PersonHandFrameFeature)
Пример #8
0
import vidfeat
import imfeat
import sklearn.svm
import kernels


class PoorQualityFrameFeature(vidfeat.ClassifierFrameFeature):
    feature = imfeat.GradientHistogram()

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(PoorQualityFrameFeature, self).__init__(classifier=classifier,
                                                      *args, **kw)
    
    def _feature(self, image):
        return self.feature(image)


if __name__ == '__main__':
    vidfeat._frame_feature_main('poor_quality', vidfeat.PoorQualityFrameFeature)
Пример #9
0
import vidfeat
import imfeat
import sklearn.svm


class FireFrameFeature(vidfeat.ClassifierFrameFeature):
    feature = imfeat.PyramidHistogram('lab')

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(FireFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)
    
    def _feature(self, image):
        return self.feature(image)


if __name__ == '__main__':
    vidfeat._frame_feature_main('fire', vidfeat.FireFrameFeature)
Пример #10
0
import vidfeat
import imfeat
import sklearn.svm
from vidfeat.models.person_bovw_clusters import clusters
HOG = imfeat.HOGLatent(8, 2)

class PersonUpperFrameFeature(vidfeat.ClassifierFrameFeature):
    #feature = imfeat.PyramidHistogram('lab')
    feature = imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3)

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(PersonUpperFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)

    def _feature(self, image):
        import time
        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out

if __name__ == '__main__':
    vidfeat._frame_feature_main('person_upper', vidfeat.PersonUpperFrameFeature)
Пример #11
0
import vidfeat
import imfeat
import sklearn.svm
from vidfeat.models.snow_bovw_clusters import clusters
HOG = imfeat.HOGLatent(8, 2)
#import kernels


class SnowFrameFeature(vidfeat.ClassifierFrameFeature):
    #feature = imfeat.PyramidHistogram('lab')
    feature = imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3)

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(SnowFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)

    def _feature(self, image):
        import time
        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out

if __name__ == '__main__':
    vidfeat._frame_feature_main('snow', vidfeat.SnowFrameFeature)
Пример #12
0
import vidfeat
import imfeat
import sklearn.svm
import numpy as np


def color_stats(image):
    image_hsv = imfeat.convert_image(image, {'mode': 'hsv', 'type': 'numpy', 'dtype': 'float32'})
    image_hsv = image_hsv.reshape((image_hsv.shape[0] * image_hsv.shape[1], image_hsv.shape[2]))
    image_hsv[:, 0] /= 360  # Rescale
    return np.hstack([np.min(image_hsv, 0), np.max(image_hsv, 0), np.mean(image_hsv, 0),
                      np.median(image_hsv, 0), np.std(image_hsv, 0), imfeat.UniqueColors()(image)])


class GrayFrameFeature(vidfeat.ClassifierFrameFeature):

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(GrayFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)

    def _feature(self, image):
        out = color_stats(imfeat.resize_image_max_side(image, 128))
        return out


if __name__ == '__main__':
    vidfeat._frame_feature_main('gray', vidfeat.GrayFrameFeature)
Пример #13
0
import vidfeat
import imfeat
import sklearn.svm


class LowLightFrameFeature(vidfeat.ClassifierFrameFeature):
    feature = imfeat.MetaFeature(imfeat.GradientHistogram(), imfeat.Histogram('lab', num_bins=4), imfeat.Moments('lab', 2), max_side=128)

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(LowLightFrameFeature, self).__init__(classifier=classifier,
                                                   *args, **kw)
    
    def _feature(self, image):
        return self.feature(image)


if __name__ == '__main__':
    vidfeat._frame_feature_main('low_light', vidfeat.LowLightFrameFeature)
Пример #14
0
import vidfeat
import imfeat
import sklearn.svm


class WaterOutdoorFrameFeature(vidfeat.ClassifierFrameFeature):
    feature = imfeat.MetaFeature(imfeat.Histogram('lab'), imfeat.GIST(), max_side=128)

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(WaterOutdoorFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)
    
    def _feature(self, image):
        return self.feature(image)


if __name__ == '__main__':
    vidfeat._frame_feature_main('water_outdoor', vidfeat.WaterOutdoorFrameFeature)
Пример #15
0
import vidfeat
import imfeat
import sklearn.svm


class VerticalBoxedFrameFeature(vidfeat.ClassifierFrameFeature):
    feature = imfeat.BlackBars()

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(VerticalBoxedFrameFeature, self).__init__(classifier=classifier,
                                                        *args, **kw)

    def _feature(self, image):
        return self.feature(image)


if __name__ == '__main__':
    vidfeat._frame_feature_main('vertical_boxed', vidfeat.VerticalBoxedFrameFeature, remove_bars=True)
Пример #16
0
from vidfeat.models.synthetic_bovw_clusters import clusters

# import kernels
HOG = imfeat.HOGLatent(8, 2)


class SyntheticFrameFeature(vidfeat.ClassifierFrameFeature):
    # feature = imfeat.MetaFeature(imfeat.GradientHistogram(), imfeat.Histogram('lab'))
    feature = imfeat.MetaFeature(
        imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3),
        imfeat.Histogram("lab", num_bins=4),
        imfeat.UniqueColors(),
    )

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight="auto")
        self.svm_parameters = [{"C": [10 ** x for x in range(0, 12, 3)]}]
        super(SyntheticFrameFeature, self).__init__(classifier=classifier, *args, **kw)

    def _feature(self, image):
        import time

        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out


if __name__ == "__main__":
    vidfeat._frame_feature_main("synthetic", vidfeat.SyntheticFrameFeature)
Пример #17
0
import vidfeat
import imfeat
import sklearn.svm
from vidfeat.models.synthetic_bovw_clusters import clusters
#import kernels
HOG = imfeat.HOGLatent(8, 2)


class TextFrameFeature(vidfeat.ClassifierFrameFeature):
    #feature = imfeat.MetaFeature(imfeat.GradientHistogram(), imfeat.Histogram('lab'))
    feature = imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3)
    
    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(TextFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)

    def _feature(self, image):
        import time
        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out

if __name__ == '__main__':
    vidfeat._frame_feature_main('text', vidfeat.TextFrameFeature)

Пример #18
0
import vidfeat
import imfeat
import sklearn.svm


class HorizontalBoxedFrameFeature(vidfeat.ClassifierFrameFeature):
    feature = imfeat.BlackBars()

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(HorizontalBoxedFrameFeature, self).__init__(classifier=classifier,
                                                          *args, **kw)
    def remove_bars(self, image):
        pass

    def _feature(self, image):
        return self.feature(image)

if __name__ == '__main__':
    vidfeat._frame_feature_main('horizontal_boxed', vidfeat.HorizontalBoxedFrameFeature, remove_bars=False)
Пример #19
0
import vidfeat
import imfeat
import sklearn.svm
from vidfeat.models.snow_bovw_clusters import clusters
HOG = imfeat.HOGLatent(8, 2)


class GrassFrameFeature(vidfeat.ClassifierFrameFeature):
    #feature = imfeat.PyramidHistogram('lab')
    feature = imfeat.BoVW(lambda x: HOG.make_bow_mask(x, clusters), clusters.shape[0], 3)

    def __init__(self, *args, **kw):
        classifier = sklearn.svm.LinearSVC(class_weight='auto')
        self.svm_parameters = [{'C': [10 ** x for x in range(0, 12, 3)]}]
        super(GrassFrameFeature, self).__init__(classifier=classifier,
                                               *args, **kw)

    def _feature(self, image):
        import time
        st = time.time()
        out = self.feature(imfeat.resize_image_max_side(image, 160))
        print time.time() - st
        return out


if __name__ == '__main__':
    vidfeat._frame_feature_main('grass', vidfeat.GrassFrameFeature)