Skip to content

Commit

Permalink
fix CV_8UC1 thresholds for direct cv::Mat4b gpgpu ACF texture process…
Browse files Browse the repository at this point in the history
…ing (#66)

* fix CV_8UC1 thresholds for direct cv::Mat4b gpgpu ACF texture processing

* fix CV_8UC1 thresholds for direct cv::Mat4b gpgpu ACF texture processing (these were being scaled (x 255) correctly during `*.mat` and `*.cpb` deserialization but they also required a conversion to CV_8UC1 format — CV_Assert() tests have been added to cover this case
* various updates to the pipeline test to support direct in report testsing and comparison between the ACF cpu pyramid based processing and the optimized GPGPU pyramid approximation
  + refactoring of GPUDetectionPipeline to accomodate both CPU and interleaved read/rocessing GPU based pipelines
  + return backing cv::Mat storage for FrameInput in pipeline Application test : getFrameInput(ogles_gpgpu::FrmaeInput &frame)
  + add pipeline GPUDetectionPipeline flags to toggle cpu/gpu processing for comparison/debugging
  + move VideoCaptureImage.{h,cpp} to separate files
* add simple parallel_for evaluation of detection scales (use randomized indices for first scheduler)
* bump version

* clang-format everything

* for max resolution in cv::VideoCapture interface, add comments

* support user specified webcam size from command line for cv::VideoCapture (--size=1920x1080), since auto/max approach doesn't work consistently
  • Loading branch information
headupinclouds authored May 16, 2018
1 parent 379254a commit d821ad3
Show file tree
Hide file tree
Showing 22 changed files with 646 additions and 292 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ endif()
###################

# See https://github.com/hunter-packages/check_ci_tag when changing VERSION
project(acf VERSION 0.1.7)
project(acf VERSION 0.1.8)

set(ACF_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}")

Expand Down
23 changes: 10 additions & 13 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
if(IOS OR ANDROID)
# local workaround for protobuf compiler crash with Xcode 8.1
# see https://github.com/elucideye/acf/issues/41
set(opencv_cmake_args
WITH_PROTOBUF=OFF
BUILD_PROTOBUF=OFF
BUILD_LIBPROTOBUF_FROM_SOURCES=NO
BUILD_opencv_dnn=OFF

WITH_JASPER=OFF
BUILD_JASPER=OFF
# the oepncv protobuf isn't friendly to a lot of compilers, skip it by default
set(opencv_cmake_args
WITH_PROTOBUF=OFF
BUILD_PROTOBUF=OFF
BUILD_LIBPROTOBUF_FROM_SOURCES=NO
BUILD_opencv_dnn=OFF

WITH_JASPER=OFF
BUILD_JASPER=OFF
)
hunter_config(OpenCV VERSION ${HUNTER_OpenCV_VERSION} CMAKE_ARGS ${opencv_cmake_args})
endif()
hunter_config(OpenCV VERSION ${HUNTER_OpenCV_VERSION} CMAKE_ARGS ${opencv_cmake_args})

### ogles_gpgpu ###
set(ogles_gpgpu_cmake_args
Expand Down
6 changes: 3 additions & 3 deletions src/app/acf/GLDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void GLDetector::init(const cv::Mat& I)
computePyramid(I, m_impl->Pcpu);
const int shrink = opts.pPyramid->pChns->shrink.get();
const auto sizes = getPyramidSizes(m_impl->Pcpu, shrink);
static const bool doGray = false;
static const bool doGray = false;
const ogles_gpgpu::Size2d inputSize(I.cols, I.rows);
m_impl->acf = std::make_shared<ogles_gpgpu::ACF>(nullptr, inputSize, sizes, m_impl->featureKind, doGray, shrink);
m_impl->acf->setDoLuvTransfer(false);
Expand All @@ -84,7 +84,7 @@ const acf::Detector::Pyramid& GLDetector::getPyramid(const cv::Mat& input, const
(*m_impl->context)();

// Fill in the pyramid:
(*m_impl->acf)({{ input.cols, input.rows }, void_ptr(input.ptr()), true, 0, DFLT_TEXTURE_FORMAT});
(*m_impl->acf)({ { input.cols, input.rows }, void_ptr(input.ptr()), true, 0, DFLT_TEXTURE_FORMAT });
glFlush();
m_impl->acf->fill(m_impl->Pgpu, m_impl->Pcpu);

Expand Down Expand Up @@ -129,7 +129,7 @@ std::vector<ogles_gpgpu::Size2d> getPyramidSizes(acf::Detector::Pyramid& Pcpu, i

void GLDetector::clear()
{
m_impl->size = {0,0};
m_impl->size = { 0, 0 };
}

cv::Mat GLDetector::draw(bool doGpu)
Expand Down
2 changes: 1 addition & 1 deletion src/app/acf/GLDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GLDetector : public acf::Detector

cv::Mat draw(bool gpu); // debug routine
void clear();

protected:
void init(const cv::Mat& I);
void initContext();
Expand Down
82 changes: 44 additions & 38 deletions src/app/acf/acf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ using ObjectDetectorPtr = std::shared_ptr<acf::ObjectDetector>;
using AcfPtr = std::shared_ptr<acf::Detector>;
using RectVec = std::vector<cv::Rect>;

static void randomShapes(cv::Mat &image, int n);
static void randomShapes(cv::Mat& image, int n);

struct VideoSource
{
Expand All @@ -65,16 +65,16 @@ struct VideoSource
{
filenames = util::cli::expand(filename);
}

VideoSource(int n) : m_n(n) // random frames

VideoSource(int n)
: m_n(n) // random frames
{

}

virtual Frame operator()(int i)
{
Frame frame;
if(filenames.size())
if (filenames.size())
{
frame.name = filenames[i];
frame.image = cv::imread(filenames[i], cv::IMREAD_COLOR);
Expand All @@ -83,9 +83,9 @@ struct VideoSource
{
frame.name = std::to_string(i);
frame.image = cv::Mat::zeros(640, 480, CV_8UC3);
randomShapes(frame.image, rand()%32);
randomShapes(frame.image, rand() % 32);
}

return frame;
}

Expand Down Expand Up @@ -244,7 +244,7 @@ int gauze_main(int argc, char** argv)
}

std::shared_ptr<VideoSource> video;
if(doRandom)
if (doRandom)
{
video = std::make_shared<VideoSource>(1000);
}
Expand Down Expand Up @@ -308,9 +308,9 @@ int gauze_main(int argc, char** argv)
// Get thread specific segmenter lazily:
auto& detector = manager[std::this_thread::get_id()];
assert(detector);

auto winSize = detector->getWindowSize();
if(!detector->getIsRowMajor())
if (!detector->getIsRowMajor())
{
std::swap(winSize.width, winSize.height);
}
Expand Down Expand Up @@ -367,7 +367,7 @@ int gauze_main(int argc, char** argv)
{
maxScore = *iter;
}

if (doPyramids)
{
// The "--pyramid" command line option can be used to visualize the
Expand All @@ -378,7 +378,7 @@ int gauze_main(int argc, char** argv)
// method in order to ensure the CPU pyramid will be computed for each
// frame.
#if defined(ACF_DO_GPU)
if(acf::GLDetector *handle = dynamic_cast<acf::GLDetector*>(detector.get()))
if (acf::GLDetector* handle = dynamic_cast<acf::GLDetector*>(detector.get()))
{
cv::Mat Pcpu = handle->draw(false);
cv::Mat Pgpu = handle->draw(true);
Expand Down Expand Up @@ -450,17 +450,20 @@ int main(int argc, char** argv)
{
try
{
const std::string home=getenv("HOME");
std::vector<char *> args(argc);
std::string home;
#if !(defined(_WIN32) || defined(_WIN64))
home = getenv("HOME");
#endif
std::vector<char*> args(argc);
args[0] = argv[0];

std::vector<std::string> storage(argc);
for(int i = 0; i < argc; i++)
for (int i = 0; i < argc; i++)
{
storage[i] = std::regex_replace(std::string(argv[i]), std::regex("HOME"), home);
args[i] = const_cast<char*>(storage[i].c_str());
}

return gauze_main(argc, &args.front());
}
catch (std::exception& e)
Expand Down Expand Up @@ -534,60 +537,63 @@ static cv::Rect2f operator*(const cv::Rect2f& roi, float scale)
return { roi.x * scale, roi.y * scale, roi.width * scale, roi.height * scale };
}

static void randomEllipse(cv::Mat &image, int n)
static void randomEllipse(cv::Mat& image, int n)
{
for(int i = 0; i < n; i++)
for (int i = 0; i < n; i++)
{
const cv::Point2f center(rand()%image.cols, rand()%image.rows);
const cv::Size2f size(rand()%image.cols, rand()%image.rows);
const cv::RotatedRect ellipse(center, size, static_cast<float>(rand() % 1000)/1000.f * M_PI);
const cv::Scalar bgr(rand()%255, rand()%255, rand()%255);
const cv::Point2f center(rand() % image.cols, rand() % image.rows);
const cv::Size2f size(rand() % image.cols, rand() % image.rows);
const cv::RotatedRect ellipse(center, size, static_cast<float>(rand() % 1000) / 1000.f * M_PI);
const cv::Scalar bgr(rand() % 255, rand() % 255, rand() % 255);
cv::ellipse(image, ellipse, bgr, -1);
}
}

static void randomRectangle(cv::Mat &image, int n)
static void randomRectangle(cv::Mat& image, int n)
{
for(int i = 0; i < n; i++)
for (int i = 0; i < n; i++)
{
const cv::Point p1(rand() % image.cols, rand() % image.rows);
const cv::Point p2(rand() % image.cols, rand() % image.rows);
if((rand() % 8) > 4)

if ((rand() % 8) > 4)
{
cv::randu(image(cv::Rect(p1, p2)), cv::Scalar::all(0), cv::Scalar::all(255));
}
else
{
const cv::Scalar bgr(rand()%255, rand()%255, rand()%255);
const cv::Scalar bgr(rand() % 255, rand() % 255, rand() % 255);
cv::rectangle(image, p1, p2, bgr, -1);
}
}
}

static void randomLines(cv::Mat &image, int n)
static void randomLines(cv::Mat& image, int n)
{
for(int i = 0; i < n; i++)
for (int i = 0; i < n; i++)
{
const cv::Point u1(rand() % image.cols, rand() % image.rows);
const cv::Point u2(rand() % image.cols, rand() % image.rows);
const cv::Scalar bgr(rand()%255, rand()%255, rand()%255);
cv::line(image, u1, u2, bgr, (rand() % 16)+1, 8);
const cv::Scalar bgr(rand() % 255, rand() % 255, rand() % 255);
cv::line(image, u1, u2, bgr, (rand() % 16) + 1, 8);
}
}

// Provide a simple mechanism for testing the ACF pyramids (GPU and CPU)
// without the need for reading actual images. This was added initially
// to aid testing on mobile devices.
static void randomShapes(cv::Mat &image, int n)
static void randomShapes(cv::Mat& image, int n)
{
for(int i = 0; i < n; i++)
for (int i = 0; i < n; i++)
{
switch(rand()%3)
switch (rand() % 3)
{
case 0: randomLines(image, 1);
case 1: randomRectangle(image, 1);
case 2: randomEllipse(image, 1);
case 0:
randomLines(image, 1);
case 1:
randomRectangle(image, 1);
case 2:
randomEllipse(image, 1);
}
}
}
2 changes: 1 addition & 1 deletion src/app/acf/mat2cpb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int gauze_main(int argc, char** argv)
acf::Detector acf(sInput);

save_cpb(sOutput, acf);

return 0;
}

Expand Down
15 changes: 4 additions & 11 deletions src/app/pipeline/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ set(acf_srcs
pipeline.cpp
GPUDetectionPipeline.h
GPUDetectionPipeline.cpp

VideoCaptureImage.h
VideoCaptureImage.cpp

# Simple line segment shader for the usual green box annotations:
lines.h
Expand Down Expand Up @@ -38,16 +41,6 @@ target_compile_definitions(${test_app} PUBLIC ACF_DO_GPU=1)
set_property(TARGET ${test_app} PROPERTY FOLDER "app/console")
install(TARGETS ${test_app} DESTINATION bin)

set_target_properties(
${test_app}
PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/plist.in" # file sharing
XCODE_ATTRIBUTE_PRODUCT_NAME "${test_app}"
XCODE_ATTRIBUTE_BUNDLE_IDENTIFIER "com.elucideye.acf.${test_app}"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.elucideye.acf.${test_app}"
XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2" # iPhone/iPad
)

#############
### TEST ####
#############
Expand All @@ -58,7 +51,7 @@ gauze_add_test(
NAME ${test_name}
COMMAND ${test_app}
--input=$<GAUZE_RESOURCE_FILE:${DRISHTI_FACES_FACE_IMAGE}>
--repeat=64
--repeat=600
--model=$<GAUZE_RESOURCE_FILE:${DRISHTI_ASSETS_FACE_DETECTOR}>
--minimum=128
--calibration=0.01
Expand Down
Loading

0 comments on commit d821ad3

Please sign in to comment.