You are on page 1of 75

Republic of Yemen

University of Science and Technology


College of Science and Engineering

Department of Computer Sciences and

Information Technology.

Hodeidah

Surveillance System By Cameras


:

:
/

-
2010-2009

II

)(200


......




.

III


.
:
/



.

IV

II

III

IV

VIII

IX

XI
-1 :

-1.1

-2.1

-3.1

-4.1

-6.1

3
-2 :

-1.2

-2.2

-3.2

-4.2

-1.4.2 Analog (VCR based) Systems

-2.4.2 DVR

-3.4.2 DVR

11

-4.4.2 IP Cameras

12

-5.2

14
V

-3 :
-1.3

16

-2.3

16

-3.3

17

-4.3

18

-5.3

19

-6.3

20

-1.6.3

20

-2.6.3

22

-3.6.3 )(Sampling

22

-4.6.3 Motion Detection Algorithm

23

-5.6.3

25

-4 :
-1.4

28

-2.4

28

-3.4

35

-1.3.4

35

-2.3.4

37

-5 :
-1.5

40

-2.5

40

-3.5

40

-6 :
-1.6

52

-2.6

52

-3.6

52
VI

53

-4.6

54

56

VII

1.3

18

2.3

18

3.3

19

VIII


1.2

2.2

3.2

DVR

10

4.2

DVR

12

5.2

IP Camera

14

-
1.3

Monochrome

21

2.3

Gray

21

3.3

RGB

21

4.3

22

5.3

24

-
1.4

28

2.4

28

3.4

29

4.4

29

5.4

30

6.4

30

7.4

31

8.4

31

9.4

32

10.4

32

11.4

33

12.4

33

13.4

34

IX

14.4

Gray

36

15.4

38

-
1.5

Login -

40

2.5

Main

41

3.5

General -

42

4.5

Change Password -

43

5.5

Cameras -

43

6.5

Cameras -

44

7.5

Events -

45

8.5

E-Mail Setting -

46

9.5

Phone Calls Setting -

46

10.5

Map Settings -

47

11.5

About -

48

12.5

Record Viewer -

49

13.5

Map -

50






)

(
.

XI


-1.
-2 .
-3 .
-4 .
-5 .

1.1


.

) : (.....
).(Surveillance Camera

) (
.
2.1

) (.


.
3.1

.
.

.
4.1
:
- 1 :
.
.
DVR .
.
-2 :
Windows XP .
) Microsoft Visual C#.Net
(.
).(Microsoft Word ,Microsoft Power Point
5.1
:
.
:
.

:
.
: .
: .
: .

-1
-2
-3
-4
-5

1.2

.
2.2


) (
(Digital Video Recorder) DVR

[3].

3.2
20

Coaxial
.

(TV Cards) TV

) +(


TV Card

[4].

4.2
-1 .
-2 .DVR
-3 .DVR
-4

[5].IP Cameras

PC Based DVR Systems

Analog type Systems

Stand Alone DVR System

IP Network Camera Systems

:1.2

1.4.2 Analog (VCR based) Systems


) Video Cassette Recording (VCR
:
24
:
.

:

.



.

DVR
.

Multiplexer
.

:2.2

: .-

:-

2.4.2 DVR
DVR

.DVR

DVR
DVR

DVR
.

DVR :

DVR ) (. DVR ) (. DVR ) (. - DVR ) (.

:3.2 DVR

.-

.
10

3.4.2 DVR



Linux Unix


.
DVR . . .11

. . DVR - .

:4.2 DVR

4.4.2 IP Cameras

IP Cameras


) / /(.


.

IP Camera


.
12



.CCTV



.
IP Camera . . . . . . . IP Camera - .

13

Bandwidth . - .

:5.2 IP Camera

5.2
-.

14


- 1
-2
-3
-4
-5
-6

1.3


-
.
2.3


.

.

.



.

16

3.3



:
1.3.3





) (


.

17

2.3.3


) ( .
:1.3

Total

Count U. Price

Part

Type

490 $

490 $

CPU Core2Due
Ram 2GB
HDD 500 GB

280 $

70 $

MSE color coms ms-216

Camera

60 $

15 $

EasyCap A/V to USB

Adapter

830 $

PC

Total

4.3
- 1 .
- 2 ) (.
:2.3

) (

) (

) (

18


.
5.3
) ( . :3.3

19

6.3
.
" "
) (Avi
.Online Streaming

.

Frames
.
Motion Detection

.
1.6.3
:
1.1.6.3 Monochrome :

) (1Bit/Pixel 0 1 .
640 x 480 .37.5 kb
20

:1.3 Monochrome

2.1.6.3 Gray
Gray
1Byte 0 255
) (640 x480 .300 kb

:2.3 Gray

3.1.6.3
Pixel 3Byte
) (
.
Blue
Green
Red

:3.3 RGB
21

Color
)(R,G,B

0 255
.
)Color(0-255,0-255,0-255

)Color(R,G,B

:4.3

2.6.3
RGB
Gray .
RGB Gray :
)Gray value= (R* 0.3) + (G *0.59) + (B * 0.11
Gray value= (R + G + B) /3
3.6.3 ) (Sampling

,
.

22

4.6.3 Motion Detection Algorithm


RGB
Gray ) (Frames
Gray
.


1.4.6.3
Continuous Frames Comparison Algorithm
Current
Frame Last Frame :
.Gray Pixel Pixel . Pixels Difference Threshold ) Pixel ( Pixel
Current Frame .
Difference Threshold Pixel Pixel Last Frame 255
Pixel .Current Frame

23

Pixels Current Frame .Pixels Changed


.
Motion Level:Motion Level=Pixels Changed / Frame Size

:5.3

24

Motion Level >0.25 .


- Motion Level >0.35 .

5.6.3
) (Frames
:
:
Gray Gray
) (2.6.3
.Motion Detection Algorithm
: )(

.

25

: ) (Pointers
)
Pixel (
.
) (Pointers
) (RAM

.

26


-1
=2
-3

1.4
65 5 3 (& 1

H, )5G
$ ,=

< : ;$

2.4
65

3 8836 . 1 7 3

&( >$ ,= :

, ; 1.2.4 ) BC A

( $ - & , "& * ) % &( "& $ % "#

)(Login
:1.4 Login

2.2.4

&( C D$

IA -

C D$

E ) F &(

"01 .

:2.4 )(Main
28

3.2.4

" &( F
I -

$ %< 6 $6 JF1 "# F

(& 1.

:3.4 )(Options

, ; 4.2.4 $ %< 6 $6
& , $ % 1 7 3< 6 $6.

:4.4 )(Change Password

29

5.2.4

) FG

$ < FG 1 ,

; = &" , ( P<" $

:5.4 )(Cameras

$ C C

6.2.4

SD 5A T U

< $

C C

<

$.

:6.4 )(Options
30

$ &N $F.

7.2.4
< Y

" &(
X1 &( )[$ & ( &N

$ A.

:7.4 )(Events

8.2.4

" $1 $;H

(E-Mail
:8.4 )Mail Setting
31

9.2.4

" ]

^ <&

.
).(Registry

(Phone Calls Settings


:9.4 ) Setting

10.2.4

$ "< T83 P E] 6

T83 E] 6= T

] E

$ "< P .T836

:10.4 )(Map Settings


32

11.2.4

<F

" &(

:11.4 )(About

12.2.4

"$ I BC G

:12.4 )(Record Viewer


33

13.2.4

"$ T83 E E] 6


Map
.

:13.4 )(Map

34

3.4

$` H< 6 , < 3 (& 1 7 3 E 8836 =

1.3.4

! ' %

) 5 ; <6 7 P
F6

$6 "< P) H, (Pixel) )C 1 5

:
)Gray value= (R* 0.3) + (G *0.59) + (B * 0.11

-1 ) .(Gray
-2 . i=0, j=0
-3 *$ i<Img.height

& G 83

- *$ j<Img.width

& G 83

)(i,j)Pix=Img.GetPixel(i,j
Gray=Pix.R*0.3+Pix.G*0.59+Pix.B*0.11
-

< 1 C

< 6 1 )C B H, Gray # N )(i,j

)Img.SetPixel(i,j,Gray
j=j+1-

i=i+1

-4 5 H, & Gray T6 $3

35

= H, f * ) ).(14.4

Start

Img=GetImage()

i=0 , j=0

No

i<Img.height?
Yes

i=i+1

j<Img.width?

No

Yes
Pix=Img.GetPixel(i,j)

Gray=Pix.R*0.3+Pix.G*0.59
+ Pic.B*0.11

Img.SetPixel(i,j,Gray)
j=j+1

Return Img

End
Gray :14.4

36

2.3.4

'* %

.
: -1 LastImg Gray .
-2 i=0, j=0, Threshold=20,PixChanged=0,
Height=LastImg.height, Width=LastImg.width
-3 CurrImg Gray
.
-4 *$ )(i<Height

& G 83

- *$ )(i<Width

Height:

& G 83

Width:

LastImg CurrImg )(i,j


]Diff=CurrImg[i,j]-LastImg[i,j
) (Thershold PixChanged .
PixChanged+=1

Diff>Threshold

j=j+1-5

i=i+1
IA F6

C C $ ) H, (Motion Level 5 " ) *1

)MotionLevel=PixChanged/(Height*Widht
-6 ; hhC; Yhh $hh
3

>

I hh 0.15 hh $hh & hh $ 6hh= hh hh5 hh $hh3 hh


jhh

$ < 83 ] 3 $ <6F 6

37

= H, f * ) ).(15.4

Start

LastImg=GetImage()
LastImg=ToGray(LastImg)

i=0 , j=0, Threshold=20


Height=LastImg.height
Width=LastImg.Width

CurrImg=GetImage()
CurrImg=ToGray(CurrImg)

No

i<Height?
i=i+1
j=0

Yes

j<Width?

No

Yes
Diff=CurrImg[i,j]-LastImg[i,j]

(Diff>Threshold)?

Yes

No
j=j+1

MotionLevel=PixChanged/(Height*Width)

MotionLevel>0.15

Yes
is Motion

No

End
:15.4
38

PixChanged+=1


-1
-2
-3

1.5
.
2.5
:
.(CPU:Core2Due,
(
)RAM:2GB, HD:250 ) Windows XP (. . 3.5
1.3.5 )(Login

.

:1.5 Login -

40

2.3.5 )(Main
).(2.5
: View ) (. : Start . : Stop . : Setting . : Viewer : Map . : Exit - .

:2.5 Main
41

4.3.5 )(Setting
/
) (General : ) (BtnChangePassword ).(4.5 : ).(ChkAutoStart ).(ChkOnTop ).(ChkDisableTaskMgr - ).(chkDisableRegistryTools

:3.5 General -

42

:4.5 Change Password -

)(Cameras ) (Active

.

).(Save Options

:5.5 Cameras

43

)(Options )(View
) (Stop
).(Property
)(Video Compressor

) (Sensitivity ) (Apply
.

:6.5 Options -

44

)(Events : :Save Video When Motion Detection .


:Alarm When Motion Detection . :Send E-Mail
Mail When Motion Detection ) Setting(.
:Phone Calls When Motion Detection ) Setting(.
:Show Map When Motion Detection )
Map Setting(.

:7.5 Events -
45

)(E-Mail Settings
.

E-Mail
:8.5 Mail Settings

)(Phone Calls Settings


.

:9.5 )(Phone Calls Settings


46

)(Map Settings Select Map



.

:10.5 )(Map Settings

47

)(About .

)(About
:11.5 About

48

5.2.5 )(Viewer
) (
.

:12.5 )(Records Viewer

49

6.2.5 ):(Map
Map )
(
.

:13.5 )(Map

50




-1
-2
-3
-4

1.6

.
2.6



) (
) (
.
3.6
-1
.
-2 .
-3 .
-4
) (.
-5
.

52

-6 .
-7
).(E-Mail
-8 .
4.6
:
) (. . - .

53

] [1 " C#" - .(2002)


] [2 " "C# - (2003)

]) http://www.shamelatec.ly [3

(.

]! ) h p://www.vb4arab.com [4 # $ ' &.(%


] &() ) http://www.smartsecurityest.com [5 + -.(,

54

55


Detection.cs (Detection Class):
using System;
using System.Timers;
using System.Drawing;
using System.Drawing.Imaging;
using System.Media;
using System.IO;
namespace SSC
{
public class Detection
{
Bitmap
OldFrame = null;
Bitmap
NewFrame = null;
JMDPlayer.JMDPlayer Player;
Camera
Cam = null;
Timer
TmrDetection = null;
SoundPlayer
SndPlayer=new SoundPlayer("Alarm.wav");
float
M_Level;
bool
Runing = false;
cImage
Cimage;
SSCSettings
Settings;
string
SavePath=System.Environment.GetFolderPath(Environment.SpecialFolder.System)+"
\\JMD";
public Detection(JMDPlayer.JMDPlayer player, Camera cam)
{
this.Player = player;
this.Cam = cam;
this.M_Level = cam.MotionLevel;
Cimage = new cImage();
Settings = new SSCSettings();
Settings.GetSetting();
TmrDetection = new Timer(500);
TmrDetection.Elapsed += new
ElapsedEventHandler(TmrDetection_Elapsed);
}
public bool isRuning
{
get { return Runing; }
}
public void StartMotionDetection()
{
OldFrame = Cimage.ToGray3(Player.GetCurrentVideoFrame());
Player.BorderColor = Color.Green;
TmrDetection.Start();
Runing = true;
if(Settings.SaveVideo==true)
Cam.StartTmrChkmotion();
}

56

public void StopMotionDetection()


{
TmrDetection.Stop();
Runing = false;
SndPlayer.Stop();
Cam.StopSave();
OldFrame = null;
Player.Start();
Player.BorderColor = Color.White;
}
private void TmrDetection_Elapsed(object sender, ElapsedEventArgs e)
{
NewFrame =Cimage.ToGray3(Player.GetCurrentVideoFrame());
if (Motion(NewFrame))
{
TmrDetection.Stop();
Cam.IsMotion = true;
if (Settings.AlarmActive == true)
{
try
{
FileInfo SndFile = new FileInfo(Settings.AlarmPath);
if (SndFile.Exists)
SndPlayer.SoundLocation = Settings.AlarmPath;
SndPlayer.PlayLooping();
}
catch (Exception SndEx)
{
SndPlayer.SoundLocation = "Alarm.wav";
SndPlayer.PlayLooping();
}
}

if (Settings.SendMailActive == true)
{
Mail Mailer = new Mail(Cam.Alias);
Mailer.GetMailSettings();
string ImgFile =SavePath+"\\"+ Cam.Alias + ".Jpg";
Cimage.saveJpeg(ImgFile, Player.GetCurrentVideoFrame(),
80);
Mailer.SendMessage(ImgFile);
}

if (Settings.SaveVideo == true)
{
Player.SignalToStop();
Player.WaitForStop();
Cam.Motion = true;
}
else
{
Player.TextColor = Color.Red;
}
}
}
private bool Motion(Bitmap NewFrame)

57

{
BitmapData bitmapData1 = OldFrame.LockBits(new Rectangle(0, 0,
OldFrame.Width, OldFrame.Height),
ImageLockMode.ReadOnly,
PixelFormat.Format24bppRgb);
BitmapData bitmapData2 = NewFrame.LockBits(new Rectangle(0, 0,
NewFrame.Width, NewFrame.Height),
ImageLockMode.ReadWrite,
PixelFormat.Format24bppRgb);
int a1 = 0, a2 = 0, Pix = 0;
unsafe
{
byte* imagePointer1 = (byte*)bitmapData1.Scan0;
byte* imagePointer2 = (byte*)bitmapData2.Scan0;
for (int i = 0; i < bitmapData1.Height; i++)
{
for (int j = 0; j < bitmapData1.Width; j++)
{
a1 = (imagePointer1[0]);
a2 = (imagePointer2[0]);
if (Math.Abs(a2 - a1) > 15)
{
Pix++;
}
//3 bytes per pixel
imagePointer1 += 3;
imagePointer2 += 3;
}//end for j
imagePointer1 += bitmapData1.Stride (bitmapData1.Width * 3);
imagePointer2 += bitmapData2.Stride (bitmapData2.Width * 3);
}//end for i
}//end unsafe
NewFrame.UnlockBits(bitmapData2);
OldFrame.UnlockBits(bitmapData1);
float MLevel = (float)Pix / (NewFrame.Width * NewFrame.Height);
if (MLevel > M_Level)
return true;
else
return false;
}
}
}

58

Camera.cs (Camera Class):


using System;
using System.Windows.Forms;
using System.Drawing;
using DirectX.Capture;
namespace SSC
{
public class Camera
{
bool
activated;
bool
inDetection;
bool
isMotion;
string
title;
string
name;
string
monikerString;
string
videoCompress;
string
compresorName;
string
alias;
string
description;
double
frameRate;
Size
frameSize;
Control
previewWindow;
Capture
capture;
bool
motion = false;
bool
recording=false;
float
motionLevel;
Timer
TmrChkmotion;
string
SavePath;
public Camera(string title)
{
this.title = title;
description = "Nothing";
frameRate = 29;
frameSize = new Size(320, 240);
previewWindow = null;
capture = null;
isMotion = false;
inDetection = false;
recording = false;
motionLevel = 0.15F;
TmrChkmotion = new Timer();
TmrChkmotion.Tick += new EventHandler(TmrChkmotion_Tick);
TmrChkmotion.Interval = 50;
SavePath =
System.Environment.GetFolderPath(Environment.SpecialFolder.System)+"\\JMD";
}
void TmrChkmotion_Tick(object sender, EventArgs e)
{
if (motion == true)
{
TmrChkmotion.Enabled = false;
SaveVideo();
}
}
public void StartTmrChkmotion()
{
TmrChkmotion.Enabled = true;
TmrChkmotion.Start();
}

59

public bool Activated


{
get { return activated; }
set { activated = value; }
}
public bool InDetection
{
get { return inDetection; }
set { inDetection = value; }
}
public bool IsMotion
{
get { return isMotion; }
set { isMotion = value; }
}
public bool Motion
{
get { return motion; }
set { motion = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Alias
{
get { return alias; }
set { alias = value; }
}
public string CompresorName
{
get { return compresorName; }
set { compresorName = value; }
}
public string Title
{
get { return title; }
set { title = value; }
}
public string Description
{
get { return description; }
set { description = value; }
}
public string MonikerString
{
get { return monikerString; }
set { monikerString = value; }
}
public string VideoCompress
{
get { return videoCompress; }
set { videoCompress = value; }
}
public double FrameRate
{
get { return frameRate; }
set { frameRate = value; }

60

}
public Size FrameSize
{
get { return frameSize; }
set { frameSize = value; }
}
public Control PreviewWindow
{
get { return previewWindow; }
set { previewWindow = value; }
}
public float MotionLevel
{
get { return motionLevel; }
set { motionLevel = value; }
}
public bool IsRecording
{
get { return recording; }//Capture.Capturing; }
}
public void SaveVideo()
{
try
{
Filter Filtervideo = new Filter(MonikerString);
Filter FilterCompress = new Filter(VideoCompress);
capture = new Capture(Filtervideo, null);
capture.VideoCompressor = FilterCompress;
capture.FrameRate = FrameRate;
capture.FrameSize = FrameSize;
capture.Filename = SavePath + "\\" + alias +
string.Format("{0:@dd-MM-yyyy.HH-mm-ss}", DateTime.Now) + ".jmd";
capture.Cue();
capture.PreviewWindow = previewWindow;
capture.Start();
recording = true;
}
catch (Exception ex) {MessageBox.Show(ex.ToString()); }
}
public void StopSave()
{
if (capture != null)
{
capture.PreviewWindow = null;
capture.Stop();
motion = false;
capture.Dispose();
recording = false;
}
}
public void SaveSetting(string Sub)
{
RegistrySSC.SetValue(Sub, "Activated", activated);
RegistrySSC.SetValue(Sub, "Name", name);
RegistrySSC.SetValue(Sub, "MonikerString", monikerString);
RegistrySSC.SetValue(Sub, "Title", title);
RegistrySSC.SetValue(Sub, "Description", description);
RegistrySSC.SetValue(Sub, "VideoCompress", videoCompress);
RegistrySSC.SetValue(Sub, "CompresorName", compresorName);

61

RegistrySSC.SetValue(Sub, "MotionLevel", motionLevel);


}
public void GetSetting(string Sub)
{
name = RegistrySSC.GetValue(Sub, "Name").ToString();
monikerString = RegistrySSC.GetValue(Sub,
"MonikerString").ToString();
title = RegistrySSC.GetValue(Sub, "Title").ToString();
description = RegistrySSC.GetValue(Sub,
"Description").ToString();
videoCompress = RegistrySSC.GetValue(Sub,
"VideoCompress").ToString();
compresorName = RegistrySSC.GetValue(Sub,
"CompresorName").ToString();
try
{
activated = bool.Parse(RegistrySSC.GetValue(Sub,
"Activated").ToString());
motionLevel = float.Parse(RegistrySSC.GetValue(Sub,
"MotionLevel").ToString());
}
catch (Exception ex)
{
//MessageBox.Show("GetSetting\r\n" + Sub + "\r\n" + name +
"\r\n" + ex.ToString(), "GetSetting");
}
}
}
}

62

You might also like