Add project and src file
This commit is contained in:
commit
7dc4d6531f
4 changed files with 287 additions and 0 deletions
22
affdex-win-samples.sln
Normal file
22
affdex-win-samples.sln
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "opencv-webcam-demo", "opencv-webcam-demo\opencv-webcam-demo.vcxproj", "{8DCDC209-C25D-4C61-B2AC-2FBA1775DD6B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{8DCDC209-C25D-4C61-B2AC-2FBA1775DD6B}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{8DCDC209-C25D-4C61-B2AC-2FBA1775DD6B}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{8DCDC209-C25D-4C61-B2AC-2FBA1775DD6B}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{8DCDC209-C25D-4C61-B2AC-2FBA1775DD6B}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
155
opencv-webcam-demo/opencv-webcam-demo.cpp
Normal file
155
opencv-webcam-demo/opencv-webcam-demo.cpp
Normal file
|
@ -0,0 +1,155 @@
|
|||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <opencv\highgui.h>
|
||||
|
||||
#include "Frame.h"
|
||||
#include "Face.h"
|
||||
#include "ImageListener.h"
|
||||
#include "FrameDetector.h"
|
||||
#include "AffdexException.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace AFFDEX;
|
||||
|
||||
float last_timestamp = -1.0f;
|
||||
float capture_fps = -1.0f;
|
||||
float process_last_timestamp = -1.0f;
|
||||
float process_fps = -1.0f;
|
||||
|
||||
|
||||
class PlottingImageListener : public ImageListener
|
||||
{
|
||||
public:
|
||||
void onImageResults(vector<Face> faces, Frame image) override {
|
||||
|
||||
shared_ptr<byte> imgdata = image.getBGRByteArray();
|
||||
cv::Mat img = cv::Mat(image.getHeight(), image.getWidth(), CV_8UC3, imgdata.get());
|
||||
for (int i = 0; i < faces.size(); i++)
|
||||
{
|
||||
Face f = faces[i];
|
||||
float smile_score = f.getSmileScore();
|
||||
int n = f.getFeaturePointCount();
|
||||
VecFeaturePoint points = f.getFeaturePoints();
|
||||
for (auto& point : points ) //Draw face feature points.
|
||||
{
|
||||
cv::circle(img, cv::Point(point.x, point.y), 1.0f, cv::Scalar(0, 0, 255));
|
||||
}
|
||||
|
||||
//Output the results of the different classifiers.
|
||||
cv::putText(img, "Smile: "+ std::to_string(f.getSmileScore()), cv::Point(30, 30), cv::FONT_HERSHEY_COMPLEX, 0.5f, cv::Scalar(0, 0, 255));
|
||||
cv::putText(img, "BrowFurrow: " + std::to_string(f.getBrowFurrowScore()), cv::Point(30, 50), cv::FONT_HERSHEY_COMPLEX, 0.5f, cv::Scalar(0, 0, 255));
|
||||
cv::putText(img, "BrowRaise: " + std::to_string(f.getBrowRaiseScore()), cv::Point(30, 70), cv::FONT_HERSHEY_COMPLEX, 0.5f, cv::Scalar(0, 0, 255));
|
||||
cv::putText(img, "LipCornerDepressor: " + std::to_string(f.getLipCornerDepressorScore()), cv::Point(30, 90), cv::FONT_HERSHEY_COMPLEX, 0.5f, cv::Scalar(0, 0, 255));
|
||||
cv::putText(img, "Engagement: " + std::to_string(f.getEngagementScore()), cv::Point(30, 110), cv::FONT_HERSHEY_COMPLEX, 0.5f, cv::Scalar(0, 0, 255));
|
||||
cv::putText(img, "Valence: " + std::to_string(f.getValenceScore()), cv::Point(30, 130), cv::FONT_HERSHEY_COMPLEX, 0.5f, cv::Scalar(0, 0, 255));
|
||||
|
||||
|
||||
//Calculate the processing framerate, output both the processing + capture framerate
|
||||
if (process_last_timestamp >= 0.0f)
|
||||
{
|
||||
process_fps = 1.0f / (image.getTimestamp() - process_last_timestamp);
|
||||
cv::putText(img, "capture fps: " + std::to_string(capture_fps), cv::Point(img.cols - 200, 30), cv::FONT_HERSHEY_COMPLEX, 0.5f, cv::Scalar(0, 0, 255));
|
||||
cv::putText(img, "process fps: " + std::to_string(process_fps), cv::Point(img.cols - 200, 50), cv::FONT_HERSHEY_COMPLEX, 0.5f, cv::Scalar(0, 0, 255));
|
||||
}
|
||||
process_last_timestamp = image.getTimestamp();
|
||||
}
|
||||
cv::imshow("analyze-image", img);
|
||||
|
||||
cv::waitKey(30);
|
||||
};
|
||||
|
||||
void onImageCapture(Frame image) override
|
||||
{};
|
||||
};
|
||||
|
||||
int main(int argsc, char ** argsv)
|
||||
{
|
||||
|
||||
try{
|
||||
// Parse and check the data folder (with assets)
|
||||
std::wstring DATA_FOLDER = L"data";
|
||||
if (argsc > 1)
|
||||
{
|
||||
std::string user_folder(argsv[1]);
|
||||
DATA_FOLDER.assign(user_folder.begin(), user_folder.end());
|
||||
}
|
||||
|
||||
int framerate = 30;
|
||||
int process_frame_rate = 30;
|
||||
int buffer_length = 2;
|
||||
if (argsc > 2)
|
||||
{
|
||||
framerate = stoi(argsv[2]);
|
||||
}
|
||||
|
||||
if (argsc > 3)
|
||||
{
|
||||
process_frame_rate = stoi(argsv[3]);
|
||||
}
|
||||
|
||||
FrameDetector frameDetector(buffer_length, process_frame_rate); // Init the FrameDetector Class
|
||||
shared_ptr<ImageListener> listenPtr(new PlottingImageListener()); // Instanciate the ImageListener class
|
||||
|
||||
cv::VideoCapture webcam(0); //Connect to the first webcam
|
||||
webcam.set(CV_CAP_PROP_FPS, framerate); //Set webcam framerate.
|
||||
std::cerr << "Setting the webcam frame rate to: " << framerate << std::endl;
|
||||
auto start_time = std::chrono::system_clock::now();
|
||||
if (!webcam.isOpened())
|
||||
{
|
||||
std::cerr << "Error opening webcam!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Initialize detectors
|
||||
frameDetector.setDetectSmile(true);
|
||||
frameDetector.setDetectBrowFurrow(true);
|
||||
frameDetector.setDetectBrowRaise(true);
|
||||
frameDetector.setDetectLipCornerDepressor(true);
|
||||
frameDetector.setDetectEngagement(true);
|
||||
frameDetector.setDetectValence(true);
|
||||
frameDetector.setClassifierPath(DATA_FOLDER);
|
||||
frameDetector.setImageListener(listenPtr.get());
|
||||
//Start the frame detector thread.
|
||||
frameDetector.start();
|
||||
|
||||
do{
|
||||
cv::Mat img;
|
||||
if (!webcam.read(img)) //Capture an image from the camera
|
||||
{
|
||||
std::cerr << "Failed to read frame from webcam! " << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
//Calculate the Image timestamp and the capture frame rate;
|
||||
const auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start_time);
|
||||
const float 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;
|
||||
std::cerr << "Capture framerate = " << capture_fps << std::endl;
|
||||
frameDetector.process(f); //Pass the frame to detector
|
||||
} while (!GetAsyncKeyState(VK_ESCAPE));
|
||||
|
||||
frameDetector.stop(); //Stop frame detector thread
|
||||
}
|
||||
catch (AffdexException ex)
|
||||
{
|
||||
std::cerr << "Encountered an AffdexException " << ex.what();
|
||||
return 1;
|
||||
}
|
||||
catch (std::exception ex)
|
||||
{
|
||||
std::cerr << "Encountered an exception " << ex.what();
|
||||
return 1;
|
||||
}
|
||||
catch (std::runtime_error err)
|
||||
{
|
||||
std::cerr << "Encountered a runtime error " << err.what();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
88
opencv-webcam-demo/opencv-webcam-demo.vcxproj
Normal file
88
opencv-webcam-demo/opencv-webcam-demo.vcxproj
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{8DCDC209-C25D-4C61-B2AC-2FBA1775DD6B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>opencvwebcamdemo</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\affdex-sdk\include;..\opencv\build\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>..\affdex-sdk\lib\affdex-sdk.lib;..\opencv\build\x86\vc12\lib\opencv_highgui249d.lib;..\opencv\build\x86\vc12\lib\opencv_core249d.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="opencv-webcam-demo.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
22
opencv-webcam-demo/opencv-webcam-demo.vcxproj.filters
Normal file
22
opencv-webcam-demo/opencv-webcam-demo.vcxproj.filters
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="opencv-webcam-demo.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in a new issue