maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Brainstorm (https://talk.maemo.org/forumdisplay.php?f=47)
-   -   N900 Sentry (https://talk.maemo.org/showthread.php?t=71156)

Soulaxe 2011-03-17 21:04

N900 Sentry
 
Could anyone create a small app that will turn the n900 into a stationary motion alarm? :D Like every second 15 frames will be compared and if anything has changed on the last taken frame an alarm will sound. K, thx.

laasonen 2011-03-17 21:20

Re: N900 Sentry
 
I once made python script like this for my netbook. Ill try to find it and test how it works on n900.

I couldn't find my script, but my friend who tried to do the same thing at the time had his :)

It used use fswebcam, but because we don't have it on maemo, I switched to gstreamer, but it works really slowly, so any faster ideas are welcome :)
Code:

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import subprocess
import math
import Image
import os

def imgdiff(A,B):
        Asize = A.size
        Bsize = B.size
        if(Asize != Bsize):
                B = B.resize(Asize)
        Apix = A.load()
        Bpix = B.load()
        diff = 0
        for x in range(0,Asize[0]/10):
                for y in range(0,Asize[1]/10):
                        diff += math.sqrt((Apix[x*10,y*10][0]-Bpix[x*10,y*10][0])**2 + (Apix[x*10,y*10][1]-Bpix[x*10,y*10][1])**2 + (Apix[x*10,y*10][1]-Bpix[x*10,y*10][1])**2)

        return 1 - (diff/(Asize[0]/10*Asize[1]/10))/(255.0*math.sqrt(3))

#Faster way on maemo?
def takePic():
        return subprocess.Popen("/usr/bin/gst-launch v4l2camsrc device=/dev/video0 num-buffers=1 \! video/x-raw-yuv,width=640,height=480  \! ffmpegcolorspace \! jpegenc \! filesink location=temp.jpg >> /dev/null", shell=True)

p = takePic()
sts = os.waitpid(p.pid, 0)
A = Image.open("temp.jpg")
p = takePic()

while True:
        if p.poll() == 0:
                B = A
                A = Image.open("temp.jpg")
                p = takePic()
                diff = imgdiff(A, B)
                if diff < 0.97:
                        print "Moves"


RenaldoTT 2011-03-18 00:59

Re: N900 Sentry
 
nice stuff guys


All times are GMT. The time now is 12:17.

vBulletin® Version 3.8.8