bool extractFeatures(TTrainingFileList& fileList,
                     vector<TrainingExample*>& trainingSet,
                     const CommandOptions& opts) {
    Timer t("extracting features from images",opts.getVerboseFlag());
    HaarFeatures haar(opts.getVerboseFlag());
    EdgeDetectionFeatures sobel;
    Hough hough;
    IplImage *image, *smallImage;
    smallImage = cvCreateImage(cvSize(64, 64), IPL_DEPTH_8U, 1);
    vector<string> labels;
    getAllLabelStrings(labels);
    for (int i = 0; i < (int)fileList.files.size(); i++) {
        // show progress
        if (i % 1000 == 0) {
            showProgress(i, fileList.files.size());
        }
        if (find(labels.begin(),labels.end(),fileList.files[i].label)!=labels.end()) {
            // load the image
            image = cvLoadImage(fileList.files[i].filename.c_str(), 0);
            if (image == NULL) {
                cerr << "ERROR: could not load image "
                     << fileList.files[i].filename.c_str() << endl;
                continue;
            }

            // resize to 64 x 64
            cvResize(image, smallImage);
            assert(smallImage->nChannels==1); // assert its grayscale
            // CS221 TO DO: extract features from image here
            vector<double> values;
            coreExtractFeatures(smallImage, values, opts);

            trainingSet.push_back(new ImagesExample(values,
                                                    getLabel(fileList.files[i].label)));
            // free memory
            cvReleaseImage(&image);
        }
    }
    // free memory
    cvReleaseImage(&smallImage);
    return fileList.files.size()==trainingSet.size();
}
void coreExtractFeatures(IplImage* image,
                         vector<double>& values,
                         const CommandOptions& opts) {
    HaarFeatures haar(opts.getVerboseFlag());
    haar.getFeatureValues(values,image);
    if(opts.getBoolOption("circle_feature")) {
        Hough hough;
        hough.getCircles(values,image);
    }
    if(opts.getBoolOption("edge_feature")) {
        Hough hough;
        hough.getEdges(values,image);
    }
    if(opts.getBoolOption("corner_feature")) {
        Hough hough;
        hough.getCorners(values,image);
    }
    if(opts.getBoolOption("sobel_feature")) {
        EdgeDetectionFeatures sobel;
        sobel.getFeatureValues(values,image);
    }
}