我在Ubuntu 16.04上使用C ++的affectiva affdex。我正在使用的程序如下。作为输入,我提供30分钟的mp4视频。我已按照affectiva网页上的所有步骤进行操作(下载Ubuntu-16.04 x86_64 4.0-75和sudo apt-get install libcurl4-openssl-dev uuid-dev
)。
问题是对于某些视频,处理在大约2分钟后终止。对于其他视频,缺少大部分(例如,缺少10分钟的帧)。我没有收到任何错误,控制台上的输出是“[Affectiva]视频处理已完成。”
为什么会这样?
#define _GLIBCXX_USE_CXX11_ABI 0
#include "VideoDetector.h"
#include "FrameDetector.h"
#include <iostream>
#include <fstream>
#include <mutex>
#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_guard<std::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();
}