I found the answer. It is not necessary to search between desired pixels. Viola - Jones Algorithm already finds the features in the way like the simple algorithm above. So if you search for the objects sequentially it finds facial features without any problem. Here is an example code:
void Detection::Detect()
{
FacialFeatures* facialFeatures = new FacialFeatures();
DrawRectangle(DetectFeature(faceDetector));
DrawRectangle(DetectFeature(eyesDetector));
DrawRectangle(DetectFeature(noseDetector));
DrawRectangle(DetectFeature(mouthDetector));
DrawRectangle(DetectFeature(leftEyeDetector));
DrawRectangle(DetectFeature(righteyeDetector));
}
CvRect* Detection::DetectFeature(const char* detectorType)
{
pCascade_ = (CvHaarClassifierCascade* ) cvLoad(detectorType,0,0,0);
pRectSeq_ = cvHaarDetectObjects(pImage_, pCascade_, pStorage_, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize(20,20));
CvRect* r = (CvRect*) cvGetSeqElem(pRectSeq_,0);
return r;
}
void Detection::DrawRectangle(CvRect* r)
{
cvNamedWindow("Detected", CV_WINDOW_AUTOSIZE);
CvPoint pt1 = { r->x, r->y };
CvPoint pt2 = { r->x + r->width, r->y + r->height };
cvRectangle(pImage_, pt1, pt2, CV_RGB(0,255,0), 3, 4, 0);
cvShowImage("Detected", pImage_);
cvWaitKey(0);
}