0

i’m trying to analyse an image with affdex SDK (like the seconde example done by Abdelrahman Mahmoud link for tutorial ) i’m using raspberry pi 3b running Raspbian stretch with gcc 6.3.0

the code :

#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;
}

when i run the script with

./test-app image.jpg

i got this error (the same if i use .bmp image ):

segmentation fault

i tried with an other image and i got this error :

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

Any pointers, thanks

6
  • from the symptoms described, it sounds like the error is coming from ImageMagick, not the Affex SDK. Can you debug into the ImageMagick code and determine why it's throwing that exception? Jan 24, 2018 at 22:56
  • yes , i found this error : what(): basic_string::_M_construct null not valid Jan 25, 2018 at 8:10
  • 1
    that's just the exception message. Why is it throwing the exception? ImageMagick is open source, you should be able to debug into it and see why it's throwing. Jan 27, 2018 at 15:38
  • also, you may get more assistance if you change the title and tag of your question to reference ImageMagick, as the problem you're encountering doesn't seem to have anything to do with the Affectiva SDK. Jan 27, 2018 at 15:44
  • thank you for your response sir , sorry i'm a beginner i don't know how to debug into the ImageMagick code can you help me Jan 27, 2018 at 21:37

1 Answer 1

0

The pixels buffer isn't large enough to accept all the data.

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);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.