The iHart server uses the library openCV to detect motion and faces in a video feed.
It then edits the data, combining the motion ares to make them more representative of
the actual motion (without this, motion causes many small blobs around the edges), and
testing the found items for presence within areas of interest. The program the sends an
encoded string to give the coordinates of the blobs within each area of interest, using
using sockets, to communicate with client programs which decode the data and push events
at listening programs.
Part of the intention behind the project is to allow relatively inexperienced programmers
to create interactive programs that utilize computer vision.
When starting the program, a prompt appears with the option to choose a camera index.
Unless the computer has access to multiple cameras (and you wish to use one of them),
choose 0. Then drag the start trackbar to 1, starting the rest of the program. Three
windows will appear: if not all are visible, drag the top one(s) out of the way.
To draw an area of interest, click on the video feed window and drag: if unsatisfied with
the starting location, simply make it smaller until it turns red and release the mouse; it
will not be saved. Edit settings through thr trackbar window. To reset areas of interest,
simply change the position of the trackbar.
@author Kim Faughnan, 2013
Drawing on work done by Cleo Schneider and Audrey St. John.
||Runs the program by searching for motion and faces, updating the GUI, and sending information|
to any programs listening to the server socket (in SocketHandler).
||Methods defined here:|
- __init__(self, autostart=False, cameraindex=0)
- Creates a new window so that the user can set the camera index to use, and waits
until the user drags the start trackbar to 1, starting the rest of the program.
@param autostart: if false, displays the start / camera index chooser upon startup
@param cameraindex: initial value of the camera index
- Create the GUI for the server.
- decideCameraTrackbars(self, x)
- Set the camera index to use, display a help menu when requested, and start
the rest of the program when prompted.
@param x: unused parameter; remains for method signature to be correct.
- Searches for faces in the current image from the video feed and stores them in data.faceList
(as instances of Blob).
- Searches for motion in the video feed; puts the found motion in data.shellList (instances of Blob).
- editDetectedMotion(self, contours, hierarchy)
- Turns the raw motion data into instances of Blob and stores them in data.shellList
after also merging them when they are within mergeDistance of each other.
@param contours: the raw data for the motion.
@param hierarchy: the hierarchy of the contours.
- editFaces(self, rawFaceList)
- Convert the raw face data into instances of Blob, stored in data.faceList.
@param rawFaceList: the raw face data returned from detectMultiScale.
- mergeOverLappingMotion(self, shellList)
- Combines blobs when they are within data.mergeDistance of each other. mergeDistance is
from 0 to 0.9, inclusive, and mergeOverlappingMotion multiplies the coordinates of blobs
by 1 + mergeDistance or 1 - mergeDistance in order to increase chances of overlap. When the
two blobs in question do overlap, they are combined into one blob, which is placed into the
list (shellList) in their stead. The process is repeated until no more overlapping blobs are found.
@param shellList: the list of blobs to attempt to combine.
- Searches the video feed for faces and motion, draws items onto the display,
updates the display, and sends messages from the server socket to any waiting
clients (using SocketHandler).
(The only way to escape the loop is to drag the quit trackbar to 1).
- startMainServer(self, cameraIndex)
- Start the main program (sensing motion and sending it to clients).
@param cameraIndex: which camera to connect to.
- Updates the GUI.
Data and other attributes defined here:
- average = None
- cameraChosenTrackbar = 'start program'
- cameraIndex = 0
- cameraTrackbar = 'camera index'
- data = None
- faceClassifier = None
- hWindow = 'help window'
- helpImage = 'startupHelp.png'
- helpOpen = False
- helpTrackbar = 'help?'
- kernelSize = 3
- sWindow = 'start'
- server_socket = None
- startQuitTrackbar = 'quit'
- timer = None