title: Can Affectiva connect Kinect v1
body: <p>I'm having a project with free Emotion Recognition version of Affectiva<a href="https://developer.affectiva.com/" rel="nofollow noreferrer">https://developer.affectiva.com/</a> on Ubuntu 14.04.
  I'm trying to use Kinect v1 as the input device for Affectiva.
  I using lsusb to find kinect v1's ID is Bus 003 Device 009: ID 045e:02ae Microsoft Corp. Xbox
  NUI Camera .I try to modify const int cameraId = 045e:02ae on affdex-sdk/CameraDetector.h and build/opencv-webcam-demo.
      </p>
  
  <pre><code>#pragma once
  #include &lt;memory&gt;
  #include "FrameDetector.h"
  
  namespace affdex
  {
      // Forward Declarations
      class Camera;
  
      /// &lt;summary&gt;
      /// A detector used to acquire and process frames from a physical camera.
      /// &lt;/summary&gt;
      class CameraDetector : public FrameDetector
      {
      public:
  
          /// &lt;summary&gt;
          /// Creates a CameraDetector.
          /// This class acquires the device camera and will immediately start processing frames from the camera feed.
          /// Processing is asynchronous so some frames may be dropped.
          /// &lt;param name="cameraId"&gt;Device id for the camera. &lt;/param&gt;
          /// &lt;param name="cameraFPS"&gt;Capture framerate from the camera. Must be positive.&lt;/param&gt;
          /// &lt;param name="processFPS"&gt;Maximum framerate from processing. Must be positive.&lt;/param&gt;
          /// &lt;param name="maxNumFaces"&gt;The max number of faces to be tracked.&lt;/param&gt;
          /// &lt;param name="faceConfig"&gt;Maximum processing framerate.&lt;/param&gt;
          /// &lt;/summary&gt;
          AFFDEXSDK CameraDetector(const int cameraId = 045e:02ae, const double cameraFPS =20 ,
                                   const double processFPS = DEFAULT_PROCESSING_FRAMERATE,
                                   const unsigned int maxNumFaces = DEFAULT_MAX_NUM_FACES,
                                   const FaceDetectorMode faceConfig = affdex::FaceDetectorMode::LARGE_FACES);
  
          /// &lt;summary&gt;
          /// Finalizes an instance of the &lt;see cref="CameraDetector"/&gt; class.
          /// &lt;/summary&gt;
          AFFDEXSDK virtual ~CameraDetector() override;
  
          /// &lt;summary&gt;
          /// Initializes the CameraDetector and starts producing frames and results immediately.
          /// &lt;/summary&gt;
          AFFDEXSDK virtual void start() override;
  
          /// &lt;summary&gt;
          /// Notifies the CameraDetector to stop processing frames. Immediately stops processing.
          /// &lt;/summary&gt;
          AFFDEXSDK virtual void stop() override;
  
          /// &lt;summary&gt;
          /// Set/reset the camera framerate. Must be positive.
          /// &lt;param name="cameraFPS"&gt;Capture framerate from the camera. Must be positive.&lt;/param&gt;
          /// &lt;exception cref="AffdexException"&gt; AffdexException on an invalid FPS value &lt;/exception&gt;
          /// &lt;/summary&gt;
          AFFDEXSDK void setCameraFPS(const double cameraFPS);
  
          /// &lt;summary&gt;
          /// Set/reset the camera id. Must be positive.
          /// &lt;param name="cameraId"&gt;Device id for the camera. &lt;/param&gt;
          /// &lt;exception cref="AffdexException"&gt; AffdexException on an invalid value &lt;/exception&gt;
          /// &lt;/summary&gt;
          AFFDEXSDK void setCameraId(const int cameraId);
  
      private:
  
          /// Masking the parent FrameDetector's process command.
          using FrameDetector::process;
          void onException(AffdexException);
  
          std::shared_ptr&lt;Camera&gt; mCam;
      };
  }
  </code></pre>
  
  <p>and modify const int cameraId = 045e:02ae on sdk-samples/opencv-webcam-demo.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  #include &lt;string&gt;
  #include &lt;cstdlib&gt;
  #include &lt;memory&gt;
  #include &lt;chrono&gt;
  #include &lt;fstream&gt;
  #include &lt;boost/filesystem.hpp&gt;
  #include &lt;boost/timer/timer.hpp&gt;
  #include &lt;boost/program_options.hpp&gt;
  #include &lt;boost/algorithm/string.hpp&gt;
  
  #include "Frame.h"
  #include "Face.h"
  #include "FrameDetector.h"
  #include "AffdexException.h"
  #include "ImageListener.h"
  #include "FaceListener.h"
  
  #include "AFaceListener.hpp"
  #include "PlottingImageListener.hpp"
  #include "StatusListener.hpp"
  
  using namespace std;
  using namespace affdex;
  
  /// &lt;summary&gt;
  /// Project for demoing the Windows SDK CameraDetector class (grabbing and processing frames from the camera).
  /// &lt;/summary&gt;
  
  //PlottingImageListener emotionlist;
  
  int main(int argsc, char ** argsv)
  {
  
      namespace po = boost::program_options; // abbreviate namespace
  
      std::cerr &lt;&lt; "Hit ESCAPE key to exit app.." &lt;&lt; endl;
      shared_ptr&lt;FrameDetector&gt; frameDetector;
  
      affdex::Emotions EmoXX;
  
  
      try{
  
          const std::vector&lt;int&gt; DEFAULT_RESOLUTION{ 640, 480 };
  
          affdex::path DATA_FOLDER;
  
          std::vector&lt;int&gt; resolution;
          int process_framerate = 30;
          int camera_framerate = 15;
          int buffer_length = 2;
          int camera_id = 045e:02ae;
          unsigned int nFaces = 1;
          bool draw_display = true;
          int faceDetectorMode = (int)FaceDetectorMode::LARGE_FACES;
  
          float last_timestamp = -1.0f;
          float capture_fps = -1.0f;
  
          const int precision = 2;
          std::cerr.precision(precision);
          std::cout.precision(precision);
  
          po::options_description description("Project for demoing the Affdex SDK CameraDetector class (grabbing and processing frames from the camera).");
          description.add_options()
              ("help,h", po::bool_switch()-&gt;default_value(false), "Display this help message.")
  #ifdef _WIN32
              ("data,d", po::wvalue&lt; affdex::path &gt;(&amp;DATA_FOLDER)-&gt;default_value(affdex::path(L"data"), std::string("data")), "Path to the data folder")
  #else //  _WIN32
              ("data,d", po::value&lt; affdex::path &gt;(&amp;DATA_FOLDER)-&gt;default_value(affdex::path("data"), std::string("data")), "Path to the data folder")
  #endif // _WIN32
              ("resolution,r", po::value&lt; std::vector&lt;int&gt; &gt;(&amp;resolution)-&gt;default_value(DEFAULT_RESOLUTION, "640 480")-&gt;multitoken(), "Resolution in pixels (2-values): width height")
              ("pfps", po::value&lt; int &gt;(&amp;process_framerate)-&gt;default_value(30), "Processing framerate.")
              ("cfps", po::value&lt; int &gt;(&amp;camera_framerate)-&gt;default_value(30), "Camera capture framerate.")
              ("bufferLen", po::value&lt; int &gt;(&amp;buffer_length)-&gt;default_value(30), "process buffer size.")
              ("cid", po::value&lt; int &gt;(&amp;camera_id)-&gt;default_value(0), "Camera ID.")
              ("faceMode", po::value&lt; int &gt;(&amp;faceDetectorMode)-&gt;default_value((int)FaceDetectorMode::LARGE_FACES), "Face detector mode (large faces vs small faces).")
              ("numFaces", po::value&lt; unsigned int &gt;(&amp;nFaces)-&gt;default_value(1), "Number of faces to be tracked.")
              ("draw", po::value&lt; bool &gt;(&amp;draw_display)-&gt;default_value(true), "Draw metrics on screen.")
              ;
          po::variables_map args;
          try
          {
              po::store(po::command_line_parser(argsc, argsv).options(description).run(), args);
              if (args["help"].as&lt;bool&gt;())
              {
                  std::cout &lt;&lt; description &lt;&lt; std::endl;
                  return 0;
              }
              po::notify(args);
          }
          catch (po::error&amp; e)
          {
              std::cerr &lt;&lt; "ERROR: " &lt;&lt; e.what() &lt;&lt; std::endl &lt;&lt; std::endl;
              std::cerr &lt;&lt; "For help, use the -h option." &lt;&lt; std::endl &lt;&lt; std::endl;
              return 1;
          }
  
          if (!boost::filesystem::exists(DATA_FOLDER))
          {
              std::cerr &lt;&lt; "Folder doesn't exist: " &lt;&lt; std::string(DATA_FOLDER.begin(), DATA_FOLDER.end()) &lt;&lt; std::endl &lt;&lt; std::endl;;
              std::cerr &lt;&lt; "Try specifying the folder through the command line" &lt;&lt; std::endl;
              std::cerr &lt;&lt; description &lt;&lt; std::endl;
              return 1;
          }
          if (resolution.size() != 2)
          {
              std::cerr &lt;&lt; "Only two numbers must be specified for resolution." &lt;&lt; std::endl;
              return 1;
          }
          else if (resolution[0] &lt;= 0 || resolution[1] &lt;= 0)
          {
              std::cerr &lt;&lt; "Resolutions must be positive number." &lt;&lt; std::endl;
              return 1;
          }
  
          std::ofstream csvFileStream;
  
          std::cerr &lt;&lt; "Initializing Affdex FrameDetector" &lt;&lt; endl;
          shared_ptr&lt;FaceListener&gt; faceListenPtr(new AFaceListener());
          shared_ptr&lt;PlottingImageListener&gt; listenPtr(new PlottingImageListener(csvFileStream, draw_display));    // Instanciate the ImageListener class
          shared_ptr&lt;StatusListener&gt; videoListenPtr(new StatusListener());
          frameDetector = make_shared&lt;FrameDetector&gt;(buffer_length, process_framerate, nFaces, (affdex::FaceDetectorMode) faceDetectorMode);        // Init the FrameDetector Class
  
          //Initialize detectors
          frameDetector-&gt;setDetectAllEmotions(true);
          frameDetector-&gt;setDetectAllExpressions(true);
          frameDetector-&gt;setDetectAllEmojis(true);
          frameDetector-&gt;setDetectAllAppearances(true);
          frameDetector-&gt;setClassifierPath(DATA_FOLDER);
          frameDetector-&gt;setImageListener(listenPtr.get());
          frameDetector-&gt;setFaceListener(faceListenPtr.get());
          frameDetector-&gt;setProcessStatusListener(videoListenPtr.get());
  
          cv::VideoCapture webcam(camera_id);    //Connect to the first webcam
          webcam.set(CV_CAP_PROP_FPS, camera_framerate);    //Set webcam framerate.
          webcam.set(CV_CAP_PROP_FRAME_WIDTH, resolution[0]);
          webcam.set(CV_CAP_PROP_FRAME_HEIGHT, resolution[1]);
          std::cerr &lt;&lt; "Setting the webcam frame rate to: " &lt;&lt; camera_framerate &lt;&lt; std::endl;
          auto start_time = std::chrono::system_clock::now();
          if (!webcam.isOpened())
          {
              std::cerr &lt;&lt; "Error opening webcam!" &lt;&lt; std::endl;
              return 1;
          }
  
          std::cout &lt;&lt; "Max num of faces set to: " &lt;&lt; frameDetector-&gt;getMaxNumberFaces() &lt;&lt; std::endl;
          std::string mode;
          switch (frameDetector-&gt;getFaceDetectorMode())
          {
          case FaceDetectorMode::LARGE_FACES:
              mode = "LARGE_FACES";
              break;
          case FaceDetectorMode::SMALL_FACES:
              mode = "SMALL_FACES";
              break;
          default:
              break;
          }
          std::cout &lt;&lt; "Face detector mode set to: " &lt;&lt; mode &lt;&lt; std::endl;
  
          //Start the frame detector thread.
          frameDetector-&gt;start();
  
          do{
              cv::Mat img;
              if (!webcam.read(img))    //Capture an image from the camera
              {
                  std::cerr &lt;&lt; "Failed to read frame from webcam! " &lt;&lt; std::endl;
                  break;
              }
  
              //Calculate the Image timestamp and the capture frame rate;
              const auto milliseconds = std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(std::chrono::system_clock::now() - start_time);
              const double seconds = milliseconds.count() / 1000.f;
  
              // Create a frame
              Frame f(img.size().width, img.size().height, img.data, Frame::COLOR_FORMAT::BGR, seconds);
              capture_fps = 1.0f / (seconds - last_timestamp);
              last_timestamp = seconds;
              frameDetector-&gt;process(f);  //Pass the frame to detector
  
              // For each frame processed
              if (listenPtr-&gt;getDataSize() &gt; 0)
              {
  
                  std::pair&lt;Frame, std::map&lt;FaceId, Face&gt; &gt; dataPoint = listenPtr-&gt;getData();
                  Frame frame = dataPoint.first;
                  std::map&lt;FaceId, Face&gt; faces = dataPoint.second;
  
                  // Draw metrics to the GUI
                  if (draw_display)
                  {
                      listenPtr-&gt;draw(faces, frame);
                  }
  
                  std::cerr &lt;&lt; "timestamp: " &lt;&lt; frame.getTimestamp()
                      &lt;&lt; " cfps: " &lt;&lt; listenPtr-&gt;getCaptureFrameRate()
                      &lt;&lt; " pfps: " &lt;&lt; listenPtr-&gt;getProcessingFrameRate()
                      &lt;&lt; " faces: " &lt;&lt; faces.size() &lt;&lt;endl;
              //&lt;&lt;listenPtr-&gt;emotiontype
              //&lt;&lt; " Value = " &lt;&lt; listenPtr-&gt;emotionlist&lt;&lt;endl
              //&lt;&lt; listenPtr-&gt;*values &lt;&lt;endl;
  
              //if(EmoXX.joy == 0){
              //  cout &lt;&lt; "Emotion = JOY\n";
              //  emo.joy = 100;
              //  };
                  //Output metrics to the file
                  listenPtr-&gt;outputToFile(faces, frame.getTimestamp());
          //cout &lt;&lt; "Joy Value = " &lt;&lt; listenPtr -&gt; &lt;&lt;"\n";
              }
  
  
          }
  
  #ifdef _WIN32
          while (!GetAsyncKeyState(VK_ESCAPE) &amp;&amp; videoListenPtr-&gt;isRunning());
  #else //  _WIN32
          while (videoListenPtr-&gt;isRunning());//(cv::waitKey(20) != -1);
  #endif
          std::cerr &lt;&lt; "Stopping FrameDetector Thread" &lt;&lt; endl;
          frameDetector-&gt;stop();    //Stop frame detector thread
      }
      catch (AffdexException ex)
      {
          std::cerr &lt;&lt; "Encountered an AffdexException " &lt;&lt; ex.what();
          return 1;
      }
      catch (std::runtime_error err)
      {
          std::cerr &lt;&lt; "Encountered a runtime error " &lt;&lt; err.what();
          return 1;
      }
      catch (std::exception ex)
      {
          std::cerr &lt;&lt; "Encountered an exception " &lt;&lt; ex.what();
          return 1;
      }
      catch (...)
      {
          std::cerr &lt;&lt; "Encountered an unhandled exception ";
          return 1;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>,but still the demo program couldn't connect kinect v1 when running opencv-webcam-demo .
  Is there any way can use kinect v1 as Affectiva's input?</p>