Implementation of Hand Detection Based Techniques For Human Computer Interaction
Implementation of Hand Detection Based Techniques For Human Computer Interaction
Implementation of Hand Detection Based Techniques For Human Computer Interaction
6
International Journal of Computer Applications (0975 – 8887)
Volume 72– No.17, June 2013
7
International Journal of Computer Applications (0975 – 8887)
Volume 72– No.17, June 2013
maxval - is only used in some of the different ways Using OpenCV library this is done by passing a special
of applying the thresholding function. In the current case parameter THRESH_OTSU as the variable type in the
of binary thresholding does not use this variable thresholding function given in 3.1.1.1 Static Thresholding.
The thresholding function ignores thevalue in the variable
type - defines the type of thresholding applied on the thresh which was used to pass the threshold value in earlier
image. In our case this is THRESH_BINARY cases. But in place of that the function calculates the threshold
value using the Otsu’s Method and threshold the image as per
this threshold value which minimizes the within group
3.1.1.2 Incremental Thresholding Value variance.
In this method, same pre-processing as in the static
thresholding value is done on the image input frame,
converting from RGB to Grayscale. Instead of using a
constant value for every input image frame, the threshold
value is incremented till a condition is not met. For this
method, a minimum threshold value is set and then the input
image frame is thresholded using this value. If the current
thresholding value does not fulfil the condition, then the
thresholding value is incremented and again the same
procedure is followed till the condition is met. The condition
to detect hand is until only one white blob is present in the
thresholded image. The detected white blob can also be some
other object so whether the detected object is a hand or not is
decided by the hand detection part explained further.
In this method, the function described in 3.1.1.1 is used i.e. 3.1.1.4 Dynamic Thresholding using Color at
Static Thresholding. But in this case the thresholding value Real Time
keeps on incrementing, that is the variable thresh is
incremented by value ‘1’ in a range from 20 to 160, till we Unlike previous methods of thresholding, in this method color
detect only one contour in the input image. based thresholding is done. This can also be termed as color
level slicing. Initially the user has to give some dummy input
3.1.1.3 Thresholding using Otsu’s Method image frames with the hand to be detected in the central part
Otsu’s Methodis used to automatically select a threshold value of the image. The system would do the analysis on these
based on the shape of the histogram of the image. This dummy input frames and generating dynamic threshold values
algorithm assumes that the image contains two dominant in RGB. In this analysis, a small central circular part, with
peaks of pixel intensities in the histogram that is two classes arbitrary radius, of the dummy input frames is considered
of pixels. The histogram should be bi-model for using this initially. The first two pixels of the central part are set as
method. The two classes are foreground and background. The minimum pixel value and maximum pixel values. Then rest
algorithm tries to find the optimal threshold value using which all pixels in the central part are processed. For every pixel
the two classes are separated in such a way that their intra- value that is scanned, it is compared with the minimum and
class variance or combined spread is minimal. The threshold maximum pixel values. If the scanned pixel value is less than
value given by the Otsu’s Method thus in our case works well the minimum pixels value then the minimum pixel value is
since the images contain two type of pixels, background updated to the scanned pixel value. Similarly if scanned pixel
pixels and hand pixels. Thus the two classes are background value is more than that of maximum pixel value, then the
and hand. So the threshold value tries to separate the peaks in maximum pixel value is updated to the scanned pixel value.
order to give minimal intra-class variance. The example The range defined by the Minimum and Maximum pixel value
output is given in the figure 4. is used to threshold the image, whichever pixel comes
between this ranges is considered as hand pixel.
8
International Journal of Computer Applications (0975 – 8887)
Volume 72– No.17, June 2013
This method is very accurate to segment the hand if the gradient is always perpendicular to the contour lines. When
intensity of the hand does not alter much during usage. It can the lines are close together, the magnitude of the gradient is
detect any color of hand thus making it independent of the usually very large. Contours are straight lines or curves
user’s skin color. The dummy input frames should have the describing the intersection of one or more horizontal planes
hand in the central part else the entire system collapses since with a real or hypothetical surface with.
the range decided is not actually for the hand. The background
should not contain pixels with values that fall in between the The contour is drawn around the white blob of the hand that is
decided range as they too would be included as hand pixels. found out by thresholding the input image. There can be
possibilities that more than one blob will be formed in the
3.1.2 Relaxed Background Constraints image due to noise in the background. So the contours are
drawn on such smaller white blobs too. Considering all blobs
3.1.2.1 Color based Thresholding formed due to noise are small, thus the large contour is
In color based thresholding, static values of hand color are considered for further processing specifying it is contour of
considered for thresholding. RGB values of hand are taken hand.
with minimum RGB value and maximum RGB value as a
range. These ranges are selected after analysing the general In this implementation, after preprocessing of the image
range of color of human hands. Then the input image frame frame, white blob is formed. Contour is drawn around this
uses these two minimum and maximum RGB values for
thresholding. Any pixel between this range is considered as
the hand pixel so it is set to 1 and pixels outside this range are
considered as background pixel is set to 0. As there are no
background constraints in this method, it is highly prone to
noise.
9
International Journal of Computer Applications (0975 – 8887)
Volume 72– No.17, June 2013
color – is of the data type Scalar and it is a constant hull – this acts as the storage for the hull output.
value. This is the color to be used to draw the contours Either it is a vector of indices of the points parameter if
all the hull points are present in the points vector or the
thickness – defines the thickness of the line to be points itself if all the hull points do not exist in the points
used to draw the contours. If this value is negative, then parameter
the contours are filled with the color specified. Default
value is set to 1 clockwise – this is the orientation flag. If it is true
then the output convex hull is oriented in the clockwise
lineType – is to select how the lines are drawn direction. Else in the anti-clockwise direction. By default
whether they are 8-connected line, 4-connected line and it is set to false
CV_AA for antialiased line
returnPoints – if the points parameter is a vector
heirarchy – this is optional information only in place of a matrix which it is in our case, the
required when only some of the contours are required to returnPoints variable is ignored. Else in case of a matrix,
be drawn this flag decided whether the hull output storage stores
the indices of points or the points itself. By default this is
set to true
offset – optional offset to add to contour points
while drawing The convex hulls are also drawn on an image using the same
3.2.2 Convex Hull function drawContours as explained in section 3.2.1 Contours.
The convex hull of a set of points in the euclidean space is the This is because both, contours and convex hulls are nothing
smallest convex set that contains all the set of given points. but a collection of points which needs to be connected with
For example, when this set of points is a bounded subset of straight lines.
the plane, the convex hull can be visualized as the shape
formed by a rubber band stretched around this set of points. 3.2.3 Convexity Defects
When the convex hull is drawn around the contour of the
Convex hull is drawn around the contour of the hand, such hand, it fits set of contour points of the hand within the hull. It
that all contour points are within the convex hull. This makes uses minimum points to form the hull to include all contour
anenvelope around the hand contour. Figure 6 shows the points inside or on the hull and maintain the property of
convex hull formed around the detected hand. convexity. This causes the formation of defects in the convex
hull with respect to the contour drawn on hand.
10
International Journal of Computer Applications (0975 – 8887)
Volume 72– No.17, June 2013
A defect is present wherever the contour of the object is away between two fingers, the system may not detect some fingers
from the convex hull drawn around the same contour. if the user’s hand is far away from the web camera.
Convexity defect gives the set of values for every defect in the
form of vector. This vector contains the start and end point of
the line of defect in the convex hull. These points indicate
3.3 Extraction of Input
After all pre-processing on the input image frame mentioned
indices of the coordinate points of the contour. These points
in hand segmentation and hand detection is done, useful
can be easily retrieved by using start and end indices of the
information is extracted from the user’s hand for input
defect formed from the contour vector. Convexity defect also
purposes. For extracting useful input, three main things that
includes index of the depth point in the contour and its depth
are mentioned in hand detection. Contour and convexity
value from the line. Figure 7 shows an example of convexity
defects in the image frame are mainly used for extraction of
defects calculated in the detected hand using the input image
inputs. For interaction with the computer system, various
of figure 1.
commands can be given
For finding convexity defects using the contour and its convex
hull we use the following function [6]:
void convexityDefects(
InputArray contour,
InputArrayconvexhull,
OutputArrayconvexityDefects);
The fixpt_depth is the parameter which we use to remove Figure 9: Finger Count of 3
convexity defects which are not large enough to be considered
as the space between two fingers. Due to this requirement on Similarly in figure 9, count given by the user is three that is
the minimum depth required for consideration as the space having two large defects in the image. So finger count is
easily determined by adding one to the count of large defects
11
International Journal of Computer Applications (0975 – 8887)
Volume 72– No.17, June 2013
in the images. This technique fails when there is no large is towards right. And if the difference between midpoint and
defect in the input image frame. This situation occurs when depth point is negative then orientation of hand is towards
there is one finger or no finger in the image. In both the cases left.
there is no large defect, so it cannot be determined whether no
count that is count 0 is given by the user or count one is given
by the user. To overcome this issue we design the commands
from count of 2 to 5. The count of 1 and 0 can also be used as
a command but they both should represent the same
command.
Similarly in figure 11, the line of hull with defect having Every time the fingertip goes outside the current acceptable
maximum depth is considered. The difference between x- area, a counter is set to 0. The new location in the current
coordinates of the midpoint and depth point is much larger frame becomes the center of the acceptable area. Now for
than the difference between y-coordinate. So orientation of each frame if the fingertip is detected in the acceptable area
the hand is either right or left. If the difference between then the counter is incremented. If the fingertip is not detected
midpoint and depth point is positive then orientation of hand in the acceptable area then a different variable anti-counter is
12
International Journal of Computer Applications (0975 – 8887)
Volume 72– No.17, June 2013
incremented. Then if anti-counter reaches the value of 2 then select the object which should be picked up and then also
counter is reset and the current location is made the center of select the destination for this object. This can be done by
the acceptable area. If the fingertip is detected in the showing the fingertip overlay over the images coming from
acceptable area then anti-counter is reset and counter is the robot's camera. When a click is registered inside a
incremented. If the counter reaches a fixed value then the detected object, the object is marked as the target object and
click is registered and the counter reset. Anti-counter variable the arm picks up the object and then again the destination is
is used to implement the relaxation of 2 consecutive frames the point where the next click is registered from the finger
not having fingertip in the acceptable area due to any reason. tracking module. The object is thus placed at the destination.
13
IJCATM : www.ijcaonline.org