#!/usr/bin/python """ This SimpleCV example uses a technique called frame differencing to determine if motion has occurred. You take an initial image, then another, subtract the difference, what is left over is what has changed between those two images this are typically blobs on the images, so we do a blob search to count the number of blobs and if they exist then motion has occurred """ import time from simplecv.api import Camera, Blob cam = Camera() # setup the camera # settings for the project # make the threshold adaptable for various camera sizes min_size = 0.1 * cam.get_property("width") * cam.get_property("height") thresh = 10 # frame diff threshold show_message_for = 2 # the amount of seconds to show the motion detected message motion_timestamp = int(time.time()) message_text = "Motion detected" draw_message = False last_img = cam.get_image() last_img.show() while True: new_img = cam.get_image() track_img = new_img - last_img # diff the images blobs = track_img.find(Blob) # use adaptive blob detection now = int(time.time())
#!/usr/bin/python """ This program basically simulates some kind of 80's music video. """ print __doc__ from simplecv.api import Camera, Blob cam = Camera() # settings for the project min_size = 0.1 * cam.get_property("width") * cam.get_property("height") # Change threshold thresh = 10 # frame difference threshold last_img = cam.get_image() last_img.dl().text("Move around to get the party started!", (5, 5)) last_img.show() while True: new_img = cam.get_image() track_img = new_img - last_img # difference the images blobs = track_img.find(Blob, -1, threshblocksize=99) # use adapative blob detection if blobs: blobs.draw(autocolor=True) track_img.show() last_img = new_img # update the image