BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Security camera image storage question.

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
Dodgy
Guest





PostPosted: Thu Sep 01, 2005 1:06 pm    Post subject: Security camera image storage question. Reply with quote



Hi all,

I've got a blank and white low light security camera hooked up to a
WinTV card and I'm happily capping images every second onto the hard
drive.

I'm using the EAVCap component, and it works fine. I was originally
saving the images off as BMP, but at over a meg a file I was going to
run out of hard drive before I'd capped a day.

My plan was to hold a 7 day loop of images, so I now save them off as
greyscale jpeg with 75% quality and that produces images of about 40k,
which will just about squeeze 7 days onto the hard drive space I have.

I'm storing the images in a directory structure as follows

c:capsday_numberhourminsec.jpg

The day number rotates from 1 to 7.

Anyway, that's all well and good except if something happens I have to
spend ages trawling through images to find it.

So what I want to do now, to reduce disk storage and aid detection, is
to do some comparison between the image I just capped, and the image I
capped a second before, and only if I have enough of a difference,
write the image file to the disk.

I've got the last and next images on the screen in two Timage
components, but I need a fast way to compare and decide. I'm capping
at 1 a second, and the machine isn't anything amazing (550Mhz Pentium
3, 256meg ram, win2k pro).

So can anyone offer any suggestions on how to calculate a difference
level between 2 images so I can check this against a threshold?

Cheers

Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
Back to top
Maarten Wiltink
Guest





PostPosted: Thu Sep 01, 2005 2:29 pm    Post subject: Re: Security camera image storage question. Reply with quote



"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> wrote


Quote:
I've got a blank and white low light security camera hooked up to a
WinTV card and I'm happily capping images every second onto the hard
drive.
[...]
Anyway, that's all well and good except if something happens I have to
spend ages trawling through images to find it.

Just play them at 30 or 50 fps. When you hit the button, replay the
last second at 5 fps and pause.

I think that a one-second interval is shorter than strictly necessary.
There's nothing actually wrong with capturing that many images, but
perhaps you could skip two or three for every frame you display, or
blend a few consecutive images together. That's assuming this is a
stationary camera.

Groetjes,
Maarten Wiltink



Back to top
Tom de Neef
Guest





PostPosted: Thu Sep 01, 2005 2:41 pm    Post subject: Re: Security camera image storage question. Reply with quote



"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> schreef in bericht
news:2fudh1tue1jhpg7ch9gbn66jem5dnf3fvc (AT) 4ax (DOT) com...
Quote:

....

I've got the last and next images on the screen in two Timage
components, but I need a fast way to compare and decide. I'm capping
at 1 a second, and the machine isn't anything amazing (550Mhz Pentium
3, 256meg ram, win2k pro).

So can anyone offer any suggestions on how to calculate a difference
level between 2 images so I can check this against a threshold?


For a bitmap your differential criterium is related to sum(abs(difference)),
where you sum over all pixels and interpret them as integers. With jpeg this
may also work, you'll have to try.
Beware: even a stationary camera may vibrate a bit (wind, etc). An image
that is displaced by one bit may result in quite a big differential.
It may also help to cut from the image the parts that you're not interested
in (like anything above 2 meters).
I wonder if google's Picasa could help you with an overview of what you've
captured.
Tom



Back to top
Dodgy
Guest





PostPosted: Thu Sep 01, 2005 3:11 pm    Post subject: Re: Security camera image storage question. Reply with quote

On Thu, 1 Sep 2005 16:41:04 +0200, "Tom de Neef" <tdeneef (AT) qolor (DOT) nl>
waffled on about something:

Quote:
"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> schreef in bericht
news:2fudh1tue1jhpg7ch9gbn66jem5dnf3fvc (AT) 4ax (DOT) com...

...

I've got the last and next images on the screen in two Timage
components, but I need a fast way to compare and decide. I'm capping
at 1 a second, and the machine isn't anything amazing (550Mhz Pentium
3, 256meg ram, win2k pro).

So can anyone offer any suggestions on how to calculate a difference
level between 2 images so I can check this against a threshold?


For a bitmap your differential criterium is related to sum(abs(difference)),
where you sum over all pixels and interpret them as integers. With jpeg this
may also work, you'll have to try.

I'm planning on putting this into the capping app, so the check can be
done against the bitmaps before any chance of random jpeg artifacts
can have an effect.
Is there a quick way of comparing two 768x576 pixel images, creating
some kind of numerical amount of change value and be able to keep up
with the capture rate?

Quote:
Beware: even a stationary camera may vibrate a bit (wind, etc). An image
that is displaced by one bit may result in quite a big differential.

I don't mind a few false triggers, it's not going to be triggering an
alarm or anything, it's purely recording. Even a 10:1 false to real
movement trigger would be fine, at the moment I'm getting 3600 images
an hour, with all but 20 being a view of a closed door!

Quote:
It may also help to cut from the image the parts that you're not interested
in (like anything above 2 meters).
I wonder if google's Picasa could help you with an overview of what you've
captured.

I really want to try and remove the redundant frames at source, as
opposed to finding a faster way to scroll through them. Hard drive
space is going to be an issue, and when this is fully up and running
it will be pushing the images down the VPN across to our co-location
site. At which point the bandwidth it uses will become an issue (well
for the accountant anyway!).

Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES

Back to top
Dodgy
Guest





PostPosted: Thu Sep 01, 2005 3:18 pm    Post subject: Re: Security camera image storage question. Reply with quote

On Thu, 1 Sep 2005 16:29:23 +0200, "Maarten Wiltink"
<maarten (AT) kittensandcats (DOT) net> waffled on about something:

Quote:
"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> wrote in message
news:2fudh1tue1jhpg7ch9gbn66jem5dnf3fvc (AT) 4ax (DOT) com...

I've got a blank and white low light security camera hooked up to a
WinTV card and I'm happily capping images every second onto the hard
drive.
[...]
Anyway, that's all well and good except if something happens I have to
spend ages trawling through images to find it.

Just play them at 30 or 50 fps. When you hit the button, replay the
last second at 5 fps and pause.

I think that a one-second interval is shorter than strictly necessary.
There's nothing actually wrong with capturing that many images, but
perhaps you could skip two or three for every frame you display, or
blend a few consecutive images together. That's assuming this is a
stationary camera.

Groetjes,
Maarten Wiltink

Hi Maarten,

Not a bad idea, but I'd really like to automatically remove as much
redundant footage as possible at source. At the moment I'm capping to
a local harddrive, but shortly I'll be capping across our VPN to the
co-location site. (Not much point having a security camera if the
buggers can break in and steal the machine with all the images on
it!).
At that point although one 40k jpeg a second isn't going to bother the
VPN bandwidth, the company accountant will come and moan at me as we
have an allocated traffic volume per month with the co-location host
company, and that level of constant data is pretty much going to use
it all up. Then we'll start incurring burst traffic charges.

Yes it is a stationary camera, it looks at a door. I tried dropping
the capture rate, but found 1 a second is the best minimum that
guarantees a good mug shot of anyone coming through the door.

Dodgy.

Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES

Back to top
Tom de Neef
Guest





PostPosted: Thu Sep 01, 2005 3:34 pm    Post subject: Re: Security camera image storage question. Reply with quote

Quote:

For a bitmap your differential criterium is related to
sum(abs(difference)),
where you sum over all pixels and interpret them as integers. With jpeg
this
may also work, you'll have to try.

I'm planning on putting this into the capping app, so the check can be
done against the bitmaps before any chance of random jpeg artifacts
can have an effect.
Is there a quick way of comparing two 768x576 pixel images, creating
some kind of numerical amount of change value and be able to keep up
with the capture rate?


If it is in a Tbitmap, use scanline:
(P1,P2 : PbyteArray; delta : integer;)
delta:=0;
for y := 0 to BitMap1.Height -1 do
begin
P1 := BitMap1.ScanLine[y];
P2 := BitMap2.ScanLine[y];
for x := 0 to BitMap1.Width -1 do inc(delta,abs(P1[x]-P2[x]))
end;

If it takes too long, compare every other 10th line or so.
Tom



Back to top
Nicholas Sherlock
Guest





PostPosted: Thu Sep 01, 2005 7:50 pm    Post subject: Re: Security camera image storage question. Reply with quote

Dodgy wrote:
Quote:
So can anyone offer any suggestions on how to calculate a difference
level between 2 images so I can check this against a threshold?

Take a look at Graphics32 http://www.g32.org. I never leave home without
it Smile. It's a really fast graphic library that may well help out here.
It has ultra fast pixel access compared to TBitmap (The only downside is
that, for speed reasons, the only supported format is 32bit bitmap).

var x,y:integer;
diff:integer;

assert(bmp1.width=bmp2.width,'!');
assert(bmp1.height=bmp2.height,'!');

diff:=0;
for y:=0 to bmp1.height-1 do
for x:=0 to bmp1.width-1 do

diff:=diff+abs(redcomponent(bmp1.pixel[x,y])-redcomponent(bmp2.pixel[x,y]));

if diff>threshold then showmessage('Changed!');


You can speed it up even more by using pointers:

var bmp1, bmp2: tbitmap32;
p1, p2: PColor32;
diff, x, y: integer;
begin
diff := 0;
for y := 0 to bmp1.height - 1 do begin
p1 := bmp1.PixelPtr[0, y];
p2 := bmp2.PixelPtr[0, y];
{Compare blue components to avoid shifts}
for x := 0 to bmp1.width - 1 do begin
diff := diff + abs(p1^ and $FF - p2^ and $FF);
inc(p1);
inc(p2);
end;
end;
if diff > threshold then
showmessage('Changed!');
end;

Cheers,
Nicholas Sherlock

Back to top
Paul Dunn
Guest





PostPosted: Fri Sep 02, 2005 9:33 am    Post subject: Re: Security camera image storage question. Reply with quote

Nicholas Sherlock wrote:
Quote:
Dodgy wrote:
So can anyone offer any suggestions on how to calculate a difference
level between 2 images so I can check this against a threshold?

Take a look at Graphics32 http://www.g32.org. I never leave home
without it Smile. It's a really fast graphic library that may well help
out here. It has ultra fast pixel access compared to TBitmap (The
only downside is that, for speed reasons, the only supported format
is 32bit bitmap).

If you manage to track down a copy of FastLIB (which appears to have
vanished) you can work in any depth you like. FastLIB provides the same
Pixel routines as an array offset into the DIB surface, and is blazingly
fast. Another up-side is that the DIB surface is exposed as a flat array of
bytes, so using BASM to write to it as you would any DDraw surface is
trivial.

I write a lot of very graphically intensive code, and found FastLIB to be
better than Graphics32 when working with offscreen directdraw surfaces - as
you can use whichever bit depth the user prefers for their desktop.

[warning, rambling ahead]

However, if you're wanting to work with graphics at a reasonable speed and
don't like to dip into assembly, then you might consider a C/C++ compiler -
Delphi's compiler can often bite you in the bum with some very sub-optimal
code. This may have changed with Delphi 2005, but my tests indicate that
Borland have only stepped around the compiler crapness by providing inline
code rather than addressed it directly.

On the other hand, most apps don't *need* fantastic speed except at certain
points, and making the jump to C/C++ purely for performance reasons might be
a bad idea when weighed up against the fact that Delphi is easier to code,
and only occasionally needs assembly.

My app BASin (http://homepage.ntlworld.com/paul.dunn4/BASin_r12.exe,
contains *DELPHI 5* source - tested under Delphi 2005, but that version of
Delphi has issues) is an example - the user interface is written in Delphi
(and badly at that) but the z80 emulation core (FastCore.pas) is extremely
fast - written in BASM for the main as many z80 opcodes can be translated
into one or two x86 opcodes which you'd find extremely difficult to do in
pure Delphi-pascal. That said, it's the only win32-based z80 core that runs
on a 50mhz 486. Any optimisations that people can offer would be gratefully
accepted... I'm not too proud of much of my code, but some of it I love.

The UpdateDisplay() procedure in FastCore.pas is an example of working with
a FastLIB surface in assembly.

And yes, it *is* a Development environment for a 20 year old obsolete
computer :-)

Crikey, that didn't manage to stay on-topic for long, did it?

D.



Back to top
J French
Guest





PostPosted: Fri Sep 02, 2005 12:46 pm    Post subject: Re: Security camera image storage question. Reply with quote

On Thu, 01 Sep 2005 16:18:25 +0100, Dodgy
<Dodgy (AT) earth (DOT) planet.universe> wrote:

Quote:
On Thu, 1 Sep 2005 16:29:23 +0200, "Maarten Wiltink"
[email]maarten (AT) kittensandcats (DOT) net[/email]> waffled on about something:

"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> wrote in message
news:2fudh1tue1jhpg7ch9gbn66jem5dnf3fvc (AT) 4ax (DOT) com...

I've got a blank and white low light security camera hooked up to a
WinTV card and I'm happily capping images every second onto the hard
drive.

Interesting problem

Comparing bitmaps is a bitch

In this case I would think sideways

- what you want is a film show of activity, and nothing but
confirmation when there is no activity

Rig up some motion sensors and let the system go wild when there is
activity - otherwise let it just write a date/time click and a visual
every minute (or longer)

I'm not keen on your data storage mechanism
- it is rational - but will bite you in the but
Just append the JPGs to one large file - open, store, close



Back to top
Dr John Stockton
Guest





PostPosted: Fri Sep 02, 2005 5:58 pm    Post subject: Re: Security camera image storage question. Reply with quote

JRS: In article <ah6eh1942ul4448imb6hvmakgfqlav8jf0 (AT) 4ax (DOT) com>, dated
Thu, 1 Sep 2005 16:18:25, seen in news:comp.lang.pascal.delphi.misc,
Dodgy <Dodgy (AT) earth (DOT) planet.universe> posted :
Quote:

Yes it is a stationary camera, it looks at a door. I tried dropping
the capture rate, but found 1 a second is the best minimum that
guarantees a good mug shot of anyone coming through the door.

Calculate the average of the picture, for each of the primary colours.
Store images while the colour is changing significantly faster than
usual. You can check this by dressing in suitable clothes and walking
through the door.

Of course, if it's *your* door, you could paint it and/or its background
a helpful colour or fit a microswitch by a hinge.

--
© John Stockton, Surrey, UK. *@merlyn.demon.co.uk / ??.Stockton (AT) physics (DOT) org ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Correct <= 4-line sig. separator as above, a line precisely "-- " (SoRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)

Back to top
Darius Blaszijk
Guest





PostPosted: Sat Sep 03, 2005 12:06 am    Post subject: Re: Security camera image storage question. Reply with quote

On Fri, 02 Sep 2005 18:58:23 +0100, Dr John Stockton wrote:

Quote:
Calculate the average of the picture, for each of the primary colours.
Store images while the colour is changing significantly faster than
usual. You can check this by dressing in suitable clothes and walking
through the door.

To increase the processing speed, you can also consider clipping a
rectangle from the picture. Just check within a certain area.

Make a diff of the area and if more than x percent of the image differs
with more than a certain threshold (to eliminate noise) than store the
images.

HTH Darius Blaszijk

Back to top
Michal Borsuk
Guest





PostPosted: Sat Sep 03, 2005 6:55 am    Post subject: Re: Security camera image storage question. Reply with quote

Dodgy wrote:
Quote:
Hi all,


So what I want to do now, to reduce disk storage and aid detection, is
to do some comparison between the image I just capped, and the image I
capped a second before, and only if I have enough of a difference,
write the image file to the disk.

This is what movie compression does (MPEG2, DivX etc.). I only know that
from the theory side, but how about trying to create acompressed avi
with those frames? You'd solve the problem going through images as well.
Just need to add date+time to the image.


Quote:
Cheers

Dodgy.


--
Michal Borsuk
Advanced Call Manager - a call register and manager.
http://www.advancedcallmanager.com/


Back to top
Bob Swart
Guest





PostPosted: Sun Sep 04, 2005 6:31 am    Post subject: Re: Security camera image storage question. Reply with quote

Hi Dodgy,

Quote:
So can anyone offer any suggestions on how to calculate a difference
level between 2 images so I can check this against a threshold?

I've done this for a webcam, and wrote about it for The Delphi Magazine
(www.TheDelphiMagazine.com) in issue #109. You can download the source
code from http://www.drbob42.com/tdm

My algorithm compared the individual R G and B values of the two
pictures against each other.

Note that for a 640 x 480 bitmap, a number of pixels may be different
without any actual motion being detected (especially when watching
something that includes sunlight and shades - like my garden). So I had
to add a minimum diff constant, to ignore small changes as motion...

Basically, the code to compare was:

for y:=0 to CaptureHeight-1 do
begin
for x:=0 to CaptureWidth-1 do
begin
NewRGB.RGBColor :=
ColorToRGB(CaptureImage.Picture.Bitmap.Canvas.Pixels[x,y]);
OldRGB.RGBColor :=
ColorToRGB(PreviousImage.Picture.Bitmap.Canvas.Pixels[x,y]);
if (abs(NewRGB.R - OldRGB.R) > $F) and
(abs(NewRGB.G - OldRGB.G) > $F) and
(abs(NewRGB.B - OldRGB.B) > $F) then Inc(diff);
end

Note that I'm also using a $F value as ignorable difference between the
R, G and B values in the first place, otherwise the compare was too
sensitive.

It works fine on the webcam in my garden, which doesn't get triggered by
movement of leaves, but does get triggered when our cat enters the view.

Quote:
Dodgy.

Groetjes,
Bob Swart (aka Dr.Bob - www.DrBob42.com)

--
Bob Swart Training & Consultancy (eBob42) - Borland Technology Partner
Delphi 2005 PDF manuals available from http://www.drbob42.com/training

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.