Exemple #1
0
def calc_feature_vector(path):
    x_cells, y_cells = good_cells(path, 3, 3)
    avg_hists, bin_edges, avg_magnitudes, variances, flow = VideoFeatures(
        path).calc_window_features(x_cells, y_cells, None)
    fv = np.concatenate(
        (avg_hists.flatten(), avg_magnitudes.flatten(), variances.flatten()))

    return fv
Exemple #2
0
    def predict(self, path):
        x_cells, y_cells = good_cells(path, 3, 3)

        avg_hists, bin_edges, avg_magnitudes, variances, flow = VideoFeatures(
            path).calc_window_features(x_cells, y_cells, None)
        fv = np.concatenate((avg_hists.flatten(), avg_magnitudes.flatten(),
                             variances.flatten()))

        prediction = self.classifier.predict(self.pca.transform(fv))[0]
        return prediction
Exemple #3
0
    def realtime_predict(self, test_path, label_path, window_size, start, end,
                         output):
        labels = self.read_labels(label_path)
        x_cells, y_cells = good_cells(test_path, 3, 3)

        v = cv2.VideoWriter()
        dims = vid_dims(test_path)
        codec = cv2.cv.CV_FOURCC('m', 'p', '4', 'v')
        v.open(output, codec, 15, dims, 1)

        predictions = []
        true_labels = []
        for pos, agg_features in enumerate(
                VideoFeatures(test_path, persist=True).aggregate_features(
                    x_cells, y_cells, window_size)):
            if window_size + pos < start:
                continue
            if window_size + pos > end:
                break

            avg_hists, bin_edges, avg_magnitudes, variances, flow = agg_features
            fv = np.concatenate((avg_hists.flatten(), avg_magnitudes.flatten(),
                                 variances.flatten()))

            if self.probabalistic:
                prediction = self.classifier.predict_proba(
                    self.pca.transform(fv))[0]
            else:
                prediction = self.classifier.predict(self.pca.transform(fv))[0]
                vis = flow.show("Prediction",
                                flow=False,
                                text=prediction,
                                display=True)
                flow.show("Flow", flow=True, display=True)
                v.write(vis)

            # prediction is centered on current_time-window_size/2
            # and current_time=window_size+pos
            # => prediction is for (window_size/2)+pos
            predictions.append(prediction)
            true_labels.append(labels[(window_size / 2) + pos])

        print

        if self.probabalistic:
            self.roc_analysis(predictions, true_labels)
        else:
            confmat_labels = sorted(set(predictions + true_labels))
            confmat = confusion_matrix(true_labels, predictions,
                                       confmat_labels)
            self.draw_confmat(confmat, confmat_labels)
            print "Accuracy: ", accuracy_score(true_labels, predictions)

        v.release()
Exemple #4
0
from bokeh.glyphs import ImageRGBA
from actipy.video_features import VideoFeatures
from actipy.plan import good_cells, vid_dims
import hashlib
from sys import argv

import matplotlib.pyplot as plt

path = argv[1]
output_path = argv[2]

vid_width, vid_height = vid_dims(path)
x_cells, y_cells = good_cells(path, 15, 15)
print "Using a cell grid of: %dx%d" % (x_cells, y_cells)

avg_hists, bin_edges, avg_magnitudes, variances, flow = VideoFeatures(
    path).calc_window_features(x_cells, y_cells)


def make_color(x, y):
    # RGB
    #return "#%02x%02x%02x" % (np.floor(x*250), np.floor(np.logspace(0,np.log10(250),251)[np.floor(y*250)]), 150)
    return "#%02x%02x%02x" % (np.floor(x * 250), np.floor(y * 250), 150)


bins = len(bin_edges) - 1
angle = 2.0 * np.pi / bins
#angles = np.arange(bins)*angle
angles = np.roll(bin_edges[:-1], bins / 4)

vis_width = 1200
vis_height = int(vid_height * (float(vis_width) / vid_width))