从照片中检测情绪的 affectiva affdex 问题

affectiva affdex issue with detecting emotions from a photo

我正在尝试使用 affdex SDK 分析图像(例如 Abdelrahman Mahmoud link for tutorial 完成的第二个示例)我正在使用 raspberry pi 3b 运行ning Raspbian 使用 gcc 6.3.0 拉伸

代码:

#include <iostream>
#include <string>
#include "Magick++.h"
#include "PhotoDetector.h"

class Listener : public affdex::ImageListener{
 void onImageResults(std::map<affdex::FaceId,affdex::Face> faces,affdex::Frame image){
  std::cout << "Found Faces: "<< faces.size() << std::endl;

  for (auto pair : faces){
   std::string pronoun="they";
   std::string emotion="neutral";
   affdex::Face face=pair.second;

   if(face.appearance.gender == affdex::Gender::Male){
    pronoun="He";
   }
   else if(face.appearance.gender == affdex::Gender::Female){
    pronoun="She";
   }
   if(face.emotions.joy>25){
    emotion="Happy :)";
   }
   else if(face.emotions.sadness>25){
    emotion="Sad :(";
   }
   
   std::cout << face.id << " : " << pronoun << " looks " << emotion << std::endl;
  }
 };
 
 void onImageCapture(affdex::Frame image){};
};

int main(int argc, char ** argsv)
{
 
 //Initialize the imagemagick library
 Magick::InitializeMagick(*argsv);
 
 // Read Image into Memory
 Magick::Image img(argsv[1]);
 char * pixels = new char [img.columns() * img.rows() * 1];
 img.write(0,0,img.columns(), img.rows(), "RGB", MagickCore::StorageType::CharPixel, pixels);
 
 affdex::Frame frame(img.columns(), img.rows(), pixels, affdex::Frame::COLOR_FORMAT::BGR);
 
 affdex::PhotoDetector detector(1);
 affdex::ImageListener * listen = new Listener();
 
 detector.setImageListener(listen);
 
 detector.setClassifierPath("/home/pi/affdex-sdk/data");
 detector.setDetectAllEmotions(true);
 detector.setDetectAllAppearances(true);
 detector.setDetectAllExpressions(true);
 
 detector.start();
 detector.process(frame);
 detector.stop();

 delete listen;
 delete [] pixels;
 return 0;
}

当我 运行 脚本

./test-app image.jpg

我遇到了这个错误(如果我使用 .bmp 图像也是如此):

segmentation fault

我尝试使用其他图像,但出现此错误:

terminate called after throwing an instance of ‘Magick::ErrorResourceLimit’ ** what(): test-app: memory allocation failed `download.png’ @ error/png.c/ReadOnePNGImage/2341 Aborted

任何指点,谢谢

pixels 缓冲区不够大,无法容纳所有数据。

size_t pixels_size = img.columns() // Width
                   * img.rows()    // Height
                   * sizeof(char)  // Size of storage
                   * 3;            // Number of parts per pixel ("RGB")
char * pixels = new char [pixels_size];
img.write(0,0,img.columns(), img.rows(), "RGB", MagickCore::StorageType::CharPixel, pixels);