Emotion SDK with Photo Recognition Errors

cpp

#1

Hello Everyone,

I have been attempting to use the Emotion SDK with Ubuntu 16.04. I have been following the instructions located at https://knowledge.affectiva.com/docs/getting-started-with-the-affectiva-sdk-for-linux. I’ve also been recreating the code that Abdelrahman Mahmoud provided in his Video “Linux - Emotion AI Developer Day 2016” on the same page.

I’ve had numerous problems getting the compile to work and also using the test-app generated by the compile code provided so generously by Abdelrahman Mahmoud.

The web page indicates we should do a couple of installs and include. According to the web page Ubuntu 16.04 with GCC v5.4.x is supported. I am using Ubuntu 16.04.3 LTS and gcc version 5.4.0.

I generally try to make these posts small. However, with the number of problems I have experienced I don’t know how to give you the information to help me without giving you a bunch of info. So bear with my long explanation below. What follows are the steps I took on a clean install of Ubuntu 16.04 on an Amazon server.

sudo apt-get update
sudo apt-get install gcc g++ libcurl4-openssl-dev uuid-dev make
sudo apt-get install libmagick++-dev ibgraphicsmagick++1-dev libmagickcore-dev libmagickwand-dev

cd ~ # cd /home/dreedy
mkdir installs
cd installs

mkdir $HOME/affdex-sdk

wget https://download.affectiva.com/linux/gcc-5.4/affdex-cpp-sdk-4.0-75-ubuntu-xenial-xerus-x86_64bit.tar.gz
tar -xzvf affdex-cpp-sdk-4.0-75-ubuntu-xenial-xerus-x86_64bit.tar.gz -C $HOME/affdex-sdk

Add compile command provided by Abdelrahman Mahmoud in his “Linux - Emotion AI Developer Day 2016” video.
vim compile

export LD_LIBRARY_PATH=$HOME/affdex-sdk/lib
g++ main.cpp -laffdex-native -std=c++11 -I$HOME/affdex-sdk/include -L$HOME/affdex-sdk/lib `Magick++-config --cppflags --cxxflags --ldflags --libs` -o test-app

chmod 775 compile

Add code provided by Abdelrahman Mahmoud in his “Linux - Emotion AI Developer Day 2016” video.
vim main.cpp

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

Error in Compile:

./compile
./compile: line 2: Magick++-config: command not found
main.cpp:3:22: fatal error: Magick++.h: No such file or directory
compilation terminated.

Solution:
Add location of ImageMagick-6 to g++ command:

vim compile

g++ main.cpp -laffdex-native -std=c++11 -I/usr/include/ImageMagick-6 -I$HOME/affdex-sdk/include -L$HOME/affdex-sdk/libMagick+±config --cppflags --cxxflags --ldflags --libs-o test-app

Error in Compile:

./compile
./compile: line 2: Magick++-config: command not found
In file included from /usr/include/ImageMagick-6/Magick++/Include.h:13:0,
                 from /usr/include/ImageMagick-6/Magick++.h:9,
                 from main.cpp:3:
/usr/include/ImageMagick-6/magick/magick-config.h:21:38: fatal error: magick/magick-baseconfig.h: No such file or directory
compilation terminated.

Solution:
Locate magick-baseconfig.h and add it to the compile.

It is located in:
/usr/include/x86_64-linux-gnu/ImageMagick-6/magick/magick-baseconfig.h

I tried including the path in another -I/usr/include/x86_64-linux-gnu/ImageMagick-6/magick. That didn’t work.
I tried adding it to the export LD_LIBRARY_PATH=$HOME/affdex-sdk/lib:/usr/include/x86_64-linux-gnu/ImageMagick-6/magick. That didn’t work.

I finally resulted to copying or symlinking the magick-baseconfig.h file:

sudo ln -s /usr/include/x86_64-linux-gnu/ImageMagick-6/magick/magick-baseconfig.h /usr/include/ImageMagick-6/magick/magick-baseconfig.h

Warning Errors in Compile:

/usr/include/ImageMagick-6/magick/magick-config.h:29:3: warning: #warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" [-Wcpp]
     # warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default"

/usr/include/ImageMagick-6/magick/magick-config.h:52:3: warning: #warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default" [-Wcpp]
 # warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default"

Solution:
Add “sensible default” to g++ command. I’m not positive the correct settings, so I guessed based on some google searches:
-DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16

vim compile

g++ main.cpp -laffdex-native -std=c++11 -I/usr/include/ImageMagick-6 -I$HOME/affdex-sdk/include -L$HOME/affdex-sdk/libMagick+±config --cppflags --cxxflags --ldflags --libs-DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -o test-app

Error in Compile:

./compile
./compile: line 2: Magick++-config: command not found

Solution:
Install library with Magick++-config.
sudo apt-get install graphicsmagick-libmagick-dev-compat

Error in Compile:

/usr/bin/ld: cannot find -lwebp
collect2: error: ld returned 1 exit status

Solution:
sudo apt-get install libwebp-dev

Error in Compile:

/usr/bin/ld: warning: libva.so.1, needed by /home/dreedy/affdex-sdk/lib/libavcodec.so.55, not found (try using -rpath or -rpath-link)

Solution:
sudo apt-get install -y ffmpeg

Error in Compile:

/tmp/cc3J5hDs.o: In function `main':
/home/dreedy/test/main.cpp:43: undefined reference to `Magick::Image::write(long, long, unsigned long, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, MagickCore::StorageType, void*)'
collect2: error: ld returned 1 exit status

Solution:
I have no clue.

I gave up and uninstalled ImageMagick with apt-get remove and installed ImageMagick from source.

Install ImageMagick From Source:

export CPPFLAGS=-I/usr/local/include
export LDFLAGS=-L/usr/local/lib
tar xvzf ImageMagick.tar.gz
cd ImageMagick-7.0.7-21
./configure  --prefix=/usr/local --with-gslib=yes CFLAGS=-O2 CXXFLAGS=-O2 --enable-hdri --enable-shared
make
sudo make install
sudo ldconfig /usr/local/lib

I was then able to run compile, but the compiled test-app now got errors.

Error in test-app:

./test-app sad.jpg
terminate called after throwing an instance of 'Magick::ErrorMissingDelegate'
  what():  test-app: no decode delegate for this image format `JPEG' @ error/constitute.c/ReadImage/509

Since it seemed to have an issue with the .jpg file, I created a .bmp file and got a new error.

Error in test-app:

./test-app sad.bmp
segment fault core dump

Solution:
I have no clue.

Error in test-app:

./test-app sad.jpg
terminate called after throwing an instance of 'Magick::ErrorCorruptImage'
  what():  test-app: Wrong JPEG library version: library is 62, caller expects 80 `sad.jpg' @ error/jpeg.c/JPEGErrorHandler/332

Solution:
I’m not sure. Google indicated that it might be that I have libjpeg62 installed on the machine and it is trying to use it. However, I do not have that version. I only have version libjpeg8. Which as I understand it is 80.

I tried installing libjpeg9 from source and all that did was change the “caller expects 80” to “caller expects 90”. So for some reason, ImageMagick is trying to use jpeg v.62.

I’m at a loss on what is wrong. I could sure use some help. I’m not positive if some of my solutions are wrong and I could really use some help.

Thank you,

Daryl


#2

Hi Daryl,
Sorry for the delay, We’ve had some issues with the ImageMagic library. We’re escalating this issue to and will hopefully have a solution for you soon.


#3

@matt.strafuss thank you for your response. I appreciate you looking into the issue.


#4

Hi Daryl,
Just circling back here, The video walk through may have skipped a step or2 in launching the example application. we should have some updates for you by tomorrow morning at the latest.


#5

Hey @daryl_reedy, just a quick update on the status of this issue. I am working on getting a resolution. In the meantime can you try pre-loading JPEG v80 since that is what the image-magick v7.0.7-21 is expecting. You can do something like

export LD_PRELOAD=/path/to/libjpeg-80.so

I am suspecting this to be an issue with image-magick on Ubuntu 16.04 with gcc-5. Feel free to check our sample app cpp-sdk-samples which can be used to process images too.