Reply
Thread Tools
Posts: 118 | Thanked: 31 times | Joined on Feb 2010
#1
Could anyone create a small app that will turn the n900 into a stationary motion alarm? 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's Avatar
Posts: 565 | Thanked: 618 times | Joined on Jun 2010 @ Finland
#2
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"

Last edited by laasonen; 2011-03-17 at 22:01.
 
RenaldoTT's Avatar
Posts: 511 | Thanked: 128 times | Joined on Aug 2010 @ Trinidad and Tobago
#3
nice stuff guys
__________________
Trini 2 D' Bone

I miss my N900
Hello DELL Venue Pro Mango
Listen to my music >>> www.reverbnation.com/rrule

TRINIDAD & TOBAGO
 
Reply


 
Forum Jump


All times are GMT. The time now is 07:58.