MohamadCm
Posts: 23
Joined: Wed Jan 14, 2015 6:14 pm

Connect 3 cameras and switch at any time

Wed Jan 14, 2015 6:34 pm

Hi friends,
Right now I'm working on a project that I need to connect three camera to Raspberry-Pi and switch between them at any time,
But I don't now what to do, :roll:
Could you help me please?! :?:

User avatar
DougieLawson
Posts: 37074
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Connect 3 cameras and switch at any time

Thu Jan 15, 2015 12:00 am

What sort of cameras?

If it's the PiCamera on the CSI interface you'll be best off having three separate Raspberry Pis and using a networked connection to synchronise them. With a Compute Module you can run two PiCameras in parallel (for stereo anaglyphs and suchlike), but with a regular A/A+/B/B+ that's not possible.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

gordon77
Posts: 4478
Joined: Sun Aug 05, 2012 3:12 pm

Re: Connect 3 cameras and switch at any time

Thu Jan 15, 2015 7:14 am

You should be able to connect 3 USB webcams, sometime in the past someone posted on here about their system. They should appear as 3 separate entries eg video0/1/2
And be selectable by python etc.


You may also be able to use a pi camera and 2 USB cameras.

MohamadCm
Posts: 23
Joined: Wed Jan 14, 2015 6:14 pm

Re: Connect 3 cameras and switch at any time

Fri Jan 16, 2015 7:56 pm

I didn't meant to switch with OS,I mean't to use an button.surly that's possible but don't know how to do it. :?:

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

Re: Connect 3 cameras and switch at any time

Sat Jan 17, 2015 7:58 am

Since your application becomes nearly impossible without
an OS , you will have to use OS features to implement the
"camera switch" button ...
Do you know any programming language ?


ghabs
• 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

MohamadCm
Posts: 23
Joined: Wed Jan 14, 2015 6:14 pm

Re: Connect 3 cameras and switch at any time

Mon Jan 19, 2015 6:25 pm

ghans wrote:Since your application becomes nearly impossible without
an OS , you will have to use OS features to implement the
"camera switch" button ...
Do you know any programming language ?


ghabs
yep, I know C++ & C# language but this kind of program is beyond my skills,I'm looking for a hardware switch.If there is a way to switch between them with software I'll be glad to do that.

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

Re: Connect 3 cameras and switch at any time

Mon Jan 19, 2015 7:21 pm

Try this example on how to use buttons :
http://hertaville.com/2012/11/18/introd ... gpio-in-c/

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

hoggerz
Posts: 8
Joined: Sun Dec 29, 2013 1:05 am

Re: Connect 3 cameras and switch at any time

Mon Jan 19, 2015 7:23 pm

I saw this kickstarter a while ago which I don't think met its target, but maybe you might be able to contact those that were going to make it if it suits what you wanted to do with actual switching of multiple raspberry pi cameras:

http://hackaday.io/project/2847-ivport- ... ultiplexer

hoggerz

MohamadCm
Posts: 23
Joined: Wed Jan 14, 2015 6:14 pm

Re: Connect 3 cameras and switch at any time

Sat Feb 14, 2015 4:49 pm

OK friends,
I have changed my mind, 8-)
I'm going to use 3 USB cameras,
Can any body help me? :roll:

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

Re: Connect 3 cameras and switch at any time

Sat Feb 14, 2015 5:32 pm

GPIO handling is the same , but be careful to only buy V4L2 compatible webcams:

http://stackoverflow.com/questions/4009 ... le-example

Alternatively only use UVC compatible webcams :
https://github.com/ktossell/libuvc

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

gordon77
Posts: 4478
Joined: Sun Aug 05, 2012 3:12 pm

Re: Connect 3 cameras and switch at any time

Sat Feb 14, 2015 6:12 pm

If you want something simple in python, this will switch between 3 cameras every 5 seconds (settable just change switchtime to required value in seconds).
It's not fast video just regularly updated stills so a few fps.

You can switch to any camera with buttons 1,2 or 3, and switch the auto cycling on/off with button A

It works on my pi B+ and pi2, just plugging in 3 usb cameras.

Code: Select all

import pygame, sys
from pygame.locals import *
import pygame.camera
import time
pygame.camera.init()
pygame.init()
windowSurfaceObj = pygame.display.set_mode((640,480),1,16)
camera = 0
cam = pygame.camera.Camera("/dev/video" +str(camera),(640,480))
cam.start()
auto = "ON"
switchtime = 5
maxcam = 3

x = 0
while x == 0:
   timer = 0
   start = time.time()
   while timer < switchtime:
      if auto == "ON":
         timer = time.time()-start
      windowSurfaceObj.blit(cam.get_image(),(0,0))
      color = pygame.Color(255,0,255)
      fontObj = pygame.font.Font('freesansbold.ttf',16)
      msgSurfaceObj = fontObj.render("Camera: " + str(camera+1)+ " Auto: " + auto, False,color)
      msgRectobj = msgSurfaceObj.get_rect()
      msgRectobj.topleft =(0,0)                                                                                                                                                                                                                                                                                                                                                          
      windowSurfaceObj.blit(msgSurfaceObj, msgRectobj)
      pygame.display.update()
      for event in pygame.event.get():
         if event.type == QUIT:
            pygame.quit()
            sys.exit()
         elif event.type == KEYDOWN:
            kz = event.key
            cam.stop()
            if kz == K_1:
               camera = 0
            if kz == K_2:
               camera = 1
            if kz == K_3:
               camera = 2
            cam = pygame.camera.Camera("/dev/video" + str(camera),(640,480))
            cam.start()
            if kz == K_a:
               if auto == "ON":
                  auto = "OFF"
               else:
                  auto = "ON"
   cam.stop()
   camera = camera + 1
   if camera == maxcam:
      camera = 0
   cam = pygame.camera.Camera("/dev/video" +str(camera),(640,480))
   cam.start()

MohamadCm
Posts: 23
Joined: Wed Jan 14, 2015 6:14 pm

Re: Connect 3 cameras and switch at any time

Tue Apr 07, 2015 7:20 am

Hey guys,
What i was going to do has changed a lot,
Now the board must switch between cameras with a sound command,
That's a lot harder, :cry: :|
What should i do? :roll:

PiGraham
Posts: 3705
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Connect 3 cameras and switch at any time

Tue Apr 07, 2015 7:33 am

What should you do? How about learning to walk before you try to run a marathon. gordon77 kindly gave you some code to switch between cameras. Try that out.

If you now want to switch by "sound command" you can add that. Do you mean "voice command" or "sound"? For the first you could take a look at Jasper or Voice command or search for "raspberry voice command".

If you mean any sufficiently loud sound should trigger a switch then you might get some ideas here http://www.raspberrypi.org/pi-rex-a-bar ... -for-dogs/

gordon77
Posts: 4478
Joined: Sun Aug 05, 2012 3:12 pm

Re: Connect 3 cameras and switch at any time

Tue Apr 07, 2015 8:38 am

Is there a single source of the 'sound' or are you expecting it to switch to a camera where it hears a sound ?

Take a look at something like this...

https://learn.sparkfun.com/tutorials/so ... okup-guide

but you may need to add an interface with the Pi as its not clear what the output GATE voltage is.

PiGraham
Posts: 3705
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Connect 3 cameras and switch at any time

Tue Apr 07, 2015 9:51 am

gordon77 wrote:Is there a single source of the 'sound' or are you expecting it to switch to a camera where it hears a sound ?

Take a look at something like this...

https://learn.sparkfun.com/tutorials/so ... okup-guide

but you may need to add an interface with the Pi as its not clear what the output GATE voltage is.
GATE is shown as 0 to 4.9v on the scope trace on the linked page. It is the output of a lmv324 OPAMP via a 100 Ohm resistor so level shifting should be used - a voltage divider would do.

It should be possible to use the audio channel of a webcam to detect sound level.

See https://docs.python.org/2/library/audio ... udioop.rms
Last edited by PiGraham on Tue Apr 07, 2015 3:03 pm, edited 1 time in total.

gordon77
Posts: 4478
Joined: Sun Aug 05, 2012 3:12 pm

Re: Connect 3 cameras and switch at any time

Tue Apr 07, 2015 12:33 pm

Sounds good :D

If the webcams audios are used then it will need to cycle through them ?

Return to “Camera board”