Ask Your Question

movement and distance detection within a room

asked 2014-03-02 10:47:28 -0500

anonymous user


I am building a program that detects/tracks movement within a room and can determine where (quadrant or distance) that movement is within the room. Any suggestions on how this can be accomplished??

Further detail: Say the camera detects a person within the room from their movement when this happens I need to relay information that 1) there is movement (a person) and 2) spatially where they are within the room either by dividing the room into quadrants and relaying the quadrant or relay the distance from the camera (which is stationary).


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-03-05 19:16:02 -0500

mechiris gravatar image

Try this for starters. Uses image differences from the last frame, and quandrant sum of pixels comparison.

cam = Camera()
lastimgimg = cam.getImage()
midw = img.width / 2
midh = img.height /2 
motionthreshold = 1000000  #you will need to tweak this to determine what the baseline for motion detection is
while True:
   img = cam.getImage()
   diffimg = (lastimg - img) + (img - lastimg) #obtain difference image
   grayim = diffimg.getGrayNumpy()
   #split into quandrants and get sum pixel scores
   quadscores = np.zeros(4)
   quadscores[0] = sum(grayim[0:midw,0:midh])
   quadscores[1] = sum(grayim[midw:,0:midh])
   quadscores[2] = sum(grayim[0:midw,midh:])
   quadscores[3] = sum(grayim[midw:,midh:])

   for x in range(len(quadscores)):
       if quadscores[x] > motionthreshold:
           print 'Motion in ' + str(x) + ' quadrant'

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2014-03-02 10:47:28 -0500

Seen: 266 times

Last updated: Mar 05 '14