Instruct

advertisement
Camera Control with Intuitive Smartphone
Interface
Orsolya Szabó
Óbuda University, John von Neumann Faculty of Informatics, Mobile Informatics
Bécsi út 96/B, Budapest, 1034, Hungary
Phone: (36)-(30)-430-3364, orsiszaboo@gmail.com
Abstract – In this paper you will read about the
experiences I earned while making a pan-tilt camera that can
be easily controlled remotely over the internet with a
smartphone.
I. INTRODUCTION
Literature research preceded the entire design process,
but I don’t want to focus on that part. I found that it’s not
common to control surveillance cameras with motion
detection so I decided to investigate the field.
While planning the project I choose to build the camera
part myself over using an existing PT camera with its
interface to gain experience in motor controlling and video
streaming.
II. HARDWARE OF THE TRANSMITTER AND THE RECEIVER
A. Transmitter
The transmitter should be a small, cheap, low-power
consumer device which is capable of video transmitting
over a network. I was considering using a microcontroller
but the low level programming language and the fact that
these are hardly capable of parallel processing hold me
back. So I decided to choose a slightly bigger category and
found a microcomputer, named Raspberry Pi Model B Rev
2 (RPi) what is suitable for the task.
RPi is a computer as big as a credit card, can run from a
battery pack and it use to run a real operating system on an
SD card: some modified Linux distributions (I used Wheezy
Raspbian). So it can easily cope with transmitting the video
and controlling the pan and tilt of it. Furthermore it has
many useful I/O ports like Ethernet or USB 2.0 (for Wifi
sticks e.g.). RPi is commonly used as a media center too
[1.], therefore some video live-stream wouldn’t be a hard
job for it.
The Raspberry Pi is based on a BCM2835 System on a
Chip (SoC) which was originally developed to do lots of
media acceleration for mobile phones. Mobile phone media
systems tend to follow behind desktop systems, but are far
more energy efficient. You can see this efficiency at work in
your Raspberry Pi: to decode H264 video on a standard
Intel desktop processor requires GHz of processing
capability and many (30-40) Watts of power, whereas the
BCM2835 on your Raspberry Pi can decode full 1080p
30fps video at a clock rate of 250MHz, and only burn
200mW. [2.]
B. Camera
For the camera to attach to the RPi there are two
alternatives:
1) Simple USB webcam that is compatible with the RPi,
there is a long list of this kind of cameras on a community
built site [3.].
2) The camera module that is designed for the RPi and
has an unfiltered version that can be used for taking pictures
at night.
To buy a webcam is very risky as it’s not guaranteed to
work properly with the RPi, therefore this project is made
with the use of the Raspberry Pi camera board, the
RaspiCam.
The RaspiCam is connected to the CSi (Camera Serial
interface) of the RPi, capable of 1080p video format using
official software easily.
C. Pan-tilt unit
While planning how to control the camera I found that the
servo motor is usually has a rotation of 180° degrees. PWM
(Pulse Width Modulation) is used to control the motor.
Basically the width of the pulse determines the rotation
angle of the shaft as showed on Fig. I. A cheap micro servo
is used to rotate the camera, that’s operates on ~4.8 Volt
with 0.5-2.5 milliseconds pulse width and 50Hertz.
The RPi has a GPIO (General-Purpose Input/Output) that
has PWM pin, but the problem it has only one. To rotate the
camera over two axes, two PWM pins are needed. To do
this an additional hardware is needed.
Fig. I. PWM control of the Tower Pro SG90 micro servo used in the
project.
The driver connects to the RPi with I2C interface and can
drive servo motors or LEDs up to 12 pieces. [4.] Although
the RPi has a 5V output, to protect the circuit from
overcurrent, additional power supply is used to feed the
motors.
The I2C is a serial interface, so the driver holds the servo
still in the last given position repeating the signal at the
given frequency (usually 50-60 Hz).
I built a prototype from Lego, to transfer the servo’s
torque and to position the camera Fig II. With this structure,
the camera is able to pan ~180° degrees and tilt ~140°
degrees (to protect the camera’s ribbon cable).
Fig. III. The setup and the Lego prototype frame of the PT camera
module.
D. Display, receiver and controller
For the other end of the transmission, I needed a device
that can detect motion and play videos streamed over the
internet so a smartphone is a perfect solution. I used my
HTC Desire X with Android 4.1.1 OS but it has a drawback
that only contains an accelerometer. A gyro sensor and a
digital compass would have eased the development of the
software, on the other hand this fact drew my attention to
make the software that can adapt to cheaper smartphones.
III. SOFTWARE TO OPERATE
A. For the PT camera part
Python is a general-purpose, high-level programming
language that is widely used among novice programmers,
and it’s suggested to use it to write programs to the RPi and
there are many open-source libraries written in Python. I
used the Adafruit’s library to control the servos and the
driver through the I2C port.
The concept is that the RPi runs a HTTP server that can
receive and process HTTP GET requests. The program
analyzes the request’s query: sets the rotation angle of the
servo motors and runs bash scripts to start/stop the camera
stream. VLC is a multimedia player and server that’s used
to stream the RaspiCam’s H264 encoded output over the
internet. It can stream over HTTP and RTSP (Real Time
Streaming Protocol) too. This stream can be easily played
by any VLC client like that is available on Android
platform.
B. For the smartphone controller
It is possible to create a webpage that is served by the
Raspberry, displaying the video and enables visitors to
control the camera with buttons [5.] and even with motion
detection due to this [6.] JavaScript has access to the
mobile’s gyroscope. While I’m not familiar with building
web pages so I decided to make an Android Application
instead, as I have more practice in Java and Android
programming.
I found that the built in MediaPlayer class is enough to
display the video stream from the network so I built the app
to use this. (Both HTTP and RTSP protocols and H264
encoded videos can be played with it according to the
documentation [7.]) First, to test the server side I used
simple buttons to change the pan and tilt of the camera. It
worked perfectly but the video stream over HTTP protocol
had a latency more than 10-15 seconds. I decided to change
the protocol to RTSP to reduce latency but the MediaPlayer
couldn’t manage to connect to the stream.
The VLC client on the Android phone displayed it well,
so I investigated the problem and found that other H264
streams over RTSP is also playable through the
MediaPlayer. This set back the project, I have to rewrite the
base, either to use and embed the VLC client for the display
or to stream the video another way to reduce latency.
What causes the latency? Both the server side and the
client side buffer the stream to avoid bad transmission due
to the network’s packet-loss.
C. Make it intuitive
To make it intuitive, I would like to implement a gesture
recognition system, using the WiiGee library what is an
open source java gesture recognition library for WiiMotes
using Hidden Markov Models.
REFERENCES
[1.] Matt Richardson, Shawn Wallace, “Getting Started with Raspberry
Pi” O’Reilly Media Inc. USA, pp. 10, December 2013.
[2.] Gordon Hollingworth, “Vectors from Coarse Motion Estimation”
http://www.raspberrypi.org/vectors-from-coarse-motion-estimation/
[3.] “RPi USB Webcams“ http://elinux.org/RPi_USB_Webcams
[4.] Simon Monk, “Raspberry Pi Cookbook” O’Reilly Media Inc. USA,
pp. 241-244, December 2013.
[5.] “Building a remote control vehicle using a Raspberry Pi“
http://raspberrywebserver.com/gpio/piface/building-a-remotecontrol-vehicle-using-a-raspberry-pi.html
[6.] Steve Block, Andrei Popescu, “DeviceOrientation Event
Specification”
http://w3c.github.io/deviceorientation/spec-sourceorientation.html ,2014,March 2014.
[7.] Supported Media Formats for playing and recording media
http://developer.android.com/guide/appendix/media-formats.htm
Download