Sie sind auf Seite 1von 80

PSZ 19:16 (Pind.

1/07)
UNIVERSITI TEKNOLOGI MALAYSIA

DECLARATION OF THESIS / UNDERGRADUATE PROJECT REPORT AND COPYRIGHT

Authors full name : BAI BING

Date of Birth : 18 JANUARY 1990

Title : MOTION DETECTION WEBCAM USING RASPBERRY PI

Academic Session : 2013/2014

I declare that this thesis is classified as:

CONFIDENTIAL (Contains confidential information under the Official Secret Act


1972)*

RESTRICTED (Contains restricted information as specified by the organization


where research was done)*

OPEN ACCESS I agree that my thesis to be published as online open access (full

text)

I acknowledged that Universiti Teknologi Malaysia reserves the right as follows:

1. The thesis is the property of Universiti Teknologi Malaysia

2. The Library of Universiti Teknologi Malaysia has the right to make copies for the
purpose of research only.

3. The Library has the right to make copies of the thesis for academic exchange.

Certified by:

SIGNATURE SIGNATURE OF SUPERVISOR

PM Muhammad Munim Bin Ahamd


200906M10025
Zabidi
(NEW IC NO/PASSPORT) NAME OF SUPERVISOR

Date: Date:

NOTES: * If the thesis is CONFIDENTAL or RESTRICTED, please attach with the letter from
the organization with period and reasons for confidentiality or restriction.
I hereby declare that I have read this thesis and in my
opinion this thesis is sufficient in terms of scope and quality for the
award of the Bachelors of Degree of Electrical and Microelectronics Engineering

Signature : .........
Name of Supervisor : PM Muhammad Munim Bin Ahamd Zabidi
Date :
MOTION DETECTION WEBCAM USING RASPBERRY PI

BAI BING

A thesis submitted in fulfillment of the


requirements for the award of the degree of
Bachelors of Electrical Engineering (Microelectronics)

Faculty of Electrical Engineering


Universiti Teknologi Malaysia

JANUARY 2014
ii

I declare that this thesis entitled Motion detection Webcam using Raspberry Pi is
the result of my own research except as cited in the references. The thesis has not
been accepted for any degree and is not concurrently submitted in candidature of any
other degree.

Signature : ....................................................
Name : .........BAI..BING.................................
Date : ........15..JANUARY..2014........................
iii

To my beloved mother and father for the continuing

support and inspiration in my journey of education


iv

ACKNOWLEDGEMENTS

I would like to take this opportunity to express my deepst gratitude to

my supervisor of this project, PM Muhammad Munim Bin Ahamd Zabidi

who has relentlessly assisted and guided me in completing this project. He

had given me a great deal of knowledge and insights along way. I also would

like thank my family for giving me full support during my academic years.

Special thanks to my friends who assisted me with ideas and supported me to

complete this project. Without them, the project would not be successful.

Finally thanks to all the course mates who have contributed directly or

indirectly to complete this project.


v

ABSTRACT

Theft problem has troubled people for years, but most motion detector

have same problem, such as expensive, large size, hard to install and

immovable after installed. To solve this problem I have design a system

motion detection webcam using Raspberry Pi, can detect motion and save

pictures in JEPG format when motion detected. And I build a webserver use

Raspberry Pi, so that allow user check the pictures taken by motion detection

program use web browser. This paper will introduce the background theory of

my project, the literature I study, how my program working and the result of

my project.
vi

ABSTRAK.

Sejak kebelakangan ini, kes kecurian semakin berleluasa sehingga mencecah tahap
yang amat membimbangkan.Untuk menbanteraskan kes ini, alat pengesan motion adalah
effective dan berkesan. Oleh sebab kos yang tinggi, saiz badan yang besar dan susah
ditanggalkan selepas memasang menyebabkan orang ramai tidak berminat
mengunakannya. Untuk menyelesaikan masalah ini, saya akan mereka satu bentuk
webcam pengesanan sistem motion yang baru dengan menggunakan Raspberry Pi. Alat ini
boleh mengesankan gerakan dan menyimpan gambar dalam format JEPG apabila
pergerakan dikesan. Selain itu, saya akan membina satu Webserver untuk pengguna
memeriksa gambar-gambar yang telah diambilkan oleh alat gerakan pengesanan ini.
Thesis ini akan memperkenalkan teori latar belakang projek saya, sastera yang saya telah
saya belajari dan bagaimana kerja program saya dan hasil projek saya.
vii

TABLE OF CONTENTS

CHAPTER TITLE PAGE


TITLE PAGE i

DECLARATION ii

DEDICATION iii

ACKNOWLEDGEMENTS iv

ABSTARCT v

ABSTRAK vi

TABLE OF CONTENTS vii

LIST OF FIGURES ix

LIST OF APPENDICES xi

1 INTRODUCTION 1
1.1 Background 1
1.2 Problem Statement 2
1.3 Objective 4
1.4 Scope of Project 4
1.5 Method 5
2 LITERATURE REVIEWS 8
2.1 OpenCV Simple Motion Detection 8
2.2 Home Automation with Raspberry 9
Pi & Arduino
viii

2.3 Control Raspberry Pi from 10

iPad/iPhone
2.4 Motion Detection and Object 11

Tracking in Image Sequences


2.4.1 Introduction 11

2.4.2 Motion Detection and Object 12

Tracking in Image Sequences


2.5 Introduction to OpenCV 14

2.6 What is web server a 23

computer of a program?
3 METHODLOGY 27

3.1 Introduction 27

3.2 Raspberry Pi 27

3.3 Web server 29

3.4 OpenCV 30

3.5 Design stages 32

3.6 Project flow chart 33

3.7 Programing flowchart 34

3.8 Website working flow chart 35

3.9Algorithm of using OpenCV 36

detect motion
4 RESULT 40

4.1 Introduction 40

4.2 Result of programing 41

4.3 Result of website design 43

5 CONCLUSION 46

5.1 Conclusion 46

5.2 Further Work 47

REFERENCES 49

APPENDICES A-B 51-67


ix

LIST OF FIGURES

FIGURES TILE PAGE


1.1 motion detect originally picture 5

1.2 no motion 6

1.3 motion detected 6

2.1 Raspberry Pi & Arduino 9

2.2 Raspberry Pi control by ipad 10

2.3 Supported Platforms 16

2.4 Basic Image Processing: Gaussian 18

Pyramids
2.5 Feature Extraction: Canny Edge Detector 19

2.6 Contours 19

2.7 Motion Analysis and Object Tracking 20

2.8 Camera Calibration 21

2.9 Video Surveillance 21

2.10 Face/Object Detection 22

3.1 Raspberry Pi 28

3.2 webserver and client 29

3.3 No different between three images 37

3.4 Found different between three images 37

3.5 flow chart of OpenCV detect motion 39

4.1 folders name with time 41

4.2 pictures name with time 42


x

4.3 website interface 43

4.4 check all pictures 44

4.5 check pictures by hour 45


xi

LIST OF APPENDICES

APPENDIX TITLE PAGE

A Motion detection code 52


B Website PHP code 59
1

CHAPTER 1

INTRODUCTION

1.1 Background

Motion detect is the process of detecting the change in the

surroundings relative to an object or a change in position of an object

relative to its surroundings. Motion detector is a device can detects

moving target, especially people. Motion detectors are widely used in lift,

supermarket. Any place that most of the time no activity can use motion

detector replace normal surveillance cameras. A motion detector is often

completed as an element of a system that automatically executes alerts a

user motion detected in an area. Motion detectors form an important

component of energy efficiency, home control, automated lighting

control, security, and other useful systems.


2

But most motion detector have same problem, such as expensive,

large size, hard to install and immovable after installed. Family Motion

Detection Monitoring System can build use computer and webcam, but

need software support. In order to solve these problems, we need design

a new system with low cost, small size, and easy install and uninstall.

This project is design a Motion Detection Monitoring System use

credit-card-sized single-board computer Raspberry Pi and USB

webcam for hardware module and writes a program can detection motion

and takes pictures and can check by web browser under local network.

The Pi and USB camera are ready, main work of this project is write a

program achieve the above functions. The final product can solve the

entire problem excellent.

1.2 Problem Statement

Theft problem has troubled people for years, but most motion

detector have same problem, such as expensive, large size, hard to install

and immovable after installed. To solve this problem, I can design a

Motion Detection Monitoring System use Raspberry Pi and USB


3

webcam for hardware module and writes a program can detection motion

and takes pictures and can check by web browser under local network.

But, the Raspberry Pi is a single-board computer which has a

Broadcom BCM2835 system on a chip, includes an ARM 700 MHz

processor, 256MB of RAM, and Video Core IV GPU. As we can see, the

performance was limited, the program must low hardware requirements,

in case cant run on Pi. Pi also dont have hard disk or solid-state drive,

but uses an SD card for booting and long-term storage, the storage

limited was another problem, we need adjustment the resolution of

pictures to make pictures clear to see and not cost so many memory

space. Pi use ARM difference with normal computer which use Intel

CPU or AMD CPU. The main problem of this project compatibility,

because the program will written and compile on normal computer, may

not compatible with Raspberry Pi.


4

1.3 Objective

There are 3 objectives in this project

(1) To write a program can detect motion on Raspberry Pi.

(2) To save the pictures of detected motion using JPEG

compression on the Raspberry Pi storage.

(3) To build a webserver on the Pi, so that the pictures stored on

Pi can be check by a Web browser.

1.4 Scope of Project

In order to achieve the objective of the project, there are several

scope had been outlined:

(1) Use C++ and OpenCV write program.

(2) Use PHP for website design.


5

(3) Use Pi and webcam for hardware module.

(4) Pictures are saved in JPEG format.

1.5 Method

In order to achieve the objective of the project, there are several

method had been outlined:

(1) Use C++ and OpenCV language write program can detection

motion and save pictures in JEPG format.

For program, motion detection doing like this:

Figure1.1: motion detect originally picture


6

First, capture a picture from camera as an example picture, and

then constantly capture pictures from camera.

Figure1.2: no motion

If there no motion detected compare with example picture, do

nothing and constantly capture pictures from camera.

Figure1.3: motion detected


7

If any motion detected, then save the new picture, and the new

picture become example picture, then repeat capture pictures and

compare with example, until new motion detected and make new

example.

(2) Make Raspberry Pi become webserver allow other users

check pictures by web browser. To achieve this goal, I need make

Raspberry Pi become a webserver, and other computers become client

can connect Pi. To make it easy use, I need make Pi have a fixed IP

address, in case IP change the program cant working well.


8

CHAPTER 2

LITERATURE REVIEWS

2.1 OpenCV Simple Motion Detection

This project is a program use OpenCV to detect motion and save

pictures. Publish by Cdric Verstraeten on website: www.cedricve.me on

February 5th, 2013. This program introduction an algorithm use

OpenCV to compare different between two images.

The algorithm is supposed have 2 images, the images are a taken

with some delay c between them. If we compare every pixel of the 2

images and theyre all the same, we could say the 2 images are same.

But if they dont, we could say there something happen during the delay

time c. Maybe someone place an object in front of the camera or

passing.
9

2.2 Home Automation with Raspberry Pi & Arduino

Theft problem has troubled people


people for
for years,
years, but
but most
most motion
motion detector
detector have
havesame
sameproblem,
problem,such
suchasasexpensive,
expensive,large
largesize,
size,hard
hardtotoinstall
installand
andimmovable after

immovableToafter
installed. solveinstalled.
this problem
To solve
I have
this problem,
design a Isystem
can design
motion
a Motion
detection
Detection
webcamMonitoring
using Raspberry
System use
Pi, Raspberry
can detectPimotion
and USB
and
webcam
save pictures
for hardware
in JEPG format when

module
motion detected.
and writesAnd
a program
I build acan
webserver
detection
use
motion
Raspberry
and takes
Pi, sopictures
that allow
anduser
cancheck
checkthe
by web
pictures
browser
takenunder
by motion
local networTheft
Theft problem has troubled
problem people for years, but
has troubled

most motion
people detector
for years, havemotion
but most same problem, such same
detector have as expensive,
problem,large
suchsize, hard to install
as expensive, largeand
size,Theft
hardproblem
to installhas
andtroubled people
immovable afterforinstalled.
years, but
Tomost
solvemotion detector

haveproblem,
this same problem, suchaasMotion
I can design expensive, largeMonitoring
Detection size, hard to installuse
System and immovable
Raspberry afterUSB
Pi and installed.
webcam Tofor
solve this problem
hardware moduleI and
have design
writes a systemcan
a program motion detection

webcam using
detection Raspberry
motion Pi, pictures
and takes can detect
andmotion and save
can check pictures
by web in JEPG
browser format
under localwhen motion detected.
networkkTheft problemAnd
hasI build
troubled
a webserver
people for
useyears,
Raspberry
but most
Pi, so that allow user

motion
check the
detector
pictures
have
taken
same
by problem,
motion detection
such as expensive,
program use
large
web
size,
browser.
hard toThis
install
paper
andwill
immovable
introduce
after
theinstalled.
backgroundTo solve
theory
thisofproblem,
my project,
I can
the
design
literature
a I study, how

Motion
my program
Detection
working
Monitoring
and the result
Systemofuse
my Raspberry
project.i Pi andproblem
Theft USB webcam for hardware
has troubled peoplemodule andbut
for years, writes
mosta program can detection
motion detector motion
have same and takes
problem, such as expensive,

pictures
large size,and can
hard to check
install by
andweb browserafter
immovable under local networkTheft
installed. problem I has
To solve this problem havetroubled
design apeople
system for years,
motion but most
detection motionusing
webcam detector have same
Raspberry Pi, can detect motion

problem, such as inexpensive,


and save pictures large
JEPG format size,motion
when hard to install and
detected. And immovable after installed.
I build a webserver To solve
use Raspberry Pi,this problem,
so that I cancheck
allow user design
theapictures
Motion taken
Detection
by motion detection

Monitoring
program useSystem use Raspberry
web browser. Pi andwill
This paper USB webcamthe
introduce for background
hardware module
theoryand writes
of my a program
project, can detection
the literature motion
I study, andprogram
how my takes pictures andand
working canthe result of my

check by web browser


project.mmovable after under local
installed. TonetworkTheft problem
solve this problem hasdesign
I have troubled people
a system for years,
motion but most
detection motion
webcam detector
using have
Raspberry Pi,same problem,
can detect suchand
motion as save pictures in

expensive, large size, hard to install and immovable after installed. To solve this problem, I can design a Motion Detection Monitoring System use

Figure2.1: Raspberry Pi & Arduino

These projects publish by Rupa Dachere, on March 16, 2013 in

Technology. This project builds to solve a problem where people

(gardeners, contractors and neighbor) would come by ones house when

not around.

This project use Arduino to detect motion, use Raspberry Pi and

Webcam to capture pictures and send the pictures through e-mail.


10

2.3 Control Raspberry Pi from iPad/iPhone

Theft problem has troubled people for years, but most motion detector have same problem, such as

expensive, large size, hard to inTheft problem has troubled people for years, but most motion detector

have same problem, such as expensive, large size, hard to install and immovable after installed. To solve

this problem, I can design a Motion Detection Monitoring System use Raspberry Pi and USB webcam for

hardware module and writes a proTheft problem has troubled people for years, but most motion

detector have same problem, such as expensive, large size, hard to install and immovable after installed.

To solve this problem, I can design a Motion Detection Monitoring System use Raspberry Pi and USB

webcam for hardware module and writes a program can detection motion and takes pictures and can

check by web browser under local networkgram can detection motion and takes pictures and can check

by web browser under local networkstall and immovable after installed. To solve this problem, I can

design a Motion Detection Monitoring System use Raspberry Pi and USB webcam for hardware module

and writes a program can detection motion and takes pictures and can check by web browser under

Figure2.2: Raspberry Pi control by ipad

This project was posted by Nick Normal , on April 3rd, 2013.This

project installs a VNC server on the Pi and a VNC client on the

iPhone/iPad. Make users can control Raspberry Pi wireless. The ipad

play the role as a monitor, this project make user easy to use Raspberry

Pi, I also want to use this technology on my own project.


11

2.4 Motion Detection and Object Tracking in Image


Sequences

2.4.1 Introduction

Artificial intelligence is an important topic of the current computer

science research. In order to be able to act intelligently a machine should

be aware of its environment. The visual information is essential for

humans. Therefore, among many different possible sensors, the cameras

seem very important. Automatically analyzing images and image

sequences is the area of research usually called computer vision. This

thesis is related to the broad subject of automatic extraction and analysis

of useful information about the world from image sequences. The focus

in this thesis is on a number of basic operations that are important for

many computer vision tasks. These basic steps are analyzed and

improvements are proposed.


12

2.4.2 Motion Detection and Object Tracking in Image


Sequences

This is a Ph.D. thesis write by Zoran Zivkovic on June 5 2003.

This thesis had introduction algorithm of how to detect motion using

image.

The algorithm is a static camera observing a spot is a common

case of a monitor system [12, 30, 8, 23]. Detecting invade objects is a

necessary step in analyzing the spot. A usually applicable hypothesis is

that the images of the spot without the invade objects exhibit some

regular behavior that can be well depict by a statistical model. If we have

a statistical model of the spot, an invade object can be detected by

spotting the parts of the image that dont fit the model. This process is

usually known as background subtraction.

Usually a simple bottom-up way is applied and the spot model has

a probability density function for each pixel divided. A pixel from a new

image is considered to be a background pixel if its new value is well

depicted by its density function. For example for a static spot the

simplest model could be just an image of the spot without the invade

objects. The next step would be, for example, to forecast appropriate
13

values for the change of the pixel intensity levels from the image since

the change can vary from pixel to pixel. However, pixel values often

have complex layout and more elaborate models are needed. In this

project, consider two popular models: the parametric Gaussian mixture

and the non-parametric k nearest neighbors (k-NN) estimate.

The spot could change from time to time (suddenly or slow

illumination changes, static objects deleted etc.). The model should be

frequently updated to incarnate the most current situation. The main

problem for the background subtraction algorithms is how to

automatically and efficiently update the model. This project analyzes the

results from the literature and extracts some basic principles. Based on

the extracted principles we recommend, analyze and compare two

efficient algorithms for the two models: Gaussian mixture and k-NN

estimate. The Gaussian mixture density function is a popular flexible

probabilistic model. A Gaussian mixture having a fixed number of

components is constantly updated using a set of heuristic equations.

Based on the results from the previous chapter of this thesis and some

additional approximations we propose a set of theoretically supported

but still very simple equations for updating the parameters of the

Gaussian mixture. The important improvement compared to the previous

approaches is that at almost no additional cost also the number of


14

components of the mixture is constantly adapted for each pixel. By

choosing the number of components for each pixel in an on-line

procedure, the algorithm can automatically fully adapt to the scene. We

propose an efficient algorithm based on the more appropriate

nonparametric k-NN based model. The both algorithms have similar

parameters with a clear meaning and that are easy to set. This project

also suggests some typical values for the parameters that work for most

of the situations. Finally, we analyze and compare the two proposed

algorithms.

2.5 Introduction to OpenCV

This literature was write by Vadim Pisarevsky, the Senior

Software Engineer of Intel Corporation, Software and Solutions Group.

This literature introduce general information of OpenCV, Getting Started

with OpenCV, Modules Description, Interaction with Intel IPP, Python

Interface, Some Usage Examples and Summary.

What is OpenCV? OpenCV (Open Source Computer Vision

Library) is a library of programming functions mainly direct at real time

computer vision, open up by Intel, and now stand by Itseez and Willow

Garage. Free for use under the open source BSD license. The library is
15

cross-platform. It is central mainly on real time image processing. If the

library finds Intel's Integrated Performance Primitives on the system, it

will use these proprietary optimized routines to accelerate itself.

Why we need OpenCV? Now, computer Vision Market is large

and still growing. But there is no standard API (like OpenGL and

DirectX in graphics, or OpenSSL in cryptography), most of CV software

is of 3 kinds:

1. Research code (slow, unstable, independent/incompatible data

types for every library/toolbox)

2. Very expensive commercial toolkits (like Halcon,

MATLAB+Simulink, )

3. Specialized solutions bundled with hardware (Video

surveillance, Manufacturing control systems, Medical equipment )

So, we need a standard library that simplifies development of new

program and solutions much easier. So, Intel develop OpenCV, and Intel

optimization for Intel Platforms that creates new usage models by

achieving real-time performance for quiteheavy algorithms and makes


16

Intel platforms attractive for CV developers.

Theft problem has troubled people for years, but most motion detector have same problem, such as expensive, large size, hard to install and immovable after
Theft problem has troubled people for years, but most motion detector have same problem, such as expensive, large size, hard to install and immovable after installed. To

installed. To solve this problem I have design a system motion detecti Theft problem has troubled people for years, but most motion detector have same problem,
solve this problem, I can design a Motion Detection Monitoring System use Raspberry Pi and USB webcam for hardware module and writes a program can detection motion

such as expensive, large size, hard Theft problem has troubled people for years, but most motion detector have same problem, such as expensive, large size, hard to
and takes pictures and can check by web browser under local networkTheft problem has troubled people for years, but most motion detector have same problem, such as

install and immovable after installed. To solve this p Theft Theft problem has troubled people for years, but most motion detector have same problem, such as
expensive, large size, hard to iTheft problem has troubled people for years, but most motion detector have same problem, such as expensive, large size, hard to install and

expensive, large size, hard to install and immovable Theft problem has troubled people for years, but most motion detector have same problem, such as expensive,
immovable after installed. To solve this problem, I can design a Motion Detection Monitoring System use Raspberry Pi and USB webcam for hardware module and writes a

large size, hard to install and immovable after installed. To solve this problem I have design a system motion detection webcam using Raspberry Pi, can detect
program can detection motion and takes pictures and can check by web browser under local networknstall and immovable after installed. To Theft problem has troubled

motion and save pictures in JEPG format when motion detected. And I build a webserver use Raspberry Pi, so that allow user check the pictures taken by motion
people for years, but most motion detector have same problem, such as expensive, large size, hard to install and immovable Theft problem has troubled people for years, but

detection program use web browser. This paper will introduce the background theory of my project, the literature I study, how my program working and the result
most motion detector have same problem, such as expensive, large size, hard to install and immovable after installed. Theft problem has troubled people for years, but most

of my project.a Theft problem has troubled people for years, but most motion detector have same problem, such as expensive, large size, hard to install and
motion detector have same problem, such as expensive, large size, hard to install and immovable after installed. To solve this problem, I can design a Motion Detection

immovable after installed. To solve this problem I have design a system motion detection webcam using Raspberry Pi, can detect motion and save pictures in JEPG
Monitoring System use Raspberry Pi and USB webcam for hardware module and writes a program can detection motion and takes pictures and can check by web browser

format when motion detected. And I build a webserver use Raspberry Pi, so that allow user check the pictures taken by motion detection program use web browser.
under local network To solve this problem, I can design a Motion Detection Monitoring System use Raspberry Pi and USB webcam for hardware module and writes a program

This paper will introduce the background theory of my project, the literature I study, how my program working and the result of my project.fter installed. To solve
can detection motion and takes pictures and can check by web browser under local networkafter installed. To solve this problem, I can design a Motion Detection Monitoring

this problem I have design a system motion detection webcam using Raspberry Pi, can detect motion and save pictures in JEPG format when motion detected. And I
System use Raspberry Pi and USB webcam for hardware module and writes a program can detection motion and takes pictures and can check by web browser under local

build a webserver use Raspberry Pi, so that allow user check the pictures taken by motion detection program use web browser. This paper will introduce the
networksolve this problem, I can design a Motion Detection Monitoring System use Raspberry Pi and USB webcam for hardware module and writes a program can detection

background theory of my project, the literature I study, how my program working and the result of my project. problem has troubled people for years, but most
motion and tTheft problem has troubled people for years, but most motion detector have same problem, such as expensive, large size, hard to install and immovable after

motion detector have same problem, such as expensive, large size, hard to install and immovable after instal Theft problem has troubled people for years, but most
installed. To solve this problem, I can design a Motion Detection Monitoring System use Raspberry Pi and USB webcam for hardware module and writes a program can

motion detector have same problem, such as expensive, large size, hard to install and immovable after installed. To solve this problem I have design a system motion
detection motion and takes pictures and can check by web browser under local networkakes pictures and can check by web browser under local networkTheft problem has

detection webcam using Raspberry Pi, can detect motion and save pictures in JEPG format when motion detected. And I build a webserver use Raspberry Pi, so that
troubled people for years, but most motion detector have same problem, such as expensive, large size, hard to install and immovable after installed. To solve this problem, I

allow user check the pictures taken by motion detection program use web browser. This paper will introduce the background theory of my project, the literature I
can design a Motion Detection Monitoring System use Raspberry Pi and USB webcam for hardware module and writes a program can detection motion and takes pictures and

study, how my program working and the result of my project.led. To solve this problem I have design a system motion detection webcam using Raspberry Pi, can
can check by web browser under local networkTheft problem has troubled people for years but most motion detector have same problem such as expensive large size hard

detect motion and save pictures in JEPG format when motion detected. And I build a webserver use Raspberry Pi, so that allow user check the pictures taken by

Figure2.3:Supported Platforms
What OpenCV can do? OpenCV library is actively used by a large

number of companies and research centers, and versatile.

OpenCV Functionality Overview:

1.Smart windows
17

2. Image I/O, rendering

3. Processing keyboard and other events, timeouts

4. Track bars

5. Mouse callbacks

6. Video I/O

7. Matrix and Image Arithmetical and Logical Operations

8. Linear algebra, DFT/DCT, vector math

9. Dynamic structures

10. Drawing functions

11. XML I/O

12. Basic Image Processing: Image filters, Morphology, Pyramids, Color

space conversions, Geometrical transformations, Histograms.


18

Figure2.4: Basic Image Processing: Gaussian Pyramids

13. Advanced Image Processing and Feature extraction: Corner detection,

Canny edge detector, Hough transform, Distance transform, Watershed,

In painting
19

Figure2.5: Feature Extraction: Canny Edge Detector

14. Shape analysis and Computational geometry: Image moments,

contours, Delaunay triangulation and Voronoi Tesselation

Figure2.6: Contours
20

15. Motion Analysis: Optical flow, Object tracking (Meanshift &

CAMSHIFT), Motion templates, Kalman filters

Theft problem has troubled people for years, but most motion detector have same problem, such as expensive, large size, hard to install

and immovable after installed. To solve this problem I have design a system motion detecti Theft problem has troubled people for years,

but most motion detector have same problem, such as expensive, large size, hard Theft problem has troubled people for years, but most

motion detector have same problem, such as expensive, large size, hard to install and immovable after installed. To solve this p Theft

Theft problem has troubled people for years, but most motion detector have same problem, such as expensive, large size, hard to install

and immovable Theft problem has troubled people for years, but most motion detector have same problem, such as expensive, large size,

hard to install and immovable after installed. To solve this problem I have design a system motion detection webcam using Raspberry Pi,

can detect motion and save pictures in JEPG format when motion detected. And I build a webserver use Raspberry Pi, so that allow user

check the pictures taken by motion detection program use web browser. This paper will introduce the background theory of my project,

the literature I study, how my program working and the result of my project.a Theft problem has troubled people for years, but most

motion detector have same problem, such as expensive, large size, hard to install and immovable after installed. To solve this problem I

have design a system motion detection webcam using Raspberry Pi, can detect motion and save pictures in JEPG format when motion

detected. And I build a webserver use Raspberry Pi, so that allow user check the pictures taken by motion detection program use web

browser. This paper will introduce the background theory of my project, the literature I study, how my program working and the result of

my project.fter installed. To solve this problem I have design a system motion detection webcam using Raspberry Pi, can detect motion

Figure2.7:Motion Analysis and Object Tracking


21

16. Camera calibration, Epipolar geometry

Figure2.8: Camera Calibration

17. Advanced Blob tracking ( Video Surveillance module)

Figure2.9: Video Surveillance


22

18. Object detection (Haar classifier)

Figure2.10: Face/Object Detection

OpenCV is a long time project and has accepted reputation because of


23

good quality. And together with IPP it is used in different parts and for

different kinds of programs, from small study projects to large

advertisement products. Intel is still standing behind of OpenCV.

OpenCV will continue to develop; the further grow will be program

driven.

2.6 What is web server a computer of a program?

This literature publish on webdevelopersnotes website, this

literature had introduce the hardware, the software and the role of web

server.

A web site is a compilation of web pages which are digital files

usually written using HyperText Markup Language (HTML). For a web

server to be active to everyone in the world at all times, it necessary to

be stored on a computer that is connected to the internet 24/7/365. Such

a computer is known as a Web Server.

There is several conditions need for a Server computer usually it

needs to be fast, have a huge storage capacity hard disk and large RAM.

But the most important thing is having a lasting internet address also

recognized as an I.P. (Internet protocol) address. If the I.P. address


24

variation, the web site would not be found and will appear offline, the

browser will display web site error.

A web server program is software that works on the web site

hosting Server computer. Its main function is serving web pages; which

mean it waits for connect requests from web browsers (also known as

clients) and answer by sending the required data back. This client-server

interplay is the characteristic of how the web works.

There are many web server programs can choose. The most

famous and welcome of all programs is Apache developed by the

Apache Foundation. Not only because Apache is free but it is also

available for several operating systems including Windows, Macintosh

and Linux/Unix.

Web servers hardware the computer or the software the program -

have an important role on the Internet. The Server machine hosts (stores)

the web site on its hard disk and the server program helps transfer the

web pages and their related files like images, flash movies etc. to clients

(browsers).

The process of loading a web site in a web browser starts with the
25

user r entering the website address in the address bar or clicking on a

link. You should know that every web page has different address (or

URL) on the internet; which means the same page cannot exist in two

addresses.

Once the suitable action has been start by the user, the browser

sends out a ask for the web page. Behind the scenes, the URL of the

requested web page is converted into an I.P. address, something that

computers understand. The I.P. addresses aim to the location of the web

server host. The request is send out to Server computer and passed on to

the server software.

The server software now gets to work and hunts for the requested

web page on the hard disk. On finding the file, it sends a answer to the

browser followed the actual web page file which then starts displaying

the page.

A representative web page not only has text but also embedded

multimedia factor like images and Flash movie. These "extra" files are

separate from the actual web page and are seeking by the browser from

the Server one by one. Note (and an important one), ONLY the web

browser determines how a web page is displayed; the web server has no
26

control over this. The job of the web server ends once the requests from

the browser are processed and the required information is sent.

Though it might seem that the request-and-answer process takes a

lot of time, especially when you consider that the client and server

computers might be thousands of miles apart, it actually happens very

quickly. That's because of the HyperText Transfer Protocol (HTTP)

which is a set of rules developed by the "big lads" to promote the

transfer of data over the internet.


27

CHAPTER 3

METHODLOGY

3.1 Introduction

These chapters will introduction the background theory of

Raspberry Pi, webserver and OpenCV. Also introduction about

algorithm of OpenCV detect motion and project flowchart.

3.2 Raspberry Pi

The Raspberry Pi is credit card size single board computer

developed by the Raspberry Pi Foundation in the UK with the purpose of

improve the teaching of basic computer science in schools. The

Raspberry Pi has a Broadcom system on a chip, which includes a Video


28

Core IV GPU, 700 MHz ARM processor, and was shipped with 256

megabytes of RAM, later upgraded to 512MB. But not include a built in

hard disk, but use SD card for long term storage and booting.

The company provides Arch Linux ARM distributions and Debian

for download. Also planned develop tools for supporting Python as the

main program language, with support for C BASIC, (via the RISC OS

image or the "Brandy Basic" clone for Linux), BBC, and Perl.

Figure3.1: Raspberry Pi
29

On 17 December 2012 the Raspberry Pi Foundation, in

collaboration with Indie City and Velocix, opened the "Pi Store", as a

"one-stop shop for all your Raspberry Pi software needs". Using an

application comprise in Raspbian, users can browse through several class

and download what they want. Software can also be uploaded for

moderation and release.

3.3 Webserver

A Web server is the program using client-server model and the

World Wide Web's Hypertext Transfer Protocol, serves the website that

form Web pages to Web users. Every computer on the Internet that

includes a Web site must have a Web server program.

Figure3.2: webserver and client


30

Server-Client show the relationship between two computer

programs in one program, the provider of a service or resource called

servers and service requester called clients. The client makes a service

request from one program, the server perform the request. Usually

clients and servers connect over a computer network on separate

hardware, but both client and server may use the same system. A server

is a host that is running server programs which share their resources with

clients. Clients not share any resources, but need a server's content or

service function. Notwithstanding the Server-Client idea can be used by

programs within a single computer, but it is a more important idea in a

network. Under a network, the client-server model provides a convenient

way to interconnect programs that are distributed efficiently across

different locations.

3.4 OpenCV

OpenCV (Open Source Computer Vision Library) is a library of

programming functions mainly direct at real time computer vision, open

up by Intel, and now stand by Itseez and Willow Garage. Free for use
31

under the open source BSD license. The library is cross-platform. It is

central mainly on real time image processing. If the library finds Intel's

Integrated Performance Primitives on the system, it will use these

proprietary optimized routines to accelerate itself.

OpenCV is written in C++ and its primary interface is in C++, but

it still retains a less comprehensive though extensive older C interface.

There are now full interfaces in Python, Java and MATLAB. The API for

these interfaces can be found in the online documentation. Wrappers in

other languages such as C#, Ruby have been developed to encourage

adoption by a wider audience. All of the new developments and

algorithms in OpenCV are now developed in the C++ interface.


32

3.5 Design stages

Review of similar
projects and learn
programing

Write program and test on


computer

Test program on Pi and fix


error

Build webserver and


design website on
computer

Build webserver on Pi and


user can use other device
open website and check
pictures
33

3.6 Project flow chart

run completed program on


Pi

camera capture pictures

Program do motion
detection No motion

detected motion

repeated capture pictures


save pictures and motion detection
34

3.7 Programing flowchart

Start

Got present time


(dd-mm-yyyy)

Folder name Yes


with present
time exist?

No

Create folder name with present time

Capture picture from cam

Motion No
detected?

Yes

Save picture name with present time


35

3.8 Website working flow chart

Scan folders

Show folders on
website

Scan pictures under


folders

Show pictures on
website
36

3.9 Algorithm of using OpenCV detect motion

The algorithm is supposed have 2 images, the images are a taken

with some delay c between them. If we compare every pixel of the 2

images and theyre all the same, we could say the 2 images are same.

But if they dont, we could say there something happen during the delay

time c. Maybe someone place an object in front of the camera or

passing.

In my project we use 3 images; they are called previous, current

and next. I first compare the images previous and current and then the

images current and next. After this I will do a logical XOR operation

between the results of both and threshold the final result to make it

accurate for large change only.

absdiff(next_frame, current_frame, d1);

absdiff(current_frame, previous_frame, d2);

bitwise_xor(d1, d2, result);

..

threshold(result, result, 140, 255, CV_THRESH_BINARY);


37

After thresholding, if there no different between three images, the

result like this, all black means no change found

Figure3.3: No different between three images

After thresholding, if there found different between three images,

the result will be like this, the white dots indicate the changes.

Figure3.4: Found different between three images


38

Next I will place a window in the central authority of the

thresholded result image. And I will look for changes, this means I will

look for pixels with values greater than zero, this will show motion.

When motion is detected (a pixel with value>0) the searching will stop

and an image will be saved.

for(int i = middle_x-window; i < middle_x+window; i++)

for(int j = middle_y-window; j < middle_y+window; j++)

if(result.at<int>(j,i)>0)

movement = true;

break;

The value of pixel can be set by myself, based on surrounding,

motion detect can me more sensitive or insensitive.


39

Figure3.5: flow chart of OpenCV detect motion


40

CHAPTER 4

RESULT

4.1 Introduction

This chapter will talk about the result I got of my project. You will

see the result of program and website interface. You will see the print

screen of the program result and the print screen of website check use

web browser.
41

4.2 Result of programing

First, my program can get system present time, and create folders

name with the time.

Figure4.1: folders name with time


42

The program also can detect motion and save the pictures name

with time and frame number.

Figure4.2: pictures name with time


43

4.3 Result of website design

For website design part, I use PHP language and javescript design

the website. First, use web browser can see the folders name with time,

so can choose the date check the pictures.

Figure4.3: website interface


44

After choose the date, you can choose two ways to check the

pictures. First is showing all the pictures under the date folder you

chosen.

Figure4.4: check all pictures


45

Second is you can choose look hourly, so the pictures under the

day you chosen will classification by hour. Allow users choose the hour

they want to check.

Figure4.5: check pictures by hour


46

CHAPTER 5

CONCLUSION

5.1 Conclusion

I have successful design a Motion Detection Monitoring System

use Raspberry Pi and webcam for hardware and write a program using

C++ language and OpenCV detect motion and save pictures in JEPG

format. I also use PHP language design a website for internet album, and

build webserver allow users visit album use web browser.

During the process to complete the project, I have learn many

thing, like how to study by yourself, how to find the document you need,

how to use Linux system and write program and compile program under

Linux system. I also learned basic knowledge of C++ programing, web

site design and webserver.


47

5.2 Further Work

The performance of my project are able save 2 pictures per second

when motion been detected, resolution 640x480. 1 GB storage space

able to save 17,000 pictures. My project able automatically starts up at

boot.

But there still many things can do to improve my project. Like my

project detect motion use OpenCV compare two images find different

and save in JEPG format, but if can compare use JEPG not image will

improve speed and reducing hardware requirement.

And my website also have many part need improve, like my

project can choose hourly check pictures, but you dont know which

hour have detected motion, if only can click the hour have pictures will

much good for users check pictures.

My program can automatically start up at boot, but if you want to

stop it or delete pictures, you need keyboard, mouse and monitor. It is

not easy for use, if can find any program can control Raspberry Pi use

other device, make Raspberry Pi no need so connect other devices, so the

system will better for normal users.


48

The time is another problem, because Raspberry Pi clock only

work on power on, so if power off the clock will stop. That means the

time program got from Pi system will wrong when boot again. Now only

way to automatically correct time need connect internet, but not all place

have internet, so time problem also need find solution.


49

REFFERENCE

[1]. Roy Ellwood. ( 2011). Build A Home Webserver

[2]. Price, Peter.(2011). "Can a 15 computer solve the

programming gap?". BBC Click.

[3]. Moorhead, Joanna.(2012). "Raspberry Pi device will reboot

computing in schools'". The Guardian (London).

[4]. Gary Bradski. (2008). Learning OpenCV: Computer Vision

with the OpenCV Library. ISBN-13:978-059616130

[5]. Daniel Lellis Baggio. (2012). Mastering OpenCV with

Practical Computer Vision Projects. ISBN-13: 978-184517829

[6] Carlo Tomasi Takeo Kanad Detection and Tracking of Point

Feature Technical Report CMU-CS-91-13


50

[7] NicolaiPetkovEaswarSubramanian Motion detection, noise

reduction, texture suppression, and contour enhancement by

spatiotemporal Gabor lters with surround inhibition

Publishedonline:25October2007

[8] Motion_Detection_Programming_Guide_V1.1 GM8126

[9] Price, Peter "Can a 15 computer solve the programming

gap?". BBC Click. 2 July 2011.

[10] "David Braben on Raspberry Pi". Edge. 25 November 2011.

8 December 2011.

[11] Moorhead, Joanna "Raspberry Pi device will 'reboot

computing in schools'". The Guardian (London). 20 January 2012.

[12] "What is web server?'". Web developers notes. 23 November

2013.

[13] "Distributed Application Architecture". Sun Microsystem. 16

July 2009
51

[14] "Interview with Eben Upton Raspberry Pi Founder".

International Business Times. 19 March 2012.

[15] "Linux news showing the first release of Debian Squeeze for

Raspberry running on QEMU". Linuxnewshere.com. 16 July 20012

[16] "Raspberry Pi maker says code for ARM chip is now open

source". Ars Technica. 3 November 2012.

[17] Shead, Sam. "Raspberry Pi delivery delays leave buyers

hungry (and angry)". ZDNet. 18 October 2012.

[18] Vallance, Chris. "Raspberry Pi bids for success with

classroom coders". BBC News. 29 February 2012.

[19] Steve Silva(2008). Web Server Administration. ISBN-13:

978-1423903239

[20] Alan Winston(2002). OpenVMS with Apache, WASD, and

OSU: The Nonstop Webserver (HP Technologies). ISBN-13:

978-1555582647
52

APPENDIX A

Motion Detection code

#include <opencv2/opencv.hpp>
#include <iostream>
#include <time.h>
#include <dirent.h>
#include <sstream>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>

using namespace std;


using namespace cv;

bool directoryExists( const char* pzPath )


{
if ( pzPath == NULL) return false;
DIR *pDir;
53

bool bExists = false;


pDir = opendir (pzPath);
if (pDir != NULL)
{
bExists = true;
(void) closedir (pDir);
}
return bExists;
}

bool saveImg(Mat image, const string DIRECTORY, const string EXTENSION,


const char * DIR_FORMAT, const char * FILE_FORMAT)
{

stringstream ss;
time_t seconds;
struct tm * timeinfo;
char TIME[80];

time (&seconds);
timeinfo = localtime (&seconds);

// convert dir...
strftime (TIME,80,DIR_FORMAT,timeinfo);
ss.str("");
ss << DIRECTORY << TIME;

if(!directoryExists(ss.str().c_str()))
mkdir(ss.str().c_str(), 0777);
54

// convert image name


strftime (TIME,80,FILE_FORMAT,timeinfo);
ss.str("");
//num.str("");
ss << DIRECTORY << TIME<<EXTENSION;

// save image
return imwrite(ss.str().c_str(), image);
}

int main (int argc, char * const argv[]){

// const
const string DIR = "/usr/share/nginx/www/pics/";
const string EXT = ".jpg";
const int DELAY = 20; // mseconds
std::ostringstream num;
std::ostringstream num1;
std::ostringstream num2;

int n=1;

string DIR_FORMAT = "%d-%m-%Y";


string FILE_FORMAT = DIR_FORMAT+ "/" +
"%d-%m-%Y_%H:%M:%S-";

num<<n;
55

string ary2 = "%S";

// create all necessary instances


CvCapture * camera = cvCaptureFromCAM(CV_CAP_ANY);
Mat original = cvQueryFrame(camera);
Mat next_frame = original;
Mat current_frame = cvQueryFrame(camera);
Mat prev_frame = cvQueryFrame(camera);

cvtColor(current_frame, current_frame, CV_RGB2GRAY);


cvtColor(prev_frame, prev_frame, CV_RGB2GRAY);
cvtColor(next_frame, next_frame, CV_RGB2GRAY);

Mat d1, d2, result;


int window = 200;
bool movement;
while (true){

movement = false;
absdiff(next_frame, current_frame, d1);
absdiff(current_frame, prev_frame, d2);
bitwise_xor(d1, d2, result);

int middle_y = result.rows/2;


int middle_x = result.cols/2;
56

// Center window
threshold(result, result, 140, 255, CV_THRESH_BINARY);
for(int i = middle_x-window; i < middle_x+window; i++)
for(int j = middle_y-window; j < middle_y+window; j++)
if(result.at<int>(j,i)>35)
{
movement = true;

break;
}

if(movement==true)
{

string FILE_FORMAT = DIR_FORMAT+ "/" +


"%d-%m-%Y_%H:%M:%S-";
FILE_FORMAT+=num.str();

saveImg(original,DIR,EXT,DIR_FORMAT.c_str(),FILE_FORMAT.c_str());
string ary1 ="%S";
num1<<ary1;

num2<<ary2;
string ary3= num1.str();
string ary4 = num2.str();
num1.str("");

//size_t comp = ary3.compare(ary4);


57

size_t comp = ary3.compare(1,2,ary4,1,2);

if(comp == 0)

{
n++;
num.str("");

num<<n;

}
else if (comp !=0 )
{

num.str("");
num1.str("");
num2.str("");
n=1;
num<<n;
}

prev_frame = current_frame;
current_frame = next_frame;
// get image from webcam
next_frame = cvQueryFrame(camera);

cvtColor(next_frame, next_frame, CV_RGB2GRAY);


58

// delay and quit when press Q/q


int key = cvWaitKey (DELAY);
if (key == 'q' || key == 'Q')
break;
}

return 0;
}
59

APPENDIX B

Website PHP code

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<link rel="stylesheet" type="text/css"
href="fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<link rel="stylesheet" type="text/css" href="jquery-ui-1.8.18.custom.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<script type="text/javascript"
src="fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript"
src="fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("a.vergroot").fancybox();
$(".video").click(function() {
$.fancybox({
'padding' : 0,
'autoScale' : false,
60

'transitionIn' : 'none',
'transitionOut' : 'none',
'title' : this.title,
'width' : 640,
'height' : 385,
'href' : this.href.replace(new
RegExp("watch\\?v=", "i"), 'v/'),
'type' : 'swf',
'swf' :{
'wmode' : 'transparent',
'allowfullscreen' : 'true'
}
});
return false;
});
});
</script>
<script type="text/javascript">

var _gaq = _gaq || [];


_gaq.push(['_setAccount', 'UA-38955983-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www')
+ '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
61

})();

</script>
</head>
<body>
<?php

if(!isset($_GET['page']))
$_GET['page'] = 1;

$aantal = 16;
$j = 0;
$begin = ($_GET['page']-1)*$aantal;
$end = $begin+$aantal;

if(!isset($_GET['day'])){
$day = date("d",time());
$mon = -date("m",time());
$year = -date("Y",time());
$current = $day.$mon.$year;
}
else
$current = $_GET['day'];

echo "<div class='month'>You're watching: $current</div><ul id='month_list'


style='overflow:hidden'>";
62

if ($handle = opendir('pics') ) {
$months = array();
while (false !== ($entry = readdir($handle))) {
if($entry != "." && $entry != ".."){
array_push($months, $entry);
}
}
sort($months);

for($f = 0; $f < count($months); $f++){

$day = substr($months[$f],0,2);
$mon = substr($months[$f],3,2);
$year = substr($months[$f],6,4);

echo "<li class='button' style='float:left'><a


style='text-decoration:none;color: #fff;'
href='index.php?page=1&day=".$day.-$mon.-$year."'>".$day.-$mon.-$year."</a></li
>";

}
}
echo "</ul>";

$filecount = count(glob("pics/$current/" . "*.jpg"));


63

echo "<h2>There are $filecount images available</h2><br/>";

$current_hour = date("G",time());
//if($current_hour==0)
//$current_hour = 24;

echo "<a href='index.php?day=$current' class='button' >Look


sequentially</a>&nbsp;&nbsp;&nbsp;<a class='button'
href='index.php?day=$current&hour=".$current_hour."'>Look
hourly</a><br/><br/>";

if(is_dir("pics/$current")){
if(!isset($_GET['hour'])){

if ($handle = opendir("pics/$current") ) {

/* This is the correct way to loop over the directory. */


$stack = array();

while (false !== ($entry = readdir($handle))) {


if($entry != "." && $entry != ".."){
array_push($stack, $entry);
}
}

sort($stack);
64

$cols = 4; $i = 0;
if(count($stack) < $end)
$end = count($stack);

for($f = 0; $f <= count($stack)/$aantal; $f++){


if($f%20==0)
echo "<br/><br/><br/>";
if($_GET['page']==$f+1)
echo "<a class='button'
href='index.php?page=".($f+1)."&day=".$current."'><span
style='text-decoration:underline;color:#B23232;'>". ($f+1) ."</span></a>";
else
echo "<a class='button'
href='index.php?page=".($f+1)."&day=".$current."'><span>".
($f+1) ."</span></a>";
}
echo "</ul>";
echo "<br/><br/>&nbsp;<br/>";

echo "<table><tr>";
for($f = $begin; $f < $end; $f++){
if($i%$cols == 0)
echo "</tr><tr>";
$i++;
$day = substr($stack[$f],0,2);
$mon = substr($stack[$f],2,3);
$year = substr($stack[$f],5,5);
$hour = substr($stack[$f],11,2);
65

$min = substr($stack[$f],14,2);
$sec = substr($stack[$f],17,5);

echo "<td style='text-align:center'><a class='vergroot' title='".$day."


".$mon." ". $year ." - ".$hour. ":" . $min. ":". $sec."' rel='reeks'
href='pics/".substr($stack[$f],0,10)."/$stack[$f]'><img
src='pics/".substr($stack[$f],0,10)."/$stack[$f]' width='300'
style='float:left;'><br/>".$day." ".$mon." ". $year . " - ".$hour. ":" . $min. ":". $sec.
"</td></a>";
}
echo "</tr></table>";

closedir($handle);
}
}
else{

echo "<br/><br/><br/>";
for($i = 0; $i <= 23 ; $i++){
if($i%14==0)
echo "<br/><br/><br/><br/>";
if($_GET['hour']==$i)
echo "<a class='button'
href='index.php?day=".$current."&hour=$i'><span
style='text-decoration:underline;color:#B23232;'>".$i."
u</span></a>&nbsp;&nbsp;&nbsp;";
else
echo "<a class='button'
href='index.php?day=".$current."&hour=$i'>".$i." u</a>&nbsp;&nbsp;&nbsp;";
}
66

echo "<br/><br/><br/>";

if ($handle = opendir("pics/$current") ) {

/* This is the correct way to loop over the directory. */


$stack = array();

while (false !== ($entry = readdir($handle))) {

$hour = substr($entry,11,2);
// if($hour == 0)
//$hour = 24;

if($entry != "." && $entry != ".." && $hour == $_GET['hour']){


array_push($stack, $entry);
}
}

sort($stack);
echo "<table><tr>";
$cols = 4; $i = 0;

for($f = 0; $f < count($stack); $f++){


if($i%$cols == 0)
echo "</tr><tr>";
$i++;

$day = substr($stack[$f],0,2);
$mon = substr($stack[$f],2,3);
$year = substr($stack[$f],5,5);
67

$hour = substr($stack[$f],11,2);
$min = substr($stack[$f],14,2);
$sec = substr($stack[$f],17,5);

echo "<td style='text-align:center'><a class='vergroot' title='".$day."


".$mon." ". $year ." - ".$hour. ":" . $min. ":". $sec."' rel='24feb'
href='pics/".substr($stack[$f],0,10)."/$stack[$f]'><img
src='pics/".substr($stack[$f],0,10)."/$stack[$f]' width='300'
style='float:left;'><br/>".$day." ".$mon." ". $year . " - ".$hour. ":" . $min. ":". $sec.
"</td></a>";
}
echo "</tr></table>";

closedir($handle);
}

}
else
print "choose one day";
?>
</body>
</html>

Das könnte Ihnen auch gefallen