mattanl
Posts: 143
Joined: Thu Jun 14, 2012 10:40 am

Motion detection

Mon Apr 15, 2013 3:10 pm

Hi,
I want to implement motion detection using a simple webcam for my raspberry pi.
I've already done it few years ago in C# for my windows machine.
Do you know if is it possible to run motion detection algorithm on the pi? Do you know a python module for doing it?
Thanks.

User avatar
piglet
Posts: 915
Joined: Sat Aug 27, 2011 1:16 pm

Re: Motion detection

Mon Apr 15, 2013 3:52 pm

Hi,

I may be missing something, but there's a package called motion you can use for this:

http://linux.die.net/man/1/motion

Graz
Posts: 12
Joined: Wed Apr 10, 2013 7:47 pm

Re: Motion detection

Mon Apr 15, 2013 4:11 pm

I found this post very helpful as an intro to motion on the pi :

http://through-the-interface.typepad.co ... art-1.html

Cheers,
Graz

mattanl
Posts: 143
Joined: Thu Jun 14, 2012 10:40 am

Re: Motion detection

Mon Apr 15, 2013 4:12 pm

Thanks, but it doesn't seem like something I can embed in a program, or even a python script.


User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Motion detection

Mon Apr 15, 2013 4:34 pm

Try OpenCV, loads of info on t'internet and works in C and Python, I've been playing with face detection over the weekend and it works a treat. Fairly sure there's motion detection in there too.

Cheers.
Dave.
Apple say... Monkey do !!

User avatar
richiepp
Posts: 140
Joined: Wed Dec 19, 2012 4:56 pm

Re: Motion detection

Tue Apr 16, 2013 1:12 am

Not exactly what you're looking for but this could be informative
http://learn.adafruit.com/adafruits-ras ... g-movement

clixxio
Posts: 7
Joined: Fri Mar 29, 2013 1:01 pm

Re: Motion detection

Wed Apr 17, 2013 2:25 am

Motion is likely to be a good fit.

When it detects motion, it writes new .jpg files to the /tmp/motion directory.

You can poll this directory with your program and delete old files.

It's really extremely good at this. You only need to do this:

> sudo apt-get install motion
> sudo motion &

And it's running. Then write your code in whatever language you like.

AKopp
Posts: 11
Joined: Wed Apr 17, 2013 2:06 am
Location: Munich
Contact: Website

Re: Motion detection

Wed Apr 17, 2013 11:05 am

and how can I access this temp file?

gordon77
Posts: 5132
Joined: Sun Aug 05, 2012 3:12 pm

Re: Motion detection

Wed Apr 17, 2013 12:47 pm

image1 = pygame.image.load(/tmp/motion/<filename>) ?

Gordon77

AKopp
Posts: 11
Joined: Wed Apr 17, 2013 2:06 am
Location: Munich
Contact: Website

Re: Motion detection

Wed Apr 17, 2013 1:03 pm

Hi Gordon,

I meant how can I see it.

I figured it out.

Its the ip of my rasperry pie and the port

In my case 192.168.178.1:6789

What I do not get now is how can I turn the motion app off.

clixxio
Posts: 7
Joined: Fri Mar 29, 2013 1:01 pm

Re: Motion detection

Wed Apr 17, 2013 11:20 pm

> I meant how can I see it.

open your browser on the pi and type: http://127.0.0.1:8081

If you want to see it from other machines then you need to change the
configuration file /etc/motion/motion.conf:

Code: Select all

webcam localhost on
to:

Code: Select all

webcam localhost off
If you want to detect motion from python code use something like this:

Code: Select all

import glob, os
 while (1):
   filelist = glob.glob('/tmp/motion/*.jpg')
   if len(filelist):
       print "I have detected motion"
       for f in filelist:
           os.unlink(f) # remove each file
   time.sleep(2) # wait a little bit of time 
> What I do not get now is how can I turn the motion app off.
sudo killall motion

mattanl
Posts: 143
Joined: Thu Jun 14, 2012 10:40 am

Re: Motion detection

Thu Apr 18, 2013 7:39 am

Thanks.
What if I have more than 1 camera connected?

Return to “Python”