Affectiva affdex does not process videos correctly

cpp

#1

Hello

I’m using affectiva affdex with C++ on Ubuntu 16.04. The programm I’m using is below. As input I’m providing a 30 min mp4 video. I have followed all steps on the affectiva webpage (downloading Ubuntu-16.04 x86_64 4.0-75 and sudo apt-get install libcurl4-openssl-dev uuid-dev).

The problem is that for some videos the processing terminates after around 2 minutes. For other videos there are large parts missing (i.e. for example 10 minutes of frames missing). I’m not getting any error and the output on the console is “[Affectiva] Video processing finised.”

Why does this happen?

#define _GLIBCXX_USE_CXX11_ABI 0
#include “VideoDetector.h”
#include “FrameDetector.h”

#include
#include
#include
#include <condition_variable>

std::mutex m;
std::condition_variable conditional_variable;
bool processed = false;

class Listener : public affdex::ImageListener {
public:
Listener(std::ofstream * fout) {
this->fout = fout;
}
virtual void onImageCapture(affdex::Frame image){
}
virtual void onImageResults(std::map<affdex::FaceId, affdex::Face> faces, affdex::Frame image){
for(auto& kv : faces){
(*this->fout) << image.getTimestamp() << “,”;
(*this->fout) << kv.first << “,”;
(*this->fout) << kv.second.emotions.joy << “,”;
(*this->fout) << kv.second.emotions.fear << “,”;
(*this->fout) << kv.second.emotions.disgust << “,”;
(*this->fout) << kv.second.emotions.sadness << “,”;
(*this->fout) << kv.second.emotions.anger << “,”;
(*this->fout) << kv.second.emotions.surprise << “,”;
(*this->fout) << kv.second.emotions.contempt << “,”;
(*this->fout) << kv.second.emotions.valence << “,”;
(*this->fout) << kv.second.emotions.engagement << “,”;
(*this->fout) << kv.second.measurements.orientation.pitch << “,”;
(*this->fout) << kv.second.measurements.orientation.yaw << “,”;
(*this->fout) << kv.second.measurements.orientation.roll << std::endl;
}
}
private:
std::ofstream * fout;
};

class ProcessListener : public affdex::ProcessStatusListener{
public:
virtual void onProcessingException (affdex::AffdexException ex){
std::cerr << "[Error] " << ex.getExceptionMessage();
}
virtual void onProcessingFinished (){
{
std::lock_guardstd::mutex lk(m);
processed = true;
std::cout << “[Affectiva] Video processing finised.” << std::endl;
}
conditional_variable.notify_one();
}
};

int main(int argc, char ** argsv)
{
affdex::VideoDetector detector(60);
std::string classifierPath="/home/test/affdex-sdk/data";
detector.setClassifierPath(classifierPath);
detector.setDetectAllEmotions(true);

	std::ofstream fout(argsv[2]);
	fout << "timestamp" << ",";
	fout << "faceId" << ",";
	fout << "joy" << ",";
	fout << "fear" << ",";
	fout << "disgust" << ",";
	fout << "sadness" << ",";
	fout << "anger" << ",";
	fout << "surprise" << ",";
	fout << "contempt" << ",";
	fout << "valence" << ",";
	fout << "engagement"  << ",";
	fout << "pitch" << ",";
	fout << "yaw" << ",";
	fout << "roll" << std::endl;
	
	Listener l(&fout);
	ProcessListener pl;
	detector.setImageListener(&l);
	detector.setProcessStatusListener(&pl);
	
	detector.start();
	detector.process(argsv[1]);
	{
		std::unique_lock<std::mutex> lk(m);
		conditional_variable.wait(lk, []{return processed;});
	}
	fout.flush();
	fout.close();

}