<commit_before>// Began with a copy-and-paste from:
//   http://www.html5rocks.com/en/tutorials/getusermedia/intro/ 
//   https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Manipulating_video_using_canvas

if (typeof YAJT === 'undefined') {
    YAJT = {};
}

YAJT.core = {
    config: {
        selector: '#yajt',
        input_class: 'input',
        output_class: 'output',
        width: 200,
        height: 150,
        timeout: 500, // 0.5 seconds
        transforms: [],
        threshold: 128
    },
    timer_callback: function () {
        if (this.video.paused || this.video.ended) {
            return;
        }
        image_data = this.compute_image_data();
        console.log(YAJT.dimension_reduction.from_top(image_data));

        var self = this;
        setTimeout(function () {
            self.timer_callback();
        }, this.config.timeout);
    },
    init: function (options) {
        for (var key in options) {
            this.config[key] = options[key];
        }
        var w_h = {
            width: this.config.width,
            height: this.config.height
        };
        var selector = this.config.selector;
        var input_class = this.config.input_class;
        var output_class = this.config.output_class;

        $(selector)
                .append($('<video autoplay>').attr(w_h).hide())
                .append($('<canvas class="' + input_class + '">').attr(w_h).hide())
                .append($('<canvas class="' + output_class + '">').attr(w_h));
        this.video = $(selector + ' video')[0];
        this.input = $(selector + ' .' + input_class)[0].getContext('2d');
        this.output = $(selector + ' .' + output_class)[0].getContext('2d');

        var self = this;
        var video_obj = {'video': true},
        error_handler = function (error) {
            console.log('Video capture error: ', error.code);
        };
        if (navigator.getUserMedia) { // Standard
            navigator.getUserMedia(video_obj, function (stream) {
                self.video.src = stream;
                self.video.play();
            }, error_handler);
        } else if (navigator.webkitGetUserMedia) { // WebKit
            navigator.webkitGetUserMedia(video_obj, function (stream) {
                self.video.src = window.webkitURL.createObjectURL(stream);
                self.video.play();
            }, error_handler);
        } else if (navigator.mozGetUserMedia) { // Firefox
            navigator.mozGetUserMedia(video_obj, function (stream) {
                self.video.src = window.URL.createObjectURL(stream);
                self.video.play();
            }, error_handler);
        }

        this.video.addEventListener('play', function () {
            self.timer_callback();
        }, false);
    },
    compute_image_data: function () {
        this.input.drawImage(this.video, 0, 0, this.config.width, this.config.height);
        var image_data = this.input.getImageData(0, 0, this.config.width, this.config.height);
        ;
        var transforms = this.config.transforms;
        for (var i = 0; i < transforms.length; i++) {
            transforms[i](image_data.data);
        }
        this.output.putImageData(image_data, 0, 0);
        return image_data.data;
    }
};<commit_msg>Things are starting to get interesting: red line over image.<commit_after>// Began with a copy-and-paste from:
//   http://www.html5rocks.com/en/tutorials/getusermedia/intro/ 
//   https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Manipulating_video_using_canvas

if (typeof YAJT === 'undefined') {
    YAJT = {};
}

YAJT.core = {
    config: {
        selector: '#yajt',
        input_class: 'input',
        output_class: 'output',
        width: 200,
        height: 150,
        timeout: 500, // 0.5 seconds
        transforms: [],
        threshold: 32
    },
    timer_callback: function () {
        if (this.video.paused || this.video.ended) {
            return;
        }
        var image_data = this.compute_image_data();
        var reduction = YAJT.dimension_reduction.from_top(image_data);
        this.draw_graph(reduction);

        var self = this;
        setTimeout(function () {
            self.timer_callback();
        }, this.config.timeout);
    },
    init: function (options) {
        for (var key in options) {
            this.config[key] = options[key];
        }
        var w_h = {
            width: this.config.width,
            height: this.config.height
        };
        var selector = this.config.selector;
        var input_class = this.config.input_class;
        var output_class = this.config.output_class;

        $(selector)
                .append($('<video autoplay>').attr(w_h).hide())
                .append($('<canvas class="' + input_class + '">').attr(w_h).hide())
                .append($('<canvas class="' + output_class + '">').attr(w_h));
        this.video = $(selector + ' video')[0];
        this.input = $(selector + ' .' + input_class)[0].getContext('2d');
        this.output = $(selector + ' .' + output_class)[0].getContext('2d');

        var self = this;
        var video_obj = {'video': true},
        error_handler = function (error) {
            console.log('Video capture error: ', error.code);
        };
        if (navigator.getUserMedia) { // Standard
            navigator.getUserMedia(video_obj, function (stream) {
                self.video.src = stream;
                self.video.play();
            }, error_handler);
        } else if (navigator.webkitGetUserMedia) { // WebKit
            navigator.webkitGetUserMedia(video_obj, function (stream) {
                self.video.src = window.webkitURL.createObjectURL(stream);
                self.video.play();
            }, error_handler);
        } else if (navigator.mozGetUserMedia) { // Firefox
            navigator.mozGetUserMedia(video_obj, function (stream) {
                self.video.src = window.URL.createObjectURL(stream);
                self.video.play();
            }, error_handler);
        }

        this.video.addEventListener('play', function () {
            self.timer_callback();
        }, false);
    },
    compute_image_data: function () {
        this.input.drawImage(this.video, 0, 0, this.config.width, this.config.height);
        var image_data = this.input.getImageData(0, 0, this.config.width, this.config.height);
        var transforms = this.config.transforms;
        for (var i = 0; i < transforms.length; i++) {
            transforms[i](image_data.data);
        }
        this.output.putImageData(image_data, 0, 0);
        return image_data.data;
    },
    draw_graph: function(array) {
        this.output.strokeStyle = '#F00';
        this.output.lineWidth = 3;
        this.output.beginPath();
        this.output.moveTo(2, array[0]);
        for (var i = 0; i < array.length; i++) {
            this.output.lineTo(i+2, array[i]);
        }
        this.output.stroke();
    }
};
{'fraction_non_alphanumeric': 0.14320632638389647, 'fraction_numerical': 0.008626887131560028, 'mean_word_length': 2.0021579628830386, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2520916', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2045, 'n_words': 374}