Occasionally I use my Contour camera to record time lapses, generally of LAN parties, but the usual clouds and landscapes as well. The only issue with the contour is that the battery life is not great, about 3 hours taking photos every 15 seconds. One solution seemed to be that I could instead use the webcam on my laptop, or another device to record such events.
I also wanted to be able to analyse the images as they were taken so that ones without data could be discarded. This acts like the time capsules in police cars, if something of consequence occurs the computer records the last image, and several into the future on disk. otherwise it discards them.This has potential if i can wire it to an external camera for use at Kambah to track down the vandals, but was mostly just a fun exercise.
I used matlab to do the coding, although i may migrate to another language to create a standalone program.
For once it was easy to program, taking just one evening to get it to a working version, but enough of that. Here's the code:
function Webcam
% acts as an image logger for my hp computer, if anything in the image
% moves substantially, or the mean brightness of any column varies, then it
% takes that picture, and 15 to follow and writes them to a folder with the
% current date.
clc
clear
beep;
vid = videoinput('winvideo',1,'YUY2_640x480');
set(vid,'ReturnedColorSpace','grayscale');
start(vid)
mkdir(date)
go = 1;
beep;
pause(3)
beep;
pause(1)
beep;beep;
OldPic = getsnapshot(vid);
pause(4);
crimcount=1;
while go
pic = getsnapshot(vid);
% comparisons
olMean = mean(OldPic); % list of column means for the old image
NewMean= mean(pic);
% normalise them
olMean = olMean*mean(NewMean)/mean(olMean);
if min(olMean>0.95*NewMean)||min(olMean>1.05*NewMean)
change = 0; % No change from previous image
else
change = 1; % Change from previous image
%figure; imshow(pic);
image = 1; % reset image count
imagename=[date '/culprit' num2str(crimcount),num2str(image,'%02d'),'.jpg'];
imwrite(pic, imagename)
for i = 1:15
pic = getsnapshot(vid);
image = image+1;
imagename=[date '/culprit' num2str(crimcount),num2str(image,'%02d'),'.jpg'];
imwrite(pic, imagename)
pause(2)
end
crimcount=crimcount+1;
end
pause(3);
OldPic = pic;
end
% moves substantially, or the mean brightness of any column varies, then it
% takes that picture, and 15 to follow and writes them to a folder with the
% current date.
clc
clear
beep;
vid = videoinput('winvideo',1,'YUY2_640x480');
set(vid,'ReturnedColorSpace','grayscale');
start(vid)
mkdir(date)
go = 1;
beep;
pause(3)
beep;
pause(1)
beep;beep;
OldPic = getsnapshot(vid);
pause(4);
crimcount=1;
while go
pic = getsnapshot(vid);
% comparisons
olMean = mean(OldPic); % list of column means for the old image
NewMean= mean(pic);
% normalise them
olMean = olMean*mean(NewMean)/mean(olMean);
if min(olMean>0.95*NewMean)||min(olMean>1.05*NewMean)
change = 0; % No change from previous image
else
change = 1; % Change from previous image
%figure; imshow(pic);
image = 1; % reset image count
imagename=[date '/culprit' num2str(crimcount),num2str(image,'%02d'),'.jpg'];
imwrite(pic, imagename)
for i = 1:15
pic = getsnapshot(vid);
image = image+1;
imagename=[date '/culprit' num2str(crimcount),num2str(image,'%02d'),'.jpg'];
imwrite(pic, imagename)
pause(2)
end
crimcount=crimcount+1;
end
pause(3);
OldPic = pic;
end
To reduce processing I used grayscale images. They are compared as a mean value of the same column in each image, with a tolerence of 5%.
This makes it less sensitve than a region, or pixelwise comparison, but given that humans tend to move horizontally, and cover a large portion of a column this seemed like a good option. in addition the movement of the sun is largely vertical, so it should be ignored.
When a detection is made, the program writes the picture to a file, and then takes another 15 at ~2 second intervals, before returning to it's standby mode, looking for changes at 8 second intervals.
The program stores the images in a new folder with todays date, and numbers them #xx for the detection number, with xx being the picture the current sequence.
By running it from dropbox the files can be immediately uploaded to a cloud, allowing an offsite backup, as well as real time notifications. So far it has been running for 4 hours in m room, with 1 good detection, and zero false ones. The undetected ones I have no evidence for, but I suspect they are also absent, this will be ivestigated further this evening.
No comments:
Post a Comment