×
Namespaces

Variants
Actions

Archived:Motion detection with camera on PySymbian

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Article Metadata
Article
Created: cyke64 (19 Mar 2007)
Last edited: hamishwillee (31 May 2013)

This is inspired from the PIL version (link to original now broken - http://gumuz.looze.net/wordpress/index.php/archives/2005/06/06/python-webcam-fun-motion-detection/)

principle : phone takes pictures and compare them for detecting motion.

from appuifw import *
from graphics import Image
import camera, e32
#import miso # don't dim the light
 
app.body = c = Canvas()
 
running = True
def quit():
global running
running = False
app.exit_key_handler=quit
 
def getdata(im, bpp=24):
import struct
im.save('D:\\pixels.png', bpp=bpp, compression='no')
f = open('D:\\pixels.png', 'rb')
f.seek(8 +8+13+4)
chunk = []
while True:
n = struct.unpack('>L', f.read(4))[0]
if n==0: break # 'IEND' chunk
f.read(4) # 'IDAT'
chunk.append(f.read(n))
f.read(4) # CRC
f.close()
return ''.join(chunk).decode('zlib') # '\x00' prefix each line
 
last1 = '\x00' * 930 # can be anything
while running:
im = camera.take_photo('RGB', (160,120))
im.rectangle([(10,10),(40,40)], 0xff0000) # red outline
im.rectangle([(120,10),(150,40)], 0xff0000) # no code for this square
# check hot spot whether active
box = Image.new((30,30), 'L') # gray scale
box.blit(im, (10,10,40,40))
data = getdata(box, 8)
# check difference for motion
pixdiff = 0
for x,y in zip(data, last1):
if abs(ord(x)-ord(y)) > 15: # pix threshold 15/256
pixdiff += 1
if pixdiff > 90: # img threshold 90/900
im.rectangle([(10,10),(40,40)], fill=0xff0000) # fill
break # motion detected
last1 = data
c.blit(im, (0,0), (8,12)) # show camera
#miso.reset_inactivity_time()
This page was last modified on 31 May 2013, at 04:08.
132 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×