Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Webcam Streaming Using Raspberry Pi and Java

DZone's Guide to

Webcam Streaming Using Raspberry Pi and Java

· IoT Zone
Free Resource

Cisco IoT makes digital transformation a reality in factories, transportation, and utilities. Learn how to start integrating with Cisco DevNet.

There are lots of devices in the market that allows monitoring home remotely from a central interface which are very expensive. Tech lovers can now own their inexpensive security systems with the tiny super computer called Raspberry Pi. Instead of using the traditional wireless CCTV surveillance cameras, IP cameras can serve better as they can send and receive data via computer network and internet based on internet protocol. Also resolution clarity of IP cameras is far better than CCTV cameras. With the increasing rate of larcenies it might be smart to invest on a Raspberry Pi controlled security system. A webcam connected to the Raspberry Pi will records all the happenings in the monitored area and live streaming can be viewed from any browser. This blog will explains the procedure for setting up webcam streaming using Raspberry Pi.

 Hardware Essentials:


  • Webcam (I used Logitech c110)
  • Raspberry Pi Model B                                     
  • Power Supply for Raspberry Pi (Mobile Charger will suffice)
  • Ethernet Cable/ WIFI Dongle (I used Ethernet cable)


Software Requirements:


  • Raspbian OS
  • Motion Library


Steps for connecting Webcam to Raspberry Pi:


  • Install Raspbian operating system on Raspberry Pi
  • Install motion library by inputting the following command from terminal 
    • sudo apt-get install motion
  • Ensure that the webcam connected is Raspberry Pi compatible. To check that run the below command from terminal
    • Lsusb
  • Then the camera connected to pi should be listed as a USB device like this
    • Bus 001 Device 006: ID 046d:0825 Logitech, Inc. Webcam C110  (If not detected, then the webcam connected is not Raspberry Pi compatible
  • Motion library has a configuration file where in one can define parameters such as the port number which motion will run on, actions to be triggered when motion is detected
  • Edit the motion configuration file using nano editor
    • sudo nano /etc/motion/motion.conf
  • Below are the parameters that needs to be configured:
    • daemon: set to ON to start motion as a daemon service when pi boots
    • webcam_localhost: set to OFF so that one can access motion from other computers
    • webcam_port : the port for the video stream (default 8081)
      • e.g.:  webcam_port:8089
    • control_localhost: set to OFF to be able to update parameters remotely via the web config interface
    • control_port: the port that will allow access to the web config interface (default 8080)
      • e.g.: control_port:8088
    • framerate: number of frames per second to be captured by the webcam. Warning: setting above 5 fps will hammer pi’s performance
  • To run motion as a daemon service, edit the following file
    • sudo nano /etc/default/motion
  • Set start_motion_daemon to YES
  • Now everything is set up and to start the service type
    • sudo service motion start
  • Wait for couple of seconds for motion to start and open the streaming in browser by typing
    •  raspberrypi_IP: webcam_port
  • Let us suppose Raspberry Pi IP address is 10.211.22.22, streaming can be viewed from browser by using http://10.211.22.22:8089. This streaming can also be used in web applications by putting the streaming in a simple <img> tag like <img src="http://10.211.22.22:8089">




Cisco is a software company. Surprised? Don’t be. Join DevNet to explore APIs, tools, and techniques that developers are using to add collaboration, IoT, security, network priority, and more!

Topics:
java ,opinion ,cloud ,iot ,webcam ,internet of things ,raspberry pi model b

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}