Exemple #1
1
/*!
	This is a basic version for returning the score of a feature on a certain position. This basic version will be called a lot, only if a specialised version of a channel (for example size, ...) will be used this function will be overloaded

	\param F The feature to evaluate
	\param Image The feature image (possible multi-channel). The structure of this image is dependend on the channel, so this allows to use specialised versions of images (such as 1 pixel large containing the layer-number)
	\param offsetX the X-position in the image
	\param offsetY the Y-position in the image
	\param shrinking The shrinking used (not useable yet)
 	\param offset The channel inside the multi-channel image
	\param method The method is default CHNFTRS, this is the only option currently available, but could later be extended with convolution


        \author F. De Smedt
        \date 2014

*/
float ChannelOld::giveScore(const Feature& F, const cv::Mat& Image, int offsetX, int offsetY, int shrinking, int offset, int method)
{
    /*
    Simple check if the offset is inside the available channels
    */
    if (offset >= this->getChannelAmount()) {
        std::cout << "Offset lies outside of number in internal channels" << std::endl;
        exit(1);
    }

    /*
    	Check if the featureis inside the feature image. A fail is most probably due to a mismatch in model size and evaluation positions

    */
    int FeaturePositionX = F.getX() + F.getWidth() + offsetX;
    int FeaturePositionY = F.getY() + F.getHeight() + offsetY;

    if (FeaturePositionX >= Image.cols || FeaturePositionY >= Image.rows) {
        std::cout << "The features lies outside the image!!" << std::endl;
        std::cout << "ImageSize: " << Image.cols << " x " << Image.rows << " Feature: X" << F.getX() << " width:" << F.getWidth() << "  offsetX:" << offsetX << "   Y:" << F.getY() << " height" << F.getHeight() << "  offsetY" << offsetY << std::endl;
        exit(4);
    }

    //Get the score of the feature out ofthe integral image
    if (method == CHNFTRS) {
        float a = Image.at<float>(F.getY() + offsetY, F.getX() + offsetX);
        float b = Image.at<float>(F.getY() + offsetY, F.getX() + F.getWidth() + offsetX);
        float d = Image.at<float>(F.getY() + F.getHeight() + offsetY, F.getX() + offsetX);
        float c = Image.at<float>(F.getY() + F.getHeight() + offsetY, F.getX() + F.getWidth() + offsetX);

        return (float)(a - b + c - d);
    }
    else {
        std::cout << "Evaluation method not supported yet" << std::endl;
        exit(3);
    }

    return 0;
}
bool StudentLocalization::stepFindChinContours(const IntensityImage &image, FeatureMap &features) const {

	//Get the position of the mouth
	Feature Mouth = features.getFeature(Feature::FEATURE_MOUTH_TOP);
	Point2D<double> MouthPosition;
	
	//Initialise the chin feature
	std::vector<Point2D<double>> ChinPositions;
	Feature Chin = Feature(Feature::FEATURE_CHIN);
	Feature ChinContour = Feature(Feature::FEATURE_CHIN_CONTOUR);
	int y = 0;
	int m = 0;
	
	//Draw a half circle starting from the center of the mouth
	for (int j = HALF_CIRCLE; j > 0; j -= DEGREE_STEP){
		
		//reset the position of the mouth
		MouthPosition.set(Mouth.getX(), Mouth.getY());
		MouthPosition.set(drawLine(j, START_POSITION, MouthPosition));
	
		m = m + 1;

		
		for (int i = 0; i < MEASURE_RANGE; i++){

			MouthPosition.set(drawLine(j, MEASURE_STEP, MouthPosition));
			Intensity pixel = image.getPixel(MouthPosition.getX(), MouthPosition.getY());

			// If the intensity of the current pixel is lower than 2 (which means it is black)
			if (pixel < 2){ 
				
				// If the current angle is within the bounds of the half circle
				if (j < RIGHT_HALF && j > LEFT_HALF){
					ChinContour.addPoint(drawLine(j, 2, MouthPosition));
				}
				else{
					//Draw a point on the mouth position, to indicate the detection failed.
					ChinContour.addPoint(MouthPosition);
				}
				break;
			}
		}	
	}	
	features.putFeature(ChinContour);
	return true;
}