Categories: S60 | Python | Code Examples
This page was last modified 14:30, 19 March 2007.
Motion detection with camera
From Forum Nokia Wiki
This is inspired from the PIL version
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 = 1 def quit(): global running running = 0 app.exit_key_handler=quit def getdata(im, bpp=24): import struct, zlib im.save('D:\\pixels.png', bpp=bpp, compression='no') f = open('D:\\pixels.png', 'rb') f.seek(8 +8+13+4) chunk = [] while 1: 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 zlib.decompress(''.join(chunk)) # '\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 i in range(len(data)): if abs(ord(data[i])-ord(last1[i])) > 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()
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 3230 Camera Module | cashgoh | Python | 3 | 2006-11-01 13:48 |
| Nokia 6220 camera disabled | nsonthefly | General Discussion | 0 | 2006-01-13 00:01 |
| Rear/front camera on 6680 | mberionne | Symbian Media (Graphics & Sounds) | 3 | 2007-12-05 17:23 |
| Full functionality of camera | myuuuu | General Symbian C++ | 3 | 2008-02-18 07:20 |
| Using the camera module in 3rd edition SDK: KErrHardwareNotAvailable | lfd | Python | 0 | 2006-10-18 12:17 |
