| |
- Data
class Data |
|
Stores and controls the data for the server; deals with formatting the data to
send over the server socket, and with updating the GUI display. |
|
Methods defined here:
- __init__(self, cameraIndex)
- Starts communication with the specified camera by getting a VideoCapture instance
from openCV, but does not store an image from the video feed yet.
@param cameraIndex: The index of the camera to communicate with
(if there is only one camera, it will always be index 0)
@return: none
- addAreaOfInterest(self, leftX, rightX, topY, bottomY)
- Creates a new AreaOfInterest with the given data and adds it to interestList.
@param leftX: The starting x coordinate of the area of interest.
@param rightX: The ending x coordinate of the area of interest.
@param topY: The starting y coordinate of the area of interest.
@param bottomY: The starting y coordinate of the area of interest.
@return: none
- createAreaData(self, interestArea)
- Creates an information string containing all the data of the given AreaOfInterest
(the data for all the areas of motion within the interest area, and then for all
the faces within the interest area). All coordinates are updated if the blob is only
partially within the area of interest. All coordinates are scaled according to scalingWidth
and scalingHeight (the dimensions of the client program) Calling this method in no way
changes the state of memory: all lists are unchanged after the call (any changes made to
coordinates only effect the output string: no Blob will have its fields changed).
The area string is formatted as follows:
{
"Faces": [ <face information>, <face information>, ... ],
"Shells": [ <shell information>, <shell information>, ... ]
}
<shell (motion) information> and <face information> are both formatted the same,
since they both represent rectangles of detected motion. The format is as
follows:
[ leftX, topY, width, height ]
We use a list since JSON does not use tuples.
@param interestArea: the AreaOfInterest that the string is being created for.
@return: the formatted message string.
- createGUI(self)
- Create the GUI for cvServer: video feed window, motion window, and settings window. Set the
video window to listen to mouse events, and add all the trackbars to the settings window.
@return: none
- createInformationString(self)
- Creates an information string to send to all of the client connections held by SocketHandler.
The string contains each area of interest. For each area of interest, every blob of detected
motion that is within that area is included, and then each face that is within that area. All
coordinates are updated if the blob is only partially within the area of interest. All coordinates
are scaled according to scalingWidth and scalingHeight (the dimensions of the client program)
Calling this method in no way changes the state of memory: all lists are unchanged after the
call (any changes made to coordinates only effect the output string: no Blob will have its
fields changed).
The format of the string itself is as follows (spaces added for readability):
[ <area information>, <area information>, ... ]
This repeats until the string ends with "
"
(if you are viewing in html, the string ends with "\ n \ 0" if you remove the spaces.)
The index of the <area information> corresponds to the number of the area of interest.
If there are no areas of interest, an empty string is returned.
<area information> is formatted as follows:
{
"Faces": [ <face information>, <face information>, ... ],
"Shells": [ <shell information>, <shell information>, ... ]
}
<shell (motion) information> and <face information> are both formatted the same,
since they both represent rectangles of detected motion. The format is as
follows:
[ leftX, topY, width, height ]
We use a list since JSON does not use tuples.
Several examples:
[ { "Faces": [], "Shells": [] }, { "Faces": [], "Shells": [] } ]
No motion blobs or faces were contained in either area of interest.
[ { "Faces": [], "Shells": [ [ 260, 136, 332, 200] ] },
{ "Faces": [], "Shells": [ [ 135, 0, 415, 400 ] ] } ]
One motion blob was in one area of interest, and one was in the other.
[ { "Faces": [ [ 63, 138, 639, 213 ] ], "Shells": [ [ 0, 0, 214, 630 ] ] },
{ "Faces": [], "Shells": [ [ 0, 20, 428, 105 ] ] } ]
Area 0 had a motion blob and a face, and Area 1 had a different motion blob and no faces.
@return: the formatted message string.
- drawAreasOfInterest(self)
- Draw all areas of interest.
@return:
- drawFaces(self)
- Draw all the faces.
@return: none
- drawMotion(self)
- Draw all the areas of motion.
@return: none
- editBounds(self, blob, interestArea)
- Determines whether the given Blob is within the given AreaOfInterest. If blob is outside of
interestArea, returns None. If blob is fully within interestArea, returns blob. If blob is
only partially within interestArea, returns a new Blob, cropped to only the portion within the
interestArea. Calling this method in no way changes the state of blob, interestArea, or any
other memory outside of this method and its return.
@param blob: the Blob to test for presence within interestArea.
@param interestArea: the AreaOfInterest to look for blob within.
@return: an instance of Blob if blob is within interestArea; None otherwise.
- getAreaOfInterest(self, index)
- Returns the area of interest at the specified interest.
@param index: the index to retrieve.
@return: the specified AreaOfInterest instance.
- mouseClicked(self, event, x, y, flags, extraParameter)
- Responds to left mouse click (cv2.EVENT_LBUTTONDOWN), mouse move/drag (cv2.EVENT_MOUSEMOVE),
and mouse release (cv2.EVENT_LBUTTONUP) to create an AreaOfInterest. Allows the user to drag
in any direction to create the AreaOfInterest, and does not create the AreaOfInterest if it
is less than a certain size (at which point the box on the window will be drawn in red).
Responds to right mouse click (cv2.EVENT_RBUTTONDOWN) by removing an area of interest.
@param event: the mouse event.
@param x: the x coordinate of the mouse.
@param y: the y coordinate of the mouse.
@param flags: unused (present for correct function signature)
@param extraParameter: unused (present for correct function signature)
@return: none
- resetAreas(self)
- Deletes all the current areas of interest.
@return: none
- updateGUI(self)
- Displays the current captured image (the most recent) on the video window.
@return:
- updateTrackbars(self, x)
- Responds to movement of the trackbars by updating the appropriate settings.
@param x: unused (present for correct signature)
@return: none
- updateVideo(self)
- Updates current video capture, and flips it horizontally if flipHorizontal is currently enabled.
@return: none
- updateVideoAndGUI(self)
- Updates the current image from the video feed and displays it.
@return: none
Data and other attributes defined here:
- average = None
- blurTrackbar = 'blur value'
- blurValue = 3
- creatingAreaOfInterest = False
- difference = None
- dilateKernel = None
- dilateTrackbar = 'increase blob size'
- dilationValue = 0
- faceList = []
- facesEnabled = False
- facesTrackbar = 'enable faces'
- flipHorizontal = False
- flipTrackbar = 'flip horizontally'
- gWindow = 'settings'
- hWindow = 'help window'
- height = 180
- helpImage = 'mainHelp.png'
- helpOpen = False
- helpTrackbar = 'help?'
- holeList = []
- iHartHeight = 180
- iHartWidth = 240
- interestList = []
- mWindow = 'motion'
- mergeDistance = 0.3
- mergeTrackbar = 'merge within distance'
- motionEnableTrackbar = 'enable motion'
- motionEnabled = True
- motionThreshold = 20
- motionTrackbar = 'motion threshold'
- noiseKernel = None
- noiseReductionValue = 0
- noiseTrackbar = 'reduce noise'
- quitTrackbar = 'quit'
- referenceShot = None
- scalingHeight = 500
- scalingWidth = 800
- shellList = []
- vWindow = 'server'
- video = None
- videoCapture = None
- width = 240
- workingAreaOfInterest = None
| |