# Processing, raspberry pi and camera

**URL:** <https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027>\
**Category:** Processing for Pi\
**Created:** [July 23, 2018, 9:16pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027 "2018-07-23T21:16:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [July 23, 2018, 9:16pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/1 "2018-07-23T21:16:27Z")

</div>

Hi everyone,

For my project on building a [universal ambilight system](https://discourse.processing.org/t/a-universal-ambilight/1962/2), I need to access the data from a camera plug into my raspberry Pi.

at first I couldn’t even find a camera from processing with the video library so I looked for answers and found this command line:  
`sudo modprobe bcm2835-v4l2`

Now processing is insulting me with that warning message:  
`No such Gstreamer factory: v4l2src`

After more digging, I found out that 2 experimental libraries exist (on [this page](https://github.com/processing/processing-video/issues/23)) and can fix the problem :

- this [experimental video library](https://github.com/processing/processing-video/tree/gst1-java-core) for processing made by Andres Colubri (alias codeanticode)
- One made by @gohai but the link is now broken

Before trying one of those solutions, since they are experimental, I would like to know if one of you would know a way to make it work with the official library?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![gohai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gohai/32/25_2.png) [@gohai](https://discourse.processing.org/u/gohai)\
**Post date:** [July 23, 2018, 9:32pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/2 "2018-07-23T21:32:42Z")

</div>

Hi @jb4x,

See here about your `v4l2src` error: [https://pi.processing.org/technical/#video-library-capture](https://pi.processing.org/technical/#video-library-capture)

The GL Video library was specifically written for the Raspberry Pi - you find it in the Processing Contribution Manager. Apart from this, there is also the current release of the “official” Video library, which I believe you are trying out right now, and an experimental pre-release version, which uses a much more modern GStreamer version - both developed by Andres.

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [July 24, 2018, 6:08am UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/3 "2018-07-24T06:08:29Z")

</div>

Thank you for your reply @gohai!

I followed the instructions of your link and try to execute this commande:  
`sudo aptitude install gstreamer0.10-plugins-good`

Sadly, it’s back to were I was at the beginning: no camera found ☹

I think I’ll try your library, I did not see it was available from the library manager of processing. And it seems that it works almost the same as the “official” video library so I should not have big changes in my code (hopefully 😃).

Thanks again, and I’ll let you know how it goes 🙂

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 24, 2018, 6:24am UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/4 "2018-07-24T06:24:05Z")

</div>

> [@jb4x](#):
>
> And it seems that it works almost the same as the “official” video library…

A noteworthy feature that hasn’t been mirrored is the lacking of callbacks like **movieEvent()**. 😞

Although both lack some kinda **eosEvent()** callback! 🙄

---

<div class="post-metadata">

**Author:** ![gohai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gohai/32/25_2.png) [@gohai](https://discourse.processing.org/u/gohai)\
**Post date:** [July 24, 2018, 4:19pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/5 "2018-07-24T16:19:55Z")

</div>

I remember you bringing this up before @GoToLoop - remind me: why would you want to use movieEvent?

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [July 24, 2018, 4:28pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/6 "2018-07-24T16:28:21Z")

</div>

@gohai, I don’t think it was me, I don’t need any movieEvent() callback for my use.

The most similar subect I opened I can think of is when I asked how to link a function to the press event of a button (of the controlP5 library) located in another class:

> [@Connect a function to a button created in an object (ControlP5)](https://discourse.processing.org/t/connect-a-function-to-a-button-created-in-an-object-controlp5/1821/7):
>
> [http://www.Sojamo.de/libraries/controlP5/reference/controlP5/Controller.html#plugTo-java.lang.Object-java.lang.String-](http://www.Sojamo.de/libraries/controlP5/reference/controlP5/Controller.html#plugTo-java.lang.Object-java.lang.String-) // https://Discourse.processing.org/t/ // connect-a-function-to-a-button-created-in-an-object-controlp5/1821/7 // https://GitHub.com/sojamo/controlp5/blob/master/examples/extra/ // ControlP5ControllerInsideClass/ControlP5ControllerInsideClass.pde // GoToLoop (2018/Jul/16) import controlP5.ControlP5; ControlP5 cp5; Interface i; void setup() { size(300, 200); i = new I…

---

<div class="post-metadata">

**Author:** ![gohai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gohai/32/25_2.png) [@gohai](https://discourse.processing.org/u/gohai)\
**Post date:** [July 24, 2018, 4:30pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/7 "2018-07-24T16:30:17Z")

</div>

Sorry, this was indeed meant to go to @GoToLoop.

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [July 24, 2018, 4:32pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/8 "2018-07-24T16:32:33Z")

</div>

No problem 🙂

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 24, 2018, 5:26pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/9 "2018-07-24T17:26:13Z")

</div>

> [@gohai](#):
>
> Why would you want to use **movieEvent()**?

I don’t like to have a boilerplate in **draw()** checking over & over whether a new frame is **available()** in order to call **read()**. 🤢

It also wastes CPU time on the main “Animation” Thread. Better leave that to Movie’s Thread. 😉

Also lotsa Processing 3rd-party libraries got reflection callbacks, even official 1s like Serial & Net: 🤠

1. [Serial / Libraries / Processing.org](http://Processing.org/reference/libraries/serial/index.html)
2. [Network / Libraries / Processing.org](http://Processing.org/reference/libraries/net/index.html)

Given GL Video is a custom version of the Video library, the reflection callback code is pretty easy to port! 😀

As I had already mentioned, the Video library sorely lacks an EoS callback. 😷

I’ve made a sketch which `@Override` the Movie::**eosEvent()** method so it calls back a sketch’s function: 🤡

- [Movie begin and end events - Processing 2.x and 3.x Forum](http://Forum.Processing.org/two/discussion/14990/movie-begin-and-end-events#Item_1)

But it’d be much nicer to have that feature builtin rather than relying on some hack! 🤖

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [July 24, 2018, 5:34pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/10 "2018-07-24T17:34:09Z")

</div>

@gohai,

I tried out your library on my raspberry with the simpleCapture exemple you have provided but I’m getting hard times displaying the camera feed.

I updated the /etc/modules file and after reboot, I can see the camera device as /dev/video0. So everything should be setup correctly.

When I run the sketch, the camera is found, the light of the camera turned on, but the render window stays black.

Any idea from where it can come from?

---

<div class="post-metadata">

**Author:** ![gohai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gohai/32/25_2.png) [@gohai](https://discourse.processing.org/u/gohai)\
**Post date:** [July 24, 2018, 5:49pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/11 "2018-07-24T17:49:21Z")

</div>

@GoToLoop The issue with callbacks is that you’re only allowed to draw to the screen during certain periods of the frame cycle. When you attempt to do so outside when you’re supposed to do so the sketch will generally crash. This is why I don’t do a `MovieEvent` - because it is safer to do so inside draw, and folks will most likely want to do some compositing (additional drawing) anyhow.

---

<div class="post-metadata">

**Author:** ![gohai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gohai/32/25_2.png) [@gohai](https://discourse.processing.org/u/gohai)\
**Post date:** [July 24, 2018, 5:51pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/12 "2018-07-24T17:51:01Z")

</div>

@jb4x That’s odd. Are you using our modified Raspbian image? Did you perhaps change the graphics driver setting (away from the default “Legacy”)?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 24, 2018, 6:33pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/13 "2018-07-24T18:33:55Z")

</div>

> [@gohai](#):
>
> The issue with callbacks is that you’re only allowed to draw to the screen during certain periods of the frame cycle.

A feature should not be withheld just b/c it would be misused somehow! 🙊

A callback isn’t a place to do heavy stuff after all; merely to reckon it’s happened. 😳

It is well known that we shouldn’t mutate the sketch’s canvas outside its “Animation Thread”. ⚠

Even though you’re “protecting” us from the “Animation Thread” crash in your custom GL Video library, folks are still gonna learn that from the other Processing 3rd-party libraries; so it’s moot!

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [July 24, 2018, 6:44pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/14 "2018-07-24T18:44:58Z")

</div>

> [@gohai](#):
>
> @jb4x That’s odd. Are you using our modified Raspbian image? Did you perhaps change the graphics driver setting (away from the default “Legacy”)?

I’ll re-install the rasbian image (I’ll take the one on [pi.processing.org](http://pi.processing.org)), cleanly re-do everything and see how it goes. I’ll let you know!

---

<div class="post-metadata">

**Author:** ![gohai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gohai/32/25_2.png) [@gohai](https://discourse.processing.org/u/gohai)\
**Post date:** [July 24, 2018, 6:58pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/15 "2018-07-24T18:58:04Z")

</div>

@GoToLoop If you’re unable to draw in the callback, but merely set a flag, and act upon it in a future invocation of `draw` - how is this “better” than just directly checking `available()` inside `draw` and acting upon that?

I want users, especially beginners, to have a rewarding time using this library. I am not convinced that everyone would know about the concept of the “Animation Thread”, or what is - and what _isn’t_ - a reasonable thing to do inside a callback handler.

And since I don’t see a real upside, I rather prevent people from shooting themselves in the foot with the tools I build. (But it’s open source, so you are of course welcome to build upon my work and prove me wrong.)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 24, 2018, 7:24pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/16 "2018-07-24T19:24:00Z")

</div>

> [@gohai](#):
>
> How is this “better” than just directly checking `available()` inside `draw()` and acting upon that?

Already gave the reason for that: 🙎‍♂️

> [@GoToLoop](#):
>
> I don’t like to have a boilerplate in **draw()** checking over & over whether a new frame is **available()** in order to call **read()**.

I just find this:

```auto
void draw() {
  set(0, 0, myMovie);
}

void movieEvent(final Movie m) {
  m.read();
}

```

Better & cleaner than this:

```auto
void draw() {
  if (!myMovie.available()) return;
  myMovie.read();
  set(0, 0, myMovie);
}

```

> [@gohai](#):
>
> I want users, especially beginners, to have a rewarding time using this library.

Given **movieEvent()** is 100% optional, that’s no excuse to have it removed when you forked GL Video from the Video library!

And again, threaded callbacks exist everywhere in Processing’s 3rd-party lib ecosystem.

> [@gohai](#):
>
> But it’s open source, so you are of course welcome to build upon my work and prove me wrong.

Given the Video library got that feature already, it’s pointless to fork yours just to put the callbacks back! 😉

---

<div class="post-metadata">

**Author:** ![gohai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gohai/32/25_2.png) [@gohai](https://discourse.processing.org/u/gohai)\
**Post date:** [July 24, 2018, 7:31pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/17 "2018-07-24T19:31:31Z")

</div>

Just because something exists elsewhere doesn’t mean you have to copy it, if you think it is wrong. Please be considerate in the language you use, I don’t think I need to explain (or excuse) myself for any code I write or publish.

```auto
void movieEvent(final Movie m) {
  m.read();
  draw(m, 0, 0);
}

```

What would prevent someone from doing that (and have it explode at the least convenient time)?

Anyway, I think we’ve circled this issue enough here.

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [July 24, 2018, 8:18pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/18 "2018-07-24T20:18:47Z")

</div>

Ok, so…

I re-installed raspbian using the image provided by [pi.processing.org](http://pi.processing.org) and I check that I was not using the KMS OpenGL driver but I still have the same problem: when I run the basic sketch, the camera is found, apparently it is turned on since I can see the LED but no image is displayed…

Can it be a power supply issue? I’m feeding the Pi with a 5.0V 2.1A and I know it should be 2.5A… ?

---

<div class="post-metadata">

**Author:** ![gohai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gohai/32/25_2.png) [@gohai](https://discourse.processing.org/u/gohai)\
**Post date:** [July 24, 2018, 8:54pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/19 "2018-07-24T20:54:23Z")

</div>

@jb4x Sorry, I don’t know what’s going on then. I’ll have to get my camera from the studio and test.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [July 24, 2018, 9:18pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/20 "2018-07-24T21:18:10Z")

</div>

Is there a way to pass custom pipelines into either of these libraries? IIRC there’s a specific GStreamer element for the Pi camera. Might be worth trying

@GoToLoop the callback is actually a really bad part of the video API anyway, complicates things and reduces the possibility for performance improvements. I tried to replicate the API in PraxisLIVE and gave up for another mechanism - it doesn’t map well to the underlying library IMO.

[Next page](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027.md?page=2)
