<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with createcapture() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=createcapture%28%29</link>
      <pubDate>Sun, 08 Aug 2021 17:41:42 +0000</pubDate>
         <description>Tagged with createcapture() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedcreatecapture%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Video Capture not working, even in reference example</title>
      <link>https://forum.processing.org/two/discussion/14867/video-capture-not-working-even-in-reference-example</link>
      <pubDate>Thu, 11 Feb 2016 22:47:33 +0000</pubDate>
      <dc:creator>kfreed</dc:creator>
      <guid isPermaLink="false">14867@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm trying to figure out how to capture webcam video but I can't seem to get it working. The problem is that not even the example is working for me here:</p>

<p><a href="http://p5js.org/examples/examples/Dom_Video_Capture.php" target="_blank" rel="nofollow">http://p5js.org/examples/examples/Dom_Video_Capture.php</a></p>

<p>This example only ever shows a black window. Firefox asks to share my webcam but doesn't display anything. Chrome and Safari do not prompt to share the webcam.</p>

<p>I am running Mac OS X El Capitan version 10.11.2 and have tried the following browsers all with the same result:</p>

<p>Chrome 48.0.2564.109 (64-bit)
Safari Version 9.0.2 (11601.3.9)
Firefox 44.0.2</p>

<p>Does anyone know why I cannot seem to access my Mac's webcam? Is this a Mac issue?</p>
]]></description>
   </item>
   <item>
      <title>p5 image() friendly error message in React / Webpack</title>
      <link>https://forum.processing.org/two/discussion/26851/p5-image-friendly-error-message-in-react-webpack</link>
      <pubDate>Wed, 14 Mar 2018 21:20:36 +0000</pubDate>
      <dc:creator>RyanAchten</dc:creator>
      <guid isPermaLink="false">26851@/two/discussions</guid>
      <description><![CDATA[<p>I am refactoring a p5 sketch as part of a React/Redux build and am getting the following friendly error message from p5 concerning arguments passed to the <a rel="nofollow" href="https://p5js.org/reference/#p5/image">p.image()</a> function (note: I am using p5 in <a rel="nofollow" href="https://github.com/processing/p5.js/wiki/Global-and-instance-mode">instance mode</a>).</p>

<p><code>p5.js says: image() was expecting p5.Image|p5.Element for parameter #0 (zero-based index), received p5.Element instead at webpack-internal:///239:103:9. [<a href="http://p5js.org/reference/#p5/image]" target="_blank" rel="nofollow">http://p5js.org/reference/#p5/image]</a></code></p>

<p>The video argument the message seems to refer to, is a <code>p5.MediaElement</code> returned from <code>p.createCapture( p.VIDEO )</code> - i.e. webcam stream. I have had no issues when using the same function calls in a static context.</p>

<p>The p.image call sits within the following code block:</p>

<pre><code>const noiseX = p.noise(xoff)*(canvWidth+vWidth);
const noiseY = p.noise(yoff)*(canvHeight+vHeight);
xoff+=visualSettings.perlinScale.active;
yoff+=visualSettings.perlinScale.active;
p.image(video, noiseX-vWidth, noiseY-vHeight, vWidth, vHeight);
</code></pre>

<p>The sketch still runs as expected, but I would like to resolve the issues appropriately (besides, the error sits within the draw cycle which is really irritating).</p>

<p>It is unclear as to what is required to resolve the issue since the friendly error message says it was <em>'expecting a p5.Image or p5.Element'</em> and has <em>'received p5.Element instead'</em>.
Any clarification anyone can provide would be much appreciated.</p>
]]></description>
   </item>
   <item>
      <title>Texturing a Body with image from webcam</title>
      <link>https://forum.processing.org/two/discussion/24938/texturing-a-body-with-image-from-webcam</link>
      <pubDate>Thu, 09 Nov 2017 19:08:54 +0000</pubDate>
      <dc:creator>desertbeaver</dc:creator>
      <guid isPermaLink="false">24938@/two/discussions</guid>
      <description><![CDATA[<p>I'm looking for a way to texture body objects made with Matter.js with snapshots taken from a webcam. For example, every time I call mousePressed() two things happen: 1) a new body is created and 2) a frame from the webcam is pushed into an array. I want to use a new image from that array to texture each new rectangular body. Do I need to somehow use the render/sprite option within Matter.js or can I somehow just use p5 to do this? Thanks for any suggestions!</p>

<p>Here are the two pertinent files:</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/864/3JZCOVDWEW6P.png" alt="Screen Shot 2017-11-09 at 12.10.20 PM" title="Screen Shot 2017-11-09 at 12.10.20 PM" />
<img src="https://forum.processing.org/two/uploads/imageupload/932/XKQNXJHET7NY.png" alt="Screen Shot 2017-11-09 at 12.10.26 PM" title="Screen Shot 2017-11-09 at 12.10.26 PM" /></p>
]]></description>
   </item>
   <item>
      <title>createCapture(VIDEO) on iPhone</title>
      <link>https://forum.processing.org/two/discussion/23952/createcapture-video-on-iphone</link>
      <pubDate>Mon, 28 Aug 2017 16:48:58 +0000</pubDate>
      <dc:creator>blindsp0t</dc:creator>
      <guid isPermaLink="false">23952@/two/discussions</guid>
      <description><![CDATA[<p>Hi there, 
I'm playing a bit with P5.js and it's really exciting.</p>

<p>My question is : i have a project (in P5.js) using createCapture() which works great on GoogleChrome desktop (at least on my laptop), works great on GoogleChrome for Android too, but seems to NOT work on GoogleChrome for iOS... (i just get a blank screen instead of my fullscreen video preview)</p>

<p>Any advices about that?
Is that a known behaviour or may i do something wrong ... ?</p>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Why is the video in canvas not working p5js?</title>
      <link>https://forum.processing.org/two/discussion/22662/why-is-the-video-in-canvas-not-working-p5js</link>
      <pubDate>Thu, 18 May 2017 19:05:59 +0000</pubDate>
      <dc:creator>banana</dc:creator>
      <guid isPermaLink="false">22662@/two/discussions</guid>
      <description><![CDATA[<p>I was watching this video: 
10.4 Brightness Mirror - p5.js Tutorial</p>

<p>and I am not getting my code to work:</p>

<pre>

var video;

function setup() {
  createCanvas(320, 240);
  pixelDensity(1);
  video = createCapture(VIDEO).size(320, 240);
}

function draw() {
  background(51);

  video.loadPixels();

  //pixels from canvas
  loadPixels();
  for (var y = 0; y &lt; height; y++) {
    for (var x = 0; x &lt; width; x++) {
      var index = (x + y * width)*4;
      pixels[index+0] = video.pixels[index+0];
      pixels[index+1] = video.pixels[index+1];
      pixels[index+2] = video.pixels[index+2];
      pixels[index+3] = 255;      
    }
  }
  updatePixels();
}

</pre>

<p>It shows like a ghost-like video :/ 
<a href="http://xxnotmuchxx.tumblr.com/post/160811589716" target="_blank" rel="nofollow">http://xxnotmuchxx.tumblr.com/post/160811589716</a></p>
]]></description>
   </item>
   <item>
      <title>How do I flip video in canvas horizontally in p5js?</title>
      <link>https://forum.processing.org/two/discussion/22546/how-do-i-flip-video-in-canvas-horizontally-in-p5js</link>
      <pubDate>Fri, 12 May 2017 20:08:26 +0000</pubDate>
      <dc:creator>banana</dc:creator>
      <guid isPermaLink="false">22546@/two/discussions</guid>
      <description><![CDATA[<p>Here is my code:</p>

<pre>
var video;

function setup() {
  createCanvas(320, 240); //canvas
  background(51);
  
  video = createCapture(VIDEO); //camera / video
  video.size(320, 240);
  video.hide(); //hides video 
}

function draw() { //canvas
  image(video, 0, 0, width, height); //video on canvas, position, dimensions
}
</pre>
]]></description>
   </item>
   <item>
      <title>Video Stream with Noje.js and Socket.io</title>
      <link>https://forum.processing.org/two/discussion/21835/video-stream-with-noje-js-and-socket-io</link>
      <pubDate>Wed, 05 Apr 2017 18:50:34 +0000</pubDate>
      <dc:creator>CharlesDesign</dc:creator>
      <guid isPermaLink="false">21835@/two/discussions</guid>
      <description><![CDATA[<p>Hi All,</p>

<p>I'm trying to create a simple video stream on the local network. However, the current code throws the following error:</p>

<p><code>Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'</code></p>

<p>Could someone point out what I'm doing wrong?</p>

<p>Thanks in advance, 
Charles</p>

<p><strong>Server.js</strong></p>

<pre><code>var express = require('express');
// Create the app
var app = express();

// Set up the server
// process.env.PORT is related to deploying on heroku
//var server = app.listen(3000);

var server = app.listen(3000, '0.0.0.0', function() {
    console.log('Listening to port:  ' + 3000);
  });

app.use(express.static('public'));

// WebSocket Portion
// WebSockets work with the HTTP server
var socket = require('socket.io');

// Register a callback function to run when we have an individual connection
// This is run for each individual user that connects
var io = socket(server);

io.sockets.on('connection', newConnection);

function newConnection(socket){
    console.log("New connection: " + socket.id);

    socket.on('camera', newFrame);

    function newFrame(data){
        socket.broadcast.emit('camera', data);
        // for(var propertyName in data) {
        //  console.log(propertyName);
        // }
        //console.log(data.elt);
    }
}
</code></pre>

<p><strong>Sketch.js</strong></p>

<pre><code>var socket;
var capture;

function setup() {
  createCanvas(innerWidth, innerHeight);
  background(0);

  capture = createCapture(VIDEO);
  capture.hide();

  socket = io.connect("<a href="http://localhost:3000" target="_blank" rel="nofollow">http://localhost:3000</a>");

  socket.on('camera', newFrame);
  noStroke();
}

function newFrame(data){
    image(data, 0, 0, 640, 320);
}


function draw() {
  socket.emit('camera', capture);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Video stream from Webcam not showing up</title>
      <link>https://forum.processing.org/two/discussion/20337/video-stream-from-webcam-not-showing-up</link>
      <pubDate>Wed, 18 Jan 2017 10:52:26 +0000</pubDate>
      <dc:creator>pranjalchaubey</dc:creator>
      <guid isPermaLink="false">20337@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I am trying to stream the webcam video on the HTML page, using the latest Chrome browser. 
The stream is not showing up, I am getting the following error in the chrome console</p>

<blockquote class="Quote">
  <p>Not allowed to load local resource: blob:null/868aad42-ffd4-4e97-b4fd-ab9a9ffe18f7</p>
</blockquote>

<p>I am trying the implement a very simple example, wondering what is wrong. 
Here is the JS sketch file code,</p>

<p>`(function () {
    "use strict";</p>

<pre><code>var s = function (p) {

      p.setup = function () {
        p.canvas = p.createCanvas(640, 480, p.WEBGL);
        p.canvas.id('p5Canvas');
        p.background(51);
        p.video = p.createCapture(p.VIDEO);
        p.video.size(640, 480);
        p.video.id('p5Video');
        p.video.removeAttribute('crossorigin');
    };

};

var myP5 = new p5(s, 'videoContainer');
</code></pre>

<p>}());`</p>

<p>Here is my HTML file code,</p>

<pre><code>&lt;div id="outputContainer"&gt;
    &lt;div id="videoContainer" width="960" height="720" style="display: inline-block;"&gt;&lt;/div&gt;
    &lt;div id="sketchContainer"&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Any help shall be deeply appreciated in this regard.</p>

<p>PS - The 'code' and 'quote' formatting arguments in this post are acting weird, not sure why.</p>
]]></description>
   </item>
   <item>
      <title>upload image with ajax from camera using p5.js?</title>
      <link>https://forum.processing.org/two/discussion/19996/upload-image-with-ajax-from-camera-using-p5-js</link>
      <pubDate>Fri, 30 Dec 2016 14:55:36 +0000</pubDate>
      <dc:creator>qifan</dc:creator>
      <guid isPermaLink="false">19996@/two/discussions</guid>
      <description><![CDATA[<p>I am using p5.js and its video capture capability to use the camera. I want to use ajax to take some of those images and upload them to a server. I dont know how to convert a p5.js Image object into a format that I can use to send over the wire with ajax. The error I get is:</p>

<p>Uncaught TypeError: Illegal invocation</p>

<p>The problem seems to be that capture is a P5.Image, which isn't something that can be simply uploaded to a server. It's not an image file. It's a data structure specific to P5.js that can render images in P5.js.</p>

<p>So, how do I  convert a P5.Image into a file that you can then upload to a server.</p>

<p>And here is the code in the forum:</p>

<pre><code>function process_image(img) {
    var url = "<a href="http://random.com/process_image" target="_blank" rel="nofollow">http://random.com/process_image</a>";
    $.ajax({
        url: url,
        type: " POST ",
        crossDomain: true,
        dataType: " json ",
        data: {
            image: img
        },
        success: function (response) {
            console.log(response);
        },
        error: function (response) {
            console.log(response);
        }
    });
}

function setup() {
    createCanvas(900, 900);
    capture = createCapture(VIDEO);
    capture.size(320, 240);
    //capture.hide();
}

function draw() {
    background(255);
    image(capture, 0, 0, 320, 240);
    filter('INVERT');
    process_image(capture);

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Camera access on iOS 10 and later</title>
      <link>https://forum.processing.org/two/discussion/19097/camera-access-on-ios-10-and-later</link>
      <pubDate>Thu, 17 Nov 2016 18:02:53 +0000</pubDate>
      <dc:creator>jet</dc:creator>
      <guid isPermaLink="false">19097@/two/discussions</guid>
      <description><![CDATA[<p>I've tried <a href="http://p5js.org/examples/dom-video-capture.html" target="_blank" rel="nofollow">http://p5js.org/examples/dom-video-capture.html</a> on iOS 10 iPhone6, I get no errors and no content.  I tried both http w/ SSL and http, neither work.   The test URL works on OS X and Linux, so I'm pretty comfortable I can cut-and-paste a JS script.</p>

<p>Any suggestions?</p>
]]></description>
   </item>
   <item>
      <title>Unknown Error in P5.js whene loadpixels()?</title>
      <link>https://forum.processing.org/two/discussion/18221/unknown-error-in-p5-js-whene-loadpixels</link>
      <pubDate>Tue, 20 Sep 2016 14:27:45 +0000</pubDate>
      <dc:creator>algercollo</dc:creator>
      <guid isPermaLink="false">18221@/two/discussions</guid>
      <description><![CDATA[<p>I want to video processing using p5.js library. but own code doesn't work when using an external video element by <strong>select(</strong>) function. But the code does work when used <strong>createCapture()</strong> function instead <strong>select()</strong></p>

<pre><code>//index.html

&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Document&lt;/title&gt;
    &lt;script src="assets/vendor/jquery-3.0.0.min.js"&gt;&lt;/script&gt;
    &lt;script src="assets/vendor/p5/p5.min.js"&gt;&lt;/script&gt;
    &lt;script src="assets/vendor/p5/p5.dom.min.js"&gt;&lt;/script&gt;
    &lt;script src="assets/vendor/p5/p5.sound.min.js"&gt;&lt;/script&gt;
    &lt;script src="assets/scripts/script.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div class="snapshot"&gt;
        &lt;video id="video"  autoplay=""&gt;&lt;/video&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

//script.js

$(document).ready(e =&gt; {
    window.currentEffect = 0;
    let v = $("#video");
    effects = [{
        name: "Normal",
        effect: (p) =&gt; {
            let v;
            p.preload = () =&gt; {};
            p.setup = () =&gt; {
                v = p.select("#video");
                if (p.select("#canvas") === null) p.createCanvas(v.width, v.height).id("#canvas");
                else {
                    p.select("#canvas").remove();
                    p.createCanvas(v.width, v.height).id("#canvas");
                }
                p.pixelDensity(1);

            };
            p.draw = () =&gt; {
                p.background(51);
                p.translate(p.width, 0);
                p.scale(-1, 1);
                p.loadPixels();
                for (let y = 0; y &lt; p.height; y++) {
                    for (let x = 0; x &lt; p.width; x++) {
                        let i = (x + y * p.width) * 4,
                            r = v.pixels[i + 0],
                            g = v.pixels[i + 1],
                            b = v.pixels[i + 2],
                            rb = (r + g + b) / 3;
                        p.pixels[i + 0] = rb;
                        p.pixels[i + 1] = rb;
                        p.pixels[i + 2] = rb;
                        p.pixels[i + 3] = 255;
                    }
                }
                p.updatePixels();

            };
        }
    }];
    navigator.mediaDevices.getUserMedia({
            audio: false,
            video: {
                mandatory: {
                    minWidth: v.width(),
                    minHeight: v.height(),
                    maxWidth: v.width(),
                    maxHeight: v.height()
                }
            }
        })
        .then(stream =&gt; {
            v.attr({
                "src": window.URL.createObjectURL(stream),
                "autoplay": "true"
            });
        })
        .catch(err =&gt; {
            console.error(err);
        });
     new p5(effects[0].effect);
});
</code></pre>
]]></description>
   </item>
   <item>
      <title>Close GetCapture Video Stream</title>
      <link>https://forum.processing.org/two/discussion/17005/close-getcapture-video-stream</link>
      <pubDate>Mon, 06 Jun 2016 08:03:25 +0000</pubDate>
      <dc:creator>jfred1979</dc:creator>
      <guid isPermaLink="false">17005@/two/discussions</guid>
      <description><![CDATA[<p>Using getCapture to show web cam input.... I want to clean up the sketch after I am done, how do I close the stream?</p>
]]></description>
   </item>
   <item>
      <title>Getting a single frame from the webcam instead of continuous stream + saving those frames in a list</title>
      <link>https://forum.processing.org/two/discussion/15965/getting-a-single-frame-from-the-webcam-instead-of-continuous-stream-saving-those-frames-in-a-list</link>
      <pubDate>Mon, 11 Apr 2016 15:17:46 +0000</pubDate>
      <dc:creator>Ders</dc:creator>
      <guid isPermaLink="false">15965@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to create a simple web application that a user can take a picture with using their webcam. At the moment I have everything figured out so that the webcam is constantly streaming the video to the canvas but I want it to save a "frame" to the app instead. Is this possible? If so, how do I do this? Also, I want to save these images in an array for now. I've tried using array.push() on the timing I want to take a picture (using mouseReleased) but that gives me an array of video streams from the webcam.</p>
]]></description>
   </item>
   <item>
      <title>video capture running on chrome issue</title>
      <link>https://forum.processing.org/two/discussion/14965/video-capture-running-on-chrome-issue</link>
      <pubDate>Wed, 17 Feb 2016 06:16:10 +0000</pubDate>
      <dc:creator>liquid</dc:creator>
      <guid isPermaLink="false">14965@/two/discussions</guid>
      <description><![CDATA[<p>since the new chrome remove the getUserMedia, is there anyway to work around with this? if my server site without support https yet. not too sure about safari,firefox(version 44.02） not working on moible device， the edge browser working though</p>
]]></description>
   </item>
   <item>
      <title>record and save video with p5.js</title>
      <link>https://forum.processing.org/two/discussion/13186/record-and-save-video-with-p5-js</link>
      <pubDate>Thu, 22 Oct 2015 19:14:35 +0000</pubDate>
      <dc:creator>slegroux</dc:creator>
      <guid isPermaLink="false">13186@/two/discussions</guid>
      <description><![CDATA[<p>Hi, is there a simple way to record and save video captured with createCapture(Video) in p5.js</p>
]]></description>
   </item>
   <item>
      <title>Render an Image over a live video capture</title>
      <link>https://forum.processing.org/two/discussion/12511/render-an-image-over-a-live-video-capture</link>
      <pubDate>Tue, 15 Sep 2015 03:19:58 +0000</pubDate>
      <dc:creator>mokargas</dc:creator>
      <guid isPermaLink="false">12511@/two/discussions</guid>
      <description><![CDATA[<p>Hey all, new to Processing/P5.js</p>

<p>I'm trying to render a PNG over a live video capture that is using clmtracker (3rd party face tracking js). Code is below.</p>

<p>I get an error:</p>

<p><em>Uncaught TypeError: Cannot read property '_imageMode' of undefined</em> (On line 19413 of p5.js).</p>

<p>Am I approaching this wrong? Note: I can see the png is loaded in Chrome's Network tools.</p>

<pre><code>&lt;html&gt;

  &lt;head&gt;
    &lt;script src="bower_components/clmtrackr/clmtrackr.js"&gt;&lt;/script&gt;
    &lt;script src="bower_components/clmtrackr/models/model_pca_20_svm.js"&gt;&lt;/script&gt;
    &lt;script src="bower_components/p5.js/lib/p5.js"&gt;&lt;/script&gt;
    &lt;script src="bower_components/p5.js/lib/addons/p5.dom.js"&gt;&lt;/script&gt;
    &lt;script&gt;
        var ctracker;
        var img;
      function setup() {

        img = loadImage("/src/images/watermark.png"); 

        // setup camera capture
        var videoInput = createCapture();
        videoInput.size(400, 300);
        videoInput.position(0, 0);

        var cnv = createCanvas(400, 300);
        cnv.position(0, 0);

        //Tracker
        ctracker = new clm.tracker();
        ctracker.init(pModel);
        ctracker.start(videoInput.elt);
        noStroke();
      }
      function draw() {
        clear();

        // Get face marker positions
        var positions = ctracker.getCurrentPosition();

        //Render watermark        
        image(img, 0, 0);

        for (var i=0; i&lt;positions.length; i++) {
            var x = positions[i][0];
            var y = positions[i][1];
            console.log('x:'+x+' y:'+y);
        }
      }
    &lt;/script&gt;

    &lt;style&gt; body { padding: 0; margin: 0} &lt;/style&gt;

  &lt;/head&gt;

  &lt;body&gt;
  &lt;/body&gt;

&lt;/html&gt;
</code></pre>
]]></description>
   </item>
   <item>
      <title>Understanding pixel density</title>
      <link>https://forum.processing.org/two/discussion/12556/understanding-pixel-density</link>
      <pubDate>Thu, 17 Sep 2015 04:12:40 +0000</pubDate>
      <dc:creator>joySeeing</dc:creator>
      <guid isPermaLink="false">12556@/two/discussions</guid>
      <description><![CDATA[<p>I have this basic code that displays a grid of squares inside your browser. There is actually a square inside of each square.</p>

<p>Each inner square color takes the color of a corresponding pixel from a webcam feed. The outer square color was basically what the inner square color was last frame.</p>

<p>I use loadPixels() on the webcam to get the array and loop through each square object. It contains an x,y coordinate to take from the webcam feed.</p>

<p>I attempt to parse pixels correctly but for some reason I end up with only half of my image. I've tried many different values for pixel density but none seem to get everything. I don't even know the pixel density of the web cam feed definitely. 1. How do you determine this? 2. What am I doing wrong?</p>

<p>Here is the retrieval code:</p>

<pre lang="javascript">
function updateAndDisplaySquares() {
    var d = 4; // not sure if that number is correct...
    var w = capture.width;
    capture.loadPixels();
    for (var i = 0; i &lt; squares.length; i++) {
        var x = squares[i].xCoordToGetFromCam;
        var y = squares[i].yCoordToGetFromCam;
        var c = [capture.pixels[(y*w*d+x)*d],
                 capture.pixels[(y*w*d+x)*d+1],
                 capture.pixels[(y*w*d+x)*d+2],
                 capture.pixels[(y*w*d+x)*d+3]];
        squares[i].update(c);
        squares[i].display();
    }
}
</pre>

<p>The full code...</p>

<p>EDIT: deleted bugged line</p>

<pre lang="javascript">
var capture;
var innerSquareSizePercent = 0.50;
var transparancyOfInnerSquare = 0.75;
var camWidth;
var camHeight;
var arrayOfDivisibles;
var currentDivisibleIndex; // which item in the array
var squares; // contains many Square class objects

function setup() {
    createCanvas(windowWidth, windowHeight);
    frameRate(30);
    console.log("window height is: " + windowHeight)

    capture = createCapture(VIDEO);
    capture.size(320, 240); // 320, 240
    capture.hide();
    camWidth = capture.width;
    camHeight = capture.height;

    arrayOfDivisibles = getDivisibleIntegers(camWidth, camHeight);
    currentDivisibleIndex = arrayOfDivisibles.length - 1;

    reconfigure();
}

function draw() {
    background(255);

    updateAndDisplaySquares();

    displayFrameRate();
}

function displayFrameRate() {
    var fr = Math.round(frameRate());
    fill(127, 80);
    textSize(20);
    text(fr, 20, 20);
}

function updateAndDisplaySquares() {
    var d = 4;
    var w = capture.width;
    capture.loadPixels();
    for (var i = 0; i &lt; squares.length; i++) {
        var x = squares[i].xCoordToGetFromCam;
        var y = squares[i].yCoordToGetFromCam;
        var c = [capture.pixels[(y*w*d+x)*d],
                 capture.pixels[(y*w*d+x)*d+1],
                 capture.pixels[(y*w*d+x)*d+2],
                 capture.pixels[(y*w*d+x)*d+3]];
        // basically, we pass in the array, which is a slice of the giant pixels array.
        // This slice contains the desired pixel color in the form of an array.
        squares[i].update(c);
        squares[i].display();
    }
}

// square class
function Square(iSL, iX, iY) {
    this.sideLength = iSL;
    this.x = iX;
    this.y = iY;
    this.innerSideLength = this.sideLength * innerSquareSizePercent;
    this.offset = (this.sideLength - this.innerSideLength) / 2;
    this.innerX = this.offset + this.x;
    this.innerY = this.offset + this.y;
    this.squareCenterX = this.x + (this.sideLength / 2);
    this.squareCenterY = this.y + (this.sideLength / 2);
    this.xCoordToGetFromCam = Math.round((this.x * camWidth) / width);
    this.yCoordToGetFromCam = Math.round((this.y * camHeight) / height);
    this.c = color(255, 255, 255);
    this.previousColor = (255, 255, 255);

    this.update = function(col) {
        this.previousColor = this.c;
        this.c = col;
    }

    this.display = function() {
        noStroke();

        // outer
        fill(this.previousColor);
        rect(this.x, this.y, this.sideLength, this.sideLength);

        // inner
        fill(this.c, transparancyOfInnerSquare);
        rect(this.innerX, this.innerY, this.innerSideLength, this.innerSideLength);
    }
}

// gets divisible integers of the width and height
function getDivisibleIntegers(int1, int2) {
    var arr = [];
    var i;
    if (int1 &gt; int2) {
        for (i = 3; i &lt; int1; i++) {
            if (int1 % i === 0) {
                if (int2 % i === 0) {
                    arr.push(i);
                }
            }
        }
    }

    if (int2 &gt; int1) {
        for (i = 3; i &lt; int2; i++) {
            if (int2 % i === 0) {
                if (int1 % i === 0) {
                    arr.push(i);
                }
            }
        }
    }
    return arr;
}

function reconfigure() {
    squares = []; //# should this be  [] or {}?
    var squareSize = arrayOfDivisibles[currentDivisibleIndex];
    var numXSquares = Math.round(width / squareSize);
    var numYSquares = Math.round(height / squareSize);
    var numberOfSquares = numXSquares * numYSquares;

    console.log("num x squares is: " + numXSquares)
    console.log("num y squares is: " + numYSquares);

    for (var i = 0; i &lt; numXSquares; i++) {
        for (var j = 0; j &lt; numYSquares; j++) {
            var squareTopLeftX = i * squareSize;
            var squareTopLeftY = j * squareSize;
            var square = new Square(squareSize, squareTopLeftX, squareTopLeftY);
            squares.push(square);
        }
    }

    console.log("number of squares is: " + squares.length)
    console.log(squares)

}
</pre>
]]></description>
   </item>
   <item>
      <title>How to pixelise video capture combining "Video Pixel" and "Video Capture"?</title>
      <link>https://forum.processing.org/two/discussion/9207/how-to-pixelise-video-capture-combining-video-pixel-and-video-capture</link>
      <pubDate>Tue, 27 Jan 2015 20:08:27 +0000</pubDate>
      <dc:creator>cklkaren</dc:creator>
      <guid isPermaLink="false">9207@/two/discussions</guid>
      <description><![CDATA[<p>Hello all,</p>

<p>I am very green on p5.js and I would like to pixelise a video capture with the examples given in the website below respectively:
<a rel="nofollow" href="http://p5js.org/learn/examples/Dom_Video_Pixels.php">Video Pixel</a>
<a rel="nofollow" href="http://p5js.org/learn/examples/Dom_Video_Capture.php">Video Capture</a></p>

<p>I have tried to code them but it doesn't work. Can anyone give me some advice please?
Below is the code I have got:</p>

<blockquote class="Quote">
  <p>var capture;
  var circles;</p>
  
  <p>function setup() {
    createCanvas(390, 240);
    capture = createCapture(VIDEO);
    capture.size(320, 240);
    circles = createVideo(capture);
    circles.loop();
    circles.hide();
  /*   capture.hide(); */
  }</p>
  
  <p>function draw() {
    background(255);
    image(capture, 0, 0, 320, 240);
    filter('INVERT');
  <br />
    circles.loadPixels();
    for (var i=0; i&lt;circles.pixels.length/2; i++) {
      circles.pixels[i] = random(255);
    }
    circles.updatePixels();
    image(circles, 0, 0, 320, 240);
  }</p>
</blockquote>

<p>Cheers!</p>
]]></description>
   </item>
   </channel>
</rss>