# Can't read pixels from capture

**URL:** <https://discourse.processing.org/t/cant-read-pixels-from-capture/13245>\
**Category:** Coding Questions\
**Created:** [August 8, 2019, 3:14am UTC](https://discourse.processing.org/t/cant-read-pixels-from-capture/13245 "2019-08-08T03:14:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshuajenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/joshuajenkins/32/5524_2.png) [@joshuajenkins](https://discourse.processing.org/u/joshuajenkins)\
**Post date:** [August 8, 2019, 3:14am UTC](https://discourse.processing.org/t/cant-read-pixels-from-capture/13245/1 "2019-08-08T03:14:00Z")

</div>

Hi,

I’m obviously missing something foundational. But at the moment I’m trying to simply get the pixels array from a video capture. My code sample follows, note this is on up-to-date versions Chrome and MacOS.

```auto
let capture;

function setup() {
	let canvas = createCanvas(1024, 1024);
	canvas.parent('canvas');

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

function draw() {
	background(0, 0, 0);

	if (capture.loadedmetadata) {
		capture.loadPixels();
		console.log(capture.pixels);
	}
}

```

I get the following error in my console after a couple beats on reload:

```auto
p5.min.js:3 Uncaught TypeError: Cannot read property '_pixelsDirty' of undefined
    at p5.MediaElement.c.Renderer2D.loadPixels (p5.min.js:3)
    at p5.MediaElement.loadPixels (p5.dom.js:2566)
    at draw (webcam.js:17)
    at h.i.redraw (p5.min.js:3)
    at h.<anonymous> (p5.min.js:3)

```

I’ve tried a bunch of variants of the above (largely borrowed from [this example](https://p5js.org/examples/dom-video-pixels.html) on the docs as well as the more basic createCapture example.) All I want is the pixels in an array so I can play with them. Any help would be greatly appreciated.

Here’s my (extremely minimal) html just for completeness. The code above is in webcam.js. The local versions of p5…js are up to date downloads from the website as of today.

```auto
<!doctype html>
<html>
<head>
<title>webcam</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="p5.min.js"></script>
<script src="p5.dom.js"></script>
<script src="webcam.js"></script>
</head>

<body>
	<div id="canvas"></div>
</body>
</html>

```

Thanks for taking a look!

---

<div class="post-metadata">

**Author:** ![joshuajenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/joshuajenkins/32/5524_2.png) [@joshuajenkins](https://discourse.processing.org/u/joshuajenkins)\
**Post date:** [August 8, 2019, 4:10am UTC](https://discourse.processing.org/t/cant-read-pixels-from-capture/13245/2 "2019-08-08T04:10:55Z")

</div>

This appears to be a bug with the version of p5js I was using (/\*! p5.js v0.9.0 July 01, 2019 \*/). I found a video example here: [https://editor.p5js.org/codingtrain/sketches/B1L5j8uk4](https://editor.p5js.org/codingtrain/sketches/B1L5j8uk4) and used the same p5js import and things started working.

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [August 8, 2019, 4:53am UTC](https://discourse.processing.org/t/cant-read-pixels-from-capture/13245/3 "2019-08-08T04:53:19Z")

</div>

Your code works fine for me with v0.9.0 on linux in firefox. I know there was a [bug in 0.7.2](https://github.com/processing/p5.js/issues/3549) that should have been fixed in 0.8.0.

Looks like it might be worth filing an issue. If the problem is in the latest version (0.9.0).
