Is it possible to access a USB webcam through Mathmatica on Linux? When I run


I get the following output

ImageCapture::notsupported: Image acquisition is not supported on Unix. >>

A quick search on Google does not return any useful solutions :(


Yes it is possible, but it is not natively supported. Therefore, the way through ImageCapture will not work here. Nevertheless, no one prevents you to use a library like opencv to access the webcam. With a MathLink wrapper you can write a routine to catch frames from the cam and transfer them as Image to Mathematica.

When opencv is initialized and has opened your cam, the pure catching routine is in the simplest case very short:

void catchFrame(void){
  long dims[3],size,mu;
  int *bm;

  bm=new int[mu];
  for(long i=0; i<size; i++) {
    bm[3*i]=(unsigned char)frame->imageData[3*i+2];
    bm[3*i+1]=(unsigned char)frame->imageData[3*i+1];
    bm[3*i+2]=(unsigned char)frame->imageData[3*i];

  delete[] bm;

I admit that this approach is not as simple as calling ImageCapture, but if you are willing to install opencv and cweb I could send you an implementation. It was once written by Jens-Peer Kuska and I only made it work for Mathematica 8.0 and its Image-framework.


I made a pure C version (without CWeb) and added a detailed how-to-use comment. You can download the file from here and with a bit of luck you can use images from your webcam in a few minutes.

| improve this answer | |
  • $\begingroup$ Thanks Patrick. will give it a try and post the results here! $\endgroup$ – Ram Mar 10 '12 at 6:56
  • $\begingroup$ It is unfortunate you still have to do this... still no camera support in v9.0 as well. I'm not a programmer by trade, I'm not even a good programmer; but I've hacked a little code together that used v4l devices (web cam, tuner cards, etc). It really wasn't that hard - you just have to want to do it and read a little documentation. A few hundred lines of code and I had a 3D rotating cube with input from a tuner card playing on each face. I don't think you can even buy a laptop without a camera these days. $\endgroup$ – cjpembo Dec 13 '12 at 23:35
  • 1
    $\begingroup$ The irony is that Wolfram likes to tout v9's face recognition algorithms, improved image processing, etc. Wolfram should just hire someone to write the code for them. Yu-Sung Chang talked about supporting Linux 18 months ago - never happened: blog.wolfram.com/2011/06/23/… $\endgroup$ – cjpembo Dec 13 '12 at 23:35
  • 1
    $\begingroup$ @cjpembo I understand Wolfram here. It's difficult to support hardware like a webcam when there are so many different Linux distributions and systems plus Linux is not the main target system plus there are usually no native drivers for Linux. Everything is only supported though things like opencv. $\endgroup$ – halirutan Dec 14 '12 at 2:40
  • 1
    $\begingroup$ @cjpembo Currently, there are bigger issues to work on. The Documentation Center bugs since version 8. The GUI of the frontend is far from being as nice as on Win or OSX. These are the things you use all the time. $\endgroup$ – halirutan Dec 14 '12 at 2:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.