Turn on your Raspberry Pi, open a terminal window, connect the webcam into the USB port and enter the following command that will list all the USB devices that are being connected.
lsusb
you should see your camera listed as a usb device, for exampleBus 001 Device 006: ID 0c45:602c Microdia Clas Ohlson TWC-30XOP Webcam
if webcam is not in the list then you are not lucky, your webcam is not compatible with Raspberry Pi. If your Webcam is compatible, you can try to take some pictures to verify its functionality by installing fswebcam software.
sudo apt-get install fswebcam
Now run this command to capture a picture from the USB Webcam and save it as testimage.jpg
fswebcam testimage.jpg
You can run fswebcam with many switches, type the following command to have more options
man fswebcam
That is all! Your webcam setup is complete, but if you want experiment more with your webcam continue to read. Now we will install another very useful software to stream the video signal via web interface. The program name is "Motion" and you can read all the documentation here.
apt-get install motion
Now edit two configuration files
sudo nano /etc/default/motion
Change the following value from NO to YES
start_motion_daemon=no
--> start_motion_daemon=yes
Press Ctrl+O to save and type Ctrl+X to exit.
sudo nano /etc/motion/motion.conf
This is quite a large conf file but the points you need to edit are:
daemon on
stream_localhost off
webcontrol_localhost off
############################################################
# Daemon
############################################################
# Start in daemon (background) mode and release terminal (default: off)
daemon on
############################################################
############################################################
# Live Stream Server
############################################################
# Restrict stream connections to localhost only (default: on)
stream_localhost off
##############################################################
############################################################
# HTTP Based Control
############################################################
# Restrict control connections to localhost only (default: on)
webcontrol_localhost off
#############################################################
Press Ctrl+O to save and type Ctrl+X to exit.
Then start the program by typing
sudo service motion start
sudo motion
To see if all is runnging type
sudo netstat -tulpn | grep LISTEN
Ports are showing as listening:
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN
Now get the local IP address of the Raspberry PI with command
ifconfig
On the second line of the resulting text, you find the IP address after "inet addr:" for example 192.168.1.6
Now visit the address http://YourIpAddress
Do you want to make available the display of your webcam directly on the Internet? Follow this tutorial.
Great tutorial.
ReplyDeleteAny tips on how to speed up the response time of the webcam video streaming (for example, by decreasing video quality). I tried overclocking my B+, that didn't seem to help.
Objective is to use webcam for navigation of robotic car.
Thanks so much for this tutorial. I am new to the PI and just starting to programme again. Last did math modelling in Fortran 4 so it was some time ago. Had great fun with some simple programme turning LEDS on an off and came across your tutorial. Followed the instructions and it worked. Thanks a lot
ReplyDeletegood
ReplyDelete