gfletch
Posts: 13
Joined: Tue Nov 20, 2012 1:04 pm

Taking images from 2 webcams

Sun Dec 02, 2012 4:37 pm

Hi

I am running Motion on my RPI but I would like to move away from motion capture and run a script to capture images, the reason being I would like to use one camera with Motion, when activated I would like to

1. turn off the Motion daemon (deactivate camera 1),
2. activate camera 1 and take a snapshot then
3. activate camera 2 and take a snapshot (within miliseconds of each other).

The purpose being obtaining a stereo image.. L & R cameras

Is this feasible, does anyone have any ideas/pointers as to where to start?

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Taking images from 2 webcams

Sun Dec 02, 2012 6:52 pm

Did you already try it with ONE webcam ?
Before you spend a lot on this I would thoroughly test this setup.


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

gfletch
Posts: 13
Joined: Tue Nov 20, 2012 1:04 pm

Re: Taking images from 2 webcams

Sun Dec 02, 2012 7:18 pm

this works

Code: Select all

#!/bin/bash

uvccapture -o/img/L.jpg -d/dev/video0 -m -w
uvccapture -o/img/R.jpg -d/dev/video1 -m -w
but is a little slow because the cameras are not initialised...

if I run this in 2 termial ssh windows it works better

Code: Select all

sudo uvccapture -v -oR.jpg -d/dev/video0 -m -t1

Code: Select all

sudo uvccapture -v -oL.jpg -d/dev/video1 -m -t1

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Taking images from 2 webcams

Sun Dec 02, 2012 7:22 pm

So what's the speed ? If it's too slow , you'll perhaps have to use
a C solution using the V4L API or something. But i don't think
that's a guarantee for sucess.


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: Taking images from 2 webcams

Sun Dec 02, 2012 8:32 pm

why can't you spawn two background copies by tagging an & on the end of the commands in a shell script? there will still be the microscopic delay as the shell interpreter reads the lines but it will be mighty close, in fact you only need to shove the first call into the background

Code: Select all

#!/bin/bash
uvccapture -o/img/L.jpg -d/dev/video0 -m -w &
uvccapture -o/img/R.jpg -d/dev/video1 -m -w
I'm sure there's a way to make a shell script wait for spawned background jobs to complete, can't remember right now
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

gfletch
Posts: 13
Joined: Tue Nov 20, 2012 1:04 pm

Re: Taking images from 2 webcams

Sun Dec 02, 2012 8:54 pm

using the & makes only a 0.2 millisecond difference...

this is at low res 320x240

I do appreciate its actually not bad, but is they any room for improvement on that?

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: Taking images from 2 webcams

Sun Dec 02, 2012 9:00 pm

so you need a 'blocking command' of some sort where you spawn the pair and they both execute at c.the same time when unblocked - i'm sure there's a way without have to resort to C ...

But this IS super trivial in C using the fork() command
if you simply trap the result fork() and if zero execute one thing system("uvcapture .... device1") if not the other system("uvcapture .... device2")

Code: Select all

pid_t pid;
     
  pid = fork ();
  
  if(pid == 0)
  {
    /* This is the child process */
    system("uvcapture .... device1");  // execute the command
    // we call exit() when system() returns to complete child process
    exit(EXIT_SUCCESS);
  }

  else if(pid > 0)
  {
    /* This is the original process */
    system("uvcapture .... device2");  // execute the command
    // we call exit() when system() returns to complete main process
    exit(EXIT_SUCCESS);
  }
They should execute at identical times
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

Return to “General programming discussion”