Search code examples
c++affdex-sdk

Cannot detect Faces using Offline Affectiva SDK


I'm new to Affectiva Emotion Recognition SDK. I have been following example from video from this link But when I feed some pictures example this image the face could not be detected. My code looks:-

Listener

    class Listener : public affdex::ImageListener{
        void onImageResults(std::map<affdex::FaceId,affdex::Face> faces,affdex::Frame image){
            std::string pronoun="they";
            std::string emotion="neutral";
            for (auto pair : faces){
                affdex::FaceId faceId=pair.first;
                affdex::Face face=pair.second;
                if(face.appearance.gender==affdex::Gender::Male){
                    pronoun="Male";
                }else if(face.appearance.gender==affdex::Gender::Female){
                    pronoun="Female";
                }

                if(face.emotions.joy>25){
                    emotion="Happy :)";
                }else if(face.emotions.sadness>25){
                    emotion="Sad :(";
                }

                cout<<faceId<<" : "<<pronoun <<" looks "<< emotion <<endl;
            }

        }
        void onImageCapture(affdex::Frame image){
            cout<<"IMage captured"<<endl;
        }
    };

Main code

    Mat img;
    img=imread(argv[1],CV_LOAD_IMAGE_COLOR);
    affdex::Frame frame(img.size().width, img.size().height, img.data, affdex::Frame::COLOR_FORMAT::BGR);
    affdex::PhotoDetector detector(3);
    detector.setClassifierPath("/xxx/xxx/affdex-sdk/data");
    affdex::ImageListener * listener(new Listener());
    detector.setImageListener(listener);
    detector.setDetectAllEmotions(true);
    detector.setDetectAllExpressions(true);
    detector.start();
    detector.process(frame);
    detector.stop();

Where do am I making mistake?Or is the sdk cannot detect faces from some images? can any body help me?

Edit I Used the following images

enter image description hereenter image description here


Solution

  • Sometimes the SDK cannot detect faces in an image. There is no detector that can detect all faces all the time. Did you check with different images?

    Edit:

    Those two images are 250x250 and 260x194 and really low quality. I recommend you to test the app with higher resolution images. As Affectiva states in their webpage that the minimum recommended resolution is 320x240 and faces should be at least 30x30. https://developer.affectiva.com/obtaining-optimal-results/