Skip to content

Commit

Permalink
simplify emulator tests (#597)
Browse files Browse the repository at this point in the history
* * refactor test image vector (various resolutions) to use map<int,image> for sparse sampling of image width
* use GAUZE_ANDROID_USE_EMULATOR preprocessor switch to reduce testing on emulator

* clang-format

* clang-format src/app
  • Loading branch information
headupinclouds authored Oct 21, 2017
1 parent 1ddf488 commit b6360c3
Show file tree
Hide file tree
Showing 72 changed files with 591 additions and 647 deletions.
4 changes: 2 additions & 2 deletions src/app/acf/mat2cpb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int gauze_main(int argc, char** argv)
else
{
std::ofstream ofs(sOutput);
if(ofs)
if (ofs)
{
remove(sOutput.c_str());
}
Expand All @@ -78,7 +78,7 @@ int gauze_main(int argc, char** argv)
logger->error("Unable to open {} for writing", sOutput);
}
}

drishti::acf::Detector acf(sInput);

save_cpb(sOutput, acf);
Expand Down
2 changes: 1 addition & 1 deletion src/app/cpr/train_cpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ int gauze_main(int argc, char** argv)
cprPrm.L = L;
cprPrm.T = T;
cprPrm.model = model;

// Note: feature parameters can be overriden
cprPrm.ftrPrm->type = 2;
cprPrm.ftrPrm->F = F;
Expand Down
4 changes: 2 additions & 2 deletions src/app/dlib/facexml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ int gauze_main(int argc, char** argv)
}

logger->info("Have {} faces", faces.size());

int code = drishtiFaceToDlib(faces, sOutput);
if(code != 0)
if (code != 0)
{
logger->error("Failed to create file {} for writing");
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/face/face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int gauze_main(int argc, char** argv)
auto factory = std::make_shared<drishti::face::FaceDetectorFactory>();

float minZ = 0.1f, maxZ = 1.f;

cxxopts::Options options("drishti-acf", "Command line interface for ACF object detection (see Piotr's toolbox)");

// clang-format off
Expand Down Expand Up @@ -236,7 +236,7 @@ int gauze_main(int argc, char** argv)
return 1;
}

if(!sFactory.empty())
if (!sFactory.empty())
{
factory = std::make_shared<drishti::face::FaceDetectorFactoryJson>(sFactory);
}
Expand Down
30 changes: 15 additions & 15 deletions src/app/hci/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int gauze_main(int argc, char** argv)
auto factory = std::make_shared<drishti::face::FaceDetectorFactory>();

cxxopts::Options options("drishti-hci", "Command line interface for video sequence FaceFinder processing.");

float minZ = 0.1f, maxZ = 2.f;

// clang-format off
Expand Down Expand Up @@ -148,11 +148,11 @@ int gauze_main(int argc, char** argv)
return 1;
}

if(!sFactory.empty())
if (!sFactory.empty())
{
factory = std::make_shared<drishti::face::FaceDetectorFactoryJson>(sFactory);
}

// Check for valid models
std::vector<std::pair<std::string, std::string>> config{
{ factory->sFaceDetector, "face-detector" },
Expand All @@ -173,11 +173,11 @@ int gauze_main(int argc, char** argv)
// Events will not be handled correctly. This is probably because _TSGetMainThread
// was called for the first time off the main thread.

// NOTE: We can create the OpenGL context prior to AVFoundation use as a workaround
// NOTE: We can create the OpenGL context prior to AVFoundation use as a workaround
auto opengl = aglet::GLContext::create(aglet::GLContext::kAuto, doWindow ? "hci" : "", 640, 480);
#if defined(_WIN32) || defined(_WIN64)
CV_Assert(!glewInit());
#endif
CV_Assert(!glewInit());
#endif

auto video = drishti::videoio::VideoSourceCV::create(sInput);
video->setOutputFormat(drishti::videoio::VideoSourceCV::ARGB); // be explicit, fail on error
Expand All @@ -190,8 +190,8 @@ int gauze_main(int argc, char** argv)
logger->info("No frames available in video");
return -1;
}
if(maxZ < minZ)

if (maxZ < minZ)
{
logger->error("max distance must be > min distance");
return -1;
Expand All @@ -212,13 +212,13 @@ int gauze_main(int argc, char** argv)
settings.faceFinderInterval = 0.f;
settings.regressorCropScale = scale;
settings.acfCalibration = cascCal;
settings.renderFaces = true; // *** rendering ***
settings.renderPupils = true; // *** rendering ***
settings.renderCorners = false; // *** rendering ***
settings.renderFaces = true; // *** rendering ***
settings.renderPupils = true; // *** rendering ***
settings.renderCorners = false; // *** rendering ***
settings.minDetectionDistance = minZ;
settings.maxDetectionDistance = maxZ;
{ // Create a sensor specification
if(fx == 0.f)
if (fx == 0.f)
{
fx = frame.image.cols; // use a sensible default guess
}
Expand All @@ -231,9 +231,9 @@ int gauze_main(int argc, char** argv)

// Allocate the detector:
auto detector = drishti::hci::FaceFinderPainter::create(factory, settings, nullptr);
detector->setLetterboxHeight(1.0); // *** rendering ***
detector->setShowMotionAxes(false); // *** rendering ***
detector->setShowDetectionScales(false); // *** rendering ***
detector->setLetterboxHeight(1.0); // *** rendering ***
detector->setShowMotionAxes(false); // *** rendering ***
detector->setShowDetectionScales(false); // *** rendering ***

ogles_gpgpu::VideoSource source;
ogles_gpgpu::SwizzleProc swizzle(ogles_gpgpu::SwizzleProc::kSwizzleGRAB); // kSwizzleRGBA
Expand Down
9 changes: 4 additions & 5 deletions src/app/qt/facefilter/CameraListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "drishti/core/make_unique.h"

CameraListener::CameraListener(QCamera *camera, LoggerPtr &logger, const GLVersion &glVersion)
CameraListener::CameraListener(QCamera* camera, LoggerPtr& logger, const GLVersion& glVersion)
: m_camera(camera)
, m_logger(logger)
, m_glVersion(glVersion)
Expand All @@ -19,7 +19,7 @@ void CameraListener::setUsePBO(bool flag)

void CameraListener::updateCameraStatus(QCamera::Status status)
{
if(status == QCamera::LoadedStatus)
if (status == QCamera::LoadedStatus)
{
configureCamera();
}
Expand All @@ -28,7 +28,7 @@ void CameraListener::updateCameraStatus(QCamera::Status status)
void CameraListener::configureCamera()
{
m_logger->info("Configuring camera");

// Create a QMLCameraManager and configure camera
auto qmlCameraManager = drishti::core::make_unique<QMLCameraManager>(m_camera, m_logger);
auto size = qmlCameraManager->configure();
Expand All @@ -38,7 +38,7 @@ void CameraListener::configureCamera()
m_logger->error("Unable to configure valid camera resolution");
throw std::runtime_error("Unable to configure valid camera resolution");
}

m_logger->info("device: {}", qmlCameraManager->getDeviceName());
m_logger->info("description: {}", qmlCameraManager->getDescription());
m_logger->info("resolution: {} {}", qmlCameraManager->getSize().width, qmlCameraManager->getSize().height);
Expand All @@ -59,5 +59,4 @@ void CameraListener::configureCamera()
frameHandler->setSize(qmlCameraManager->getSize());
}
}

}
12 changes: 5 additions & 7 deletions src/app/qt/facefilter/CameraListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@ class CameraListener : public QObject
Q_OBJECT

public:

using LoggerPtr = std::shared_ptr<spdlog::logger>;

CameraListener(QCamera *camera, LoggerPtr &logger, const GLVersion &version);
CameraListener(QCamera* camera, LoggerPtr& logger, const GLVersion& version);

void setUsePBO(bool flag);

void configureCamera();

protected:

QCamera *m_camera = nullptr;
QCamera* m_camera = nullptr;
std::shared_ptr<spdlog::logger> m_logger;
GLVersion m_glVersion;
bool m_usePBO = false;

public slots:

void updateCameraStatus(QCamera::Status status);
void updateCameraStatus(QCamera::Status status);
};

#endif // _facefilter_CameraListener_h_
2 changes: 1 addition & 1 deletion src/app/qt/facefilter/FPSCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ float FPSCalculator::fps()
fps_ = (count_ > 0) ? ((fps_ * alpha_) + ((1.0 - alpha_) * fps)) : fps;
last_ = now;
++count_;
return fps_;
return fps_;
}
16 changes: 7 additions & 9 deletions src/app/qt/facefilter/FrameHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ std::unique_ptr<nlohmann::json> loadJSON(spdlog::logger& logger);

FrameHandlerManager* FrameHandlerManager::m_instance = nullptr;

FrameHandlerManager::FrameHandlerManager(const std::string& name, const std::string& description, const GLVersion &glVersion) :
m_glVersion(glVersion)
FrameHandlerManager::FrameHandlerManager(const std::string& name, const std::string& description, const GLVersion& glVersion)
: m_glVersion(glVersion)
{
m_logger = drishti::core::Logger::create("drishti");
m_logger->info("FrameHandlerManager #################################################################");
Expand All @@ -72,7 +72,7 @@ FrameHandlerManager::FrameHandlerManager(const std::string& name, const std::str
{
std::string host = address["host"];
std::string port = address["port"];

float frequency = address["frequency"];
m_imageLogger = std::make_shared<drishti::core::ImageLogger>(host, port);
m_imageLogger->setMaxFramesPerSecond(frequency); // throttle network traffic
Expand All @@ -97,15 +97,15 @@ FrameHandlerManager::FrameHandlerManager(const std::string& name, const std::str
const auto& intrinsic = sensor["intrinsic"];

cv::Size size;
const auto &sizeParams = intrinsic["size"];
const auto& sizeParams = intrinsic["size"];
if (!sizeParams.empty())
{
size.width = sizeParams["width"].get<int>();
size.height = sizeParams["height"].get<int>();
}

cv::Point2f p;
const auto &principalParams = intrinsic["principal"];
const auto& principalParams = intrinsic["principal"];
if (!principalParams.empty())
{
p.x = principalParams["x"].get<float>();
Expand Down Expand Up @@ -189,7 +189,7 @@ cv::Size FrameHandlerManager::getSize() const
}

FrameHandlerManager*
FrameHandlerManager::get(const std::string& name, const std::string& description, const GLVersion &glVersion)
FrameHandlerManager::get(const std::string& name, const std::string& description, const GLVersion& glVersion)
{
if (!m_instance)
{
Expand Down Expand Up @@ -225,8 +225,6 @@ std::unique_ptr<nlohmann::json> loadJSON(spdlog::logger& logger)
{
throw std::runtime_error("loadJSON: Can't read file");
}

return json;
}


13 changes: 6 additions & 7 deletions src/app/qt/facefilter/FrameHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ class FrameHandlerManager
using Settings = nlohmann::json;
using FrameHandler = std::function<void(const cv::Mat&)>;

FrameHandlerManager(const std::string& name, const std::string& description, const GLVersion &glVersion);
FrameHandlerManager(const std::string& name, const std::string& description, const GLVersion& glVersion);

~FrameHandlerManager();

bool good() const;

static FrameHandlerManager* get(const std::string& name = {}, const std::string& description = {}, const GLVersion &glVersion = {});
static FrameHandlerManager* get(const std::string& name = {}, const std::string& description = {}, const GLVersion& glVersion = {});

void setUsePBO(bool flag)
{
m_usePBO = flag;
}

bool getUsePBO()
{
return m_usePBO;
}

int getOrientation() const
{
return m_orientation;
Expand Down Expand Up @@ -141,13 +141,12 @@ class FrameHandlerManager
const Settings* getSettings() const { return m_settings.get(); }

protected:

std::unique_ptr<Settings> m_settings;

DetectionParams m_detectionParams;

GLVersion m_glVersion;

bool m_usePBO = false;
int m_orientation = 0;
std::string m_deviceName;
Expand Down
10 changes: 7 additions & 3 deletions src/app/qt/facefilter/GLVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
#define _facefilter_gl_version_h_

#if defined(major)
# undef major
#undef major
#endif

#if defined(minor)
# undef minor
#undef minor
#endif

struct GLVersion
{
GLVersion() = default;
GLVersion(int major, int minor) : major(major), minor(minor) {}
GLVersion(int major, int minor)
: major(major)
, minor(minor)
{
}
int major = 2;
int minor = 0;
};
Expand Down
Loading

0 comments on commit b6360c3

Please sign in to comment.