removed obsolete tests
This commit is contained in:
parent
8be541eed2
commit
2c8af20bd0
@ -1,65 +0,0 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
# CMake file for gputest. See root CMakeLists.txt
|
||||
# ----------------------------------------------------------------------------
|
||||
project(opencv_test_gpu)
|
||||
|
||||
set(the_target "opencv_test_gpu")
|
||||
|
||||
file(GLOB test_srcs "src/*.cpp")
|
||||
file(GLOB test_hdrs "src/*.h*")
|
||||
source_group("Src" FILES ${test_srcs})
|
||||
source_group("Include" FILES ${test_hdrs})
|
||||
|
||||
|
||||
|
||||
|
||||
include_directories (
|
||||
"${CMAKE_SOURCE_DIR}/include/opencv"
|
||||
"${CMAKE_SOURCE_DIR}/modules/core/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/imgproc/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/features2d/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/flann/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/calib3d/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/highgui/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/objdetect/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/video/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/legacy/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/contrib/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/gpu/include"
|
||||
"${CMAKE_SOURCE_DIR}/modules/ml/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/modules/gpu/src/nvidia"
|
||||
"${CMAKE_SOURCE_DIR}/modules/gpu/src/nvidia/core"
|
||||
)
|
||||
|
||||
include_directories(../cxts)
|
||||
|
||||
if(HAVE_CUDA)
|
||||
include_directories(${CUDA_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/modules/gpu/src/nvidia ${CMAKE_SOURCE_DIR}/modules/gpu/src/nvidia/core ${CMAKE_SOURCE_DIR}/modules/gpu/src/nvidia/NPP_staging)
|
||||
|
||||
file(GLOB nvidia "src/nvidia/*.*")
|
||||
source_group("Src\\nvidia" FILES ${nvidia})
|
||||
endif()
|
||||
|
||||
add_executable(${the_target} ${test_srcs} ${test_hdrs} ${nvidia})
|
||||
|
||||
# Additional target properties
|
||||
set_target_properties(${the_target} PROPERTIES
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
||||
)
|
||||
|
||||
add_dependencies(${the_target} opencv_ts opencv_gpu opencv_highgui opencv_imgproc opencv_calib3d)
|
||||
|
||||
# Add the required libraries for linking:
|
||||
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_ts opencv_gpu opencv_highgui opencv_imgproc opencv_calib3d)
|
||||
|
||||
enable_testing()
|
||||
get_target_property(LOC ${the_target} LOCATION)
|
||||
add_test(${the_target} "${LOC}")
|
||||
|
||||
if(WIN32)
|
||||
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
|
||||
endif()
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,234 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include "gputest.hpp"
|
||||
|
||||
#define CHECK(pred, err) if (!(pred)) { \
|
||||
ts->printf(CvTS::CONSOLE, "Fail: \"%s\" at line: %d\n", #pred, __LINE__); \
|
||||
ts->set_failed_test_info(err); \
|
||||
return; }
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
struct CV_GpuBitwiseTest: public CvTest
|
||||
{
|
||||
CV_GpuBitwiseTest(): CvTest("GPU-BitwiseOpersTest", "bitwiseMatOperators") {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
int rows, cols;
|
||||
|
||||
bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) &&
|
||||
gpu::DeviceInfo().supports(gpu::NATIVE_DOUBLE);
|
||||
int depth_end = double_ok ? CV_64F : CV_32F;
|
||||
|
||||
for (int depth = CV_8U; depth <= depth_end; ++depth)
|
||||
for (int cn = 1; cn <= 4; ++cn)
|
||||
for (int attempt = 0; attempt < 3; ++attempt)
|
||||
{
|
||||
rows = 1 + rand() % 100;
|
||||
cols = 1 + rand() % 100;
|
||||
test_bitwise_not(rows, cols, CV_MAKETYPE(depth, cn));
|
||||
test_bitwise_or(rows, cols, CV_MAKETYPE(depth, cn));
|
||||
test_bitwise_and(rows, cols, CV_MAKETYPE(depth, cn));
|
||||
test_bitwise_xor(rows, cols, CV_MAKETYPE(depth, cn));
|
||||
}
|
||||
}
|
||||
|
||||
void test_bitwise_not(int rows, int cols, int type)
|
||||
{
|
||||
Mat src(rows, cols, type);
|
||||
|
||||
RNG rng;
|
||||
for (int i = 0; i < src.rows; ++i)
|
||||
{
|
||||
Mat row(1, src.cols * src.elemSize(), CV_8U, src.ptr(i));
|
||||
rng.fill(row, RNG::UNIFORM, Scalar(0), Scalar(255));
|
||||
}
|
||||
|
||||
Mat dst_gold = ~src;
|
||||
|
||||
gpu::GpuMat mask(src.size(), CV_8U);
|
||||
mask.setTo(Scalar(1));
|
||||
|
||||
gpu::GpuMat dst;
|
||||
gpu::bitwise_not(gpu::GpuMat(src), dst);
|
||||
|
||||
CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
|
||||
Mat dsth(dst);
|
||||
for (int i = 0; i < dst_gold.rows; ++i)
|
||||
CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT);
|
||||
|
||||
dst.setTo(Scalar::all(0));
|
||||
gpu::bitwise_not(gpu::GpuMat(src), dst, mask);
|
||||
|
||||
CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
|
||||
dsth = dst;
|
||||
for (int i = 0; i < dst_gold.rows; ++i)
|
||||
CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
|
||||
}
|
||||
|
||||
void test_bitwise_or(int rows, int cols, int type)
|
||||
{
|
||||
Mat src1(rows, cols, type);
|
||||
Mat src2(rows, cols, type);
|
||||
|
||||
RNG rng;
|
||||
for (int i = 0; i < src1.rows; ++i)
|
||||
{
|
||||
Mat row1(1, src1.cols * src1.elemSize(), CV_8U, src1.ptr(i));
|
||||
rng.fill(row1, RNG::UNIFORM, Scalar(0), Scalar(255));
|
||||
Mat row2(1, src2.cols * src2.elemSize(), CV_8U, src2.ptr(i));
|
||||
rng.fill(row2, RNG::UNIFORM, Scalar(0), Scalar(255));
|
||||
}
|
||||
|
||||
Mat dst_gold = src1 | src2;
|
||||
gpu::GpuMat dst = gpu::GpuMat(src1) | gpu::GpuMat(src2);
|
||||
|
||||
CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
Mat dsth(dst);
|
||||
for (int i = 0; i < dst_gold.rows; ++i)
|
||||
CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
|
||||
|
||||
Mat mask(src1.size(), CV_8U);
|
||||
randu(mask, Scalar(0), Scalar(255));
|
||||
|
||||
Mat dst_gold2(dst_gold.size(), dst_gold.type()); dst_gold2.setTo(Scalar::all(0));
|
||||
gpu::GpuMat dst2(dst.size(), dst.type()); dst2.setTo(Scalar::all(0));
|
||||
bitwise_or(src1, src2, dst_gold2, mask);
|
||||
gpu::bitwise_or(gpu::GpuMat(src1), gpu::GpuMat(src2), dst2, gpu::GpuMat(mask));
|
||||
|
||||
CHECK(dst_gold2.size() == dst2.size(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
CHECK(dst_gold2.type() == dst2.type(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
dsth = dst2;
|
||||
for (int i = 0; i < dst_gold.rows; ++i)
|
||||
CHECK(memcmp(dst_gold2.ptr(i), dsth.ptr(i), dst_gold2.cols * dst_gold2.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
|
||||
}
|
||||
|
||||
void test_bitwise_and(int rows, int cols, int type)
|
||||
{
|
||||
Mat src1(rows, cols, type);
|
||||
Mat src2(rows, cols, type);
|
||||
|
||||
RNG rng;
|
||||
for (int i = 0; i < src1.rows; ++i)
|
||||
{
|
||||
Mat row1(1, src1.cols * src1.elemSize(), CV_8U, src1.ptr(i));
|
||||
rng.fill(row1, RNG::UNIFORM, Scalar(0), Scalar(255));
|
||||
Mat row2(1, src2.cols * src2.elemSize(), CV_8U, src2.ptr(i));
|
||||
rng.fill(row2, RNG::UNIFORM, Scalar(0), Scalar(255));
|
||||
}
|
||||
|
||||
Mat dst_gold = src1 & src2;
|
||||
|
||||
gpu::GpuMat dst = gpu::GpuMat(src1) & gpu::GpuMat(src2);
|
||||
|
||||
CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
Mat dsth(dst);
|
||||
for (int i = 0; i < dst_gold.rows; ++i)
|
||||
CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
|
||||
|
||||
|
||||
Mat mask(src1.size(), CV_8U);
|
||||
randu(mask, Scalar(0), Scalar(255));
|
||||
|
||||
Mat dst_gold2(dst_gold.size(), dst_gold.type()); dst_gold2.setTo(Scalar::all(0));
|
||||
gpu::GpuMat dst2(dst.size(), dst.type()); dst2.setTo(Scalar::all(0));
|
||||
bitwise_and(src1, src2, dst_gold2, mask);
|
||||
gpu::bitwise_and(gpu::GpuMat(src1), gpu::GpuMat(src2), dst2, gpu::GpuMat(mask));
|
||||
|
||||
CHECK(dst_gold2.size() == dst2.size(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
CHECK(dst_gold2.type() == dst2.type(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
dsth = dst2;
|
||||
for (int i = 0; i < dst_gold.rows; ++i)
|
||||
CHECK(memcmp(dst_gold2.ptr(i), dsth.ptr(i), dst_gold2.cols * dst_gold2.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
|
||||
}
|
||||
|
||||
void test_bitwise_xor(int rows, int cols, int type)
|
||||
{
|
||||
Mat src1(rows, cols, type);
|
||||
Mat src2(rows, cols, type);
|
||||
|
||||
RNG rng;
|
||||
for (int i = 0; i < src1.rows; ++i)
|
||||
{
|
||||
Mat row1(1, src1.cols * src1.elemSize(), CV_8U, src1.ptr(i));
|
||||
rng.fill(row1, RNG::UNIFORM, Scalar(0), Scalar(255));
|
||||
Mat row2(1, src2.cols * src2.elemSize(), CV_8U, src2.ptr(i));
|
||||
rng.fill(row2, RNG::UNIFORM, Scalar(0), Scalar(255));
|
||||
}
|
||||
|
||||
Mat dst_gold = src1 ^ src2;
|
||||
|
||||
gpu::GpuMat dst = gpu::GpuMat(src1) ^ gpu::GpuMat(src2);
|
||||
|
||||
CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
Mat dsth(dst);
|
||||
for (int i = 0; i < dst_gold.rows; ++i)
|
||||
CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
|
||||
|
||||
|
||||
Mat mask(src1.size(), CV_8U);
|
||||
randu(mask, Scalar(0), Scalar(255));
|
||||
|
||||
Mat dst_gold2(dst_gold.size(), dst_gold.type()); dst_gold2.setTo(Scalar::all(0));
|
||||
gpu::GpuMat dst2(dst.size(), dst.type()); dst2.setTo(Scalar::all(0));
|
||||
bitwise_xor(src1, src2, dst_gold2, mask);
|
||||
gpu::bitwise_xor(gpu::GpuMat(src1), gpu::GpuMat(src2), dst2, gpu::GpuMat(mask));
|
||||
|
||||
CHECK(dst_gold2.size() == dst2.size(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
CHECK(dst_gold2.type() == dst2.type(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
dsth = dst2;
|
||||
for (int i = 0; i < dst_gold.rows; ++i)
|
||||
CHECK(memcmp(dst_gold2.ptr(i), dsth.ptr(i), dst_gold2.cols * dst_gold2.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
|
||||
}
|
||||
} gpu_bitwise_test;
|
||||
|
@ -1,532 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
using namespace std;
|
||||
|
||||
class CV_GpuBruteForceMatcherTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GpuBruteForceMatcherTest() :
|
||||
CvTest( "GPU-BruteForceMatcher", "BruteForceMatcher" )
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void run(int);
|
||||
|
||||
void emptyDataTest();
|
||||
void dataTest(int dim);
|
||||
|
||||
void generateData(GpuMat& query, GpuMat& train, int dim);
|
||||
|
||||
void matchTest(const GpuMat& query, const GpuMat& train);
|
||||
void knnMatchTest(const GpuMat& query, const GpuMat& train);
|
||||
void radiusMatchTest(const GpuMat& query, const GpuMat& train);
|
||||
|
||||
private:
|
||||
BruteForceMatcher_GPU< L2<float> > dmatcher;
|
||||
|
||||
static const int queryDescCount = 300; // must be even number because we split train data in some cases in two
|
||||
static const int countFactor = 4; // do not change it
|
||||
};
|
||||
|
||||
void CV_GpuBruteForceMatcherTest::emptyDataTest()
|
||||
{
|
||||
GpuMat queryDescriptors, trainDescriptors, mask;
|
||||
vector<GpuMat> trainDescriptorCollection, masks;
|
||||
vector<DMatch> matches;
|
||||
vector< vector<DMatch> > vmatches;
|
||||
|
||||
try
|
||||
{
|
||||
dmatcher.match(queryDescriptors, trainDescriptors, matches, mask);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "match() on empty descriptors must not generate exception (1).\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dmatcher.knnMatch(queryDescriptors, trainDescriptors, vmatches, 2, mask);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "knnMatch() on empty descriptors must not generate exception (1).\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dmatcher.radiusMatch(queryDescriptors, trainDescriptors, vmatches, 10.f, mask);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "radiusMatch() on empty descriptors must not generate exception (1).\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dmatcher.add(trainDescriptorCollection);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "add() on empty descriptors must not generate exception.\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dmatcher.match(queryDescriptors, matches, masks);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "match() on empty descriptors must not generate exception (2).\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dmatcher.knnMatch(queryDescriptors, vmatches, 2, masks);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "knnMatch() on empty descriptors must not generate exception (2).\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dmatcher.radiusMatch( queryDescriptors, vmatches, 10.f, masks );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "radiusMatch() on empty descriptors must not generate exception (2).\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CV_GpuBruteForceMatcherTest::generateData( GpuMat& queryGPU, GpuMat& trainGPU, int dim )
|
||||
{
|
||||
Mat query, train;
|
||||
RNG rng(*ts->get_rng());
|
||||
|
||||
// Generate query descriptors randomly.
|
||||
// Descriptor vector elements are integer values.
|
||||
Mat buf( queryDescCount, dim, CV_32SC1 );
|
||||
rng.fill( buf, RNG::UNIFORM, Scalar::all(0), Scalar(3) );
|
||||
buf.convertTo( query, CV_32FC1 );
|
||||
|
||||
// Generate train decriptors as follows:
|
||||
// copy each query descriptor to train set countFactor times
|
||||
// and perturb some one element of the copied descriptors in
|
||||
// in ascending order. General boundaries of the perturbation
|
||||
// are (0.f, 1.f).
|
||||
train.create( query.rows*countFactor, query.cols, CV_32FC1 );
|
||||
float step = 1.f / countFactor;
|
||||
for( int qIdx = 0; qIdx < query.rows; qIdx++ )
|
||||
{
|
||||
Mat queryDescriptor = query.row(qIdx);
|
||||
for( int c = 0; c < countFactor; c++ )
|
||||
{
|
||||
int tIdx = qIdx * countFactor + c;
|
||||
Mat trainDescriptor = train.row(tIdx);
|
||||
queryDescriptor.copyTo( trainDescriptor );
|
||||
int elem = rng(dim);
|
||||
float diff = rng.uniform( step*c, step*(c+1) );
|
||||
trainDescriptor.at<float>(0, elem) += diff;
|
||||
}
|
||||
}
|
||||
|
||||
queryGPU.upload(query);
|
||||
trainGPU.upload(train);
|
||||
}
|
||||
|
||||
void CV_GpuBruteForceMatcherTest::matchTest( const GpuMat& query, const GpuMat& train )
|
||||
{
|
||||
dmatcher.clear();
|
||||
|
||||
// test const version of match()
|
||||
{
|
||||
vector<DMatch> matches;
|
||||
dmatcher.match( query, train, matches );
|
||||
|
||||
if( (int)matches.size() != queryDescCount )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Incorrect matches count while test match() function (1).\n");
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
else
|
||||
{
|
||||
int badCount = 0;
|
||||
for( size_t i = 0; i < matches.size(); i++ )
|
||||
{
|
||||
DMatch match = matches[i];
|
||||
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor) || (match.imgIdx != 0) )
|
||||
badCount++;
|
||||
}
|
||||
if (badCount > 0)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "%f - too large bad matches part while test match() function (1).\n",
|
||||
(float)badCount/(float)queryDescCount );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test version of match() with add()
|
||||
{
|
||||
vector<DMatch> matches;
|
||||
// make add() twice to test such case
|
||||
dmatcher.add( vector<GpuMat>(1,train.rowRange(0, train.rows/2)) );
|
||||
dmatcher.add( vector<GpuMat>(1,train.rowRange(train.rows/2, train.rows)) );
|
||||
// prepare masks (make first nearest match illegal)
|
||||
vector<GpuMat> masks(2);
|
||||
for(int mi = 0; mi < 2; mi++ )
|
||||
{
|
||||
masks[mi] = GpuMat(query.rows, train.rows/2, CV_8UC1, Scalar::all(1));
|
||||
for( int di = 0; di < queryDescCount/2; di++ )
|
||||
masks[mi].col(di*countFactor).setTo(Scalar::all(0));
|
||||
}
|
||||
|
||||
dmatcher.match( query, matches, masks );
|
||||
|
||||
if( (int)matches.size() != queryDescCount )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Incorrect matches count while test match() function (2).\n");
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
else
|
||||
{
|
||||
int badCount = 0;
|
||||
for( size_t i = 0; i < matches.size(); i++ )
|
||||
{
|
||||
DMatch match = matches[i];
|
||||
int shift = dmatcher.isMaskSupported() ? 1 : 0;
|
||||
{
|
||||
if( i < queryDescCount/2 )
|
||||
{
|
||||
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor + shift) || (match.imgIdx != 0) )
|
||||
badCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (match.queryIdx != (int)i) || (match.trainIdx != ((int)i-queryDescCount/2)*countFactor + shift) || (match.imgIdx != 1) )
|
||||
badCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (badCount > 0)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "%f - too large bad matches part while test match() function (2).\n",
|
||||
(float)badCount/(float)queryDescCount );
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CV_GpuBruteForceMatcherTest::knnMatchTest( const GpuMat& query, const GpuMat& train )
|
||||
{
|
||||
dmatcher.clear();
|
||||
|
||||
// test const version of knnMatch()
|
||||
{
|
||||
const int knn = 3;
|
||||
|
||||
vector< vector<DMatch> > matches;
|
||||
dmatcher.knnMatch( query, train, matches, knn );
|
||||
|
||||
if( (int)matches.size() != queryDescCount )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Incorrect matches count while test knnMatch() function (1).\n");
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
else
|
||||
{
|
||||
int badCount = 0;
|
||||
for( size_t i = 0; i < matches.size(); i++ )
|
||||
{
|
||||
if( (int)matches[i].size() != knn )
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
int localBadCount = 0;
|
||||
for( int k = 0; k < knn; k++ )
|
||||
{
|
||||
DMatch match = matches[i][k];
|
||||
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor+k) || (match.imgIdx != 0) )
|
||||
localBadCount++;
|
||||
}
|
||||
badCount += localBadCount > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
if (badCount > 0)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "%f - too large bad matches part while test knnMatch() function (1).\n",
|
||||
(float)badCount/(float)queryDescCount );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test version of knnMatch() with add()
|
||||
{
|
||||
const int knn = 2;
|
||||
vector<vector<DMatch> > matches;
|
||||
// make add() twice to test such case
|
||||
dmatcher.add( vector<GpuMat>(1,train.rowRange(0, train.rows/2)) );
|
||||
dmatcher.add( vector<GpuMat>(1,train.rowRange(train.rows/2, train.rows)) );
|
||||
// prepare masks (make first nearest match illegal)
|
||||
vector<GpuMat> masks(2);
|
||||
for(int mi = 0; mi < 2; mi++ )
|
||||
{
|
||||
masks[mi] = GpuMat(query.rows, train.rows/2, CV_8UC1, Scalar::all(1));
|
||||
for( int di = 0; di < queryDescCount/2; di++ )
|
||||
masks[mi].col(di*countFactor).setTo(Scalar::all(0));
|
||||
}
|
||||
|
||||
dmatcher.knnMatch( query, matches, knn, masks );
|
||||
|
||||
if( (int)matches.size() != queryDescCount )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Incorrect matches count while test knnMatch() function (2).\n");
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
else
|
||||
{
|
||||
int badCount = 0;
|
||||
int shift = dmatcher.isMaskSupported() ? 1 : 0;
|
||||
for( size_t i = 0; i < matches.size(); i++ )
|
||||
{
|
||||
if( (int)matches[i].size() != knn )
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
int localBadCount = 0;
|
||||
for( int k = 0; k < knn; k++ )
|
||||
{
|
||||
DMatch match = matches[i][k];
|
||||
{
|
||||
if( i < queryDescCount/2 )
|
||||
{
|
||||
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor + k + shift) ||
|
||||
(match.imgIdx != 0) )
|
||||
localBadCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (match.queryIdx != (int)i) || (match.trainIdx != ((int)i-queryDescCount/2)*countFactor + k + shift) ||
|
||||
(match.imgIdx != 1) )
|
||||
localBadCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
badCount += localBadCount > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
if (badCount > 0)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "%f - too large bad matches part while test knnMatch() function (2).\n",
|
||||
(float)badCount/(float)queryDescCount );
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CV_GpuBruteForceMatcherTest::radiusMatchTest( const GpuMat& query, const GpuMat& train )
|
||||
{
|
||||
bool atomics_ok = TargetArchs::builtWith(GLOBAL_ATOMICS) && DeviceInfo().supports(GLOBAL_ATOMICS);
|
||||
if (!atomics_ok)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "\nCode and device atomics support is required for radiusMatch (CC >= 1.1)");
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
|
||||
dmatcher.clear();
|
||||
// test const version of match()
|
||||
{
|
||||
const float radius = 1.f/countFactor;
|
||||
vector< vector<DMatch> > matches;
|
||||
dmatcher.radiusMatch( query, train, matches, radius );
|
||||
|
||||
if( (int)matches.size() != queryDescCount )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Incorrect matches count while test radiusMatch() function (1).\n");
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
else
|
||||
{
|
||||
int badCount = 0;
|
||||
for( size_t i = 0; i < matches.size(); i++ )
|
||||
{
|
||||
if( (int)matches[i].size() != 1 )
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
DMatch match = matches[i][0];
|
||||
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor) || (match.imgIdx != 0) )
|
||||
badCount++;
|
||||
}
|
||||
}
|
||||
if (badCount > 0)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "%f - too large bad matches part while test radiusMatch() function (1).\n",
|
||||
(float)badCount/(float)queryDescCount );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test version of match() with add()
|
||||
{
|
||||
int n = 3;
|
||||
const float radius = 1.f/countFactor * n;
|
||||
vector< vector<DMatch> > matches;
|
||||
// make add() twice to test such case
|
||||
dmatcher.add( vector<GpuMat>(1,train.rowRange(0, train.rows/2)) );
|
||||
dmatcher.add( vector<GpuMat>(1,train.rowRange(train.rows/2, train.rows)) );
|
||||
// prepare masks (make first nearest match illegal)
|
||||
vector<GpuMat> masks(2);
|
||||
for(int mi = 0; mi < 2; mi++ )
|
||||
{
|
||||
masks[mi] = GpuMat(query.rows, train.rows/2, CV_8UC1, Scalar::all(1));
|
||||
for( int di = 0; di < queryDescCount/2; di++ )
|
||||
masks[mi].col(di*countFactor).setTo(Scalar::all(0));
|
||||
}
|
||||
|
||||
dmatcher.radiusMatch( query, matches, radius, masks );
|
||||
|
||||
int curRes = CvTS::OK;
|
||||
if( (int)matches.size() != queryDescCount )
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Incorrect matches count while test radiusMatch() function (1).\n");
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
|
||||
int badCount = 0;
|
||||
int shift = dmatcher.isMaskSupported() ? 1 : 0;
|
||||
int needMatchCount = dmatcher.isMaskSupported() ? n-1 : n;
|
||||
for( size_t i = 0; i < matches.size(); i++ )
|
||||
{
|
||||
if( (int)matches[i].size() != needMatchCount )
|
||||
badCount++;
|
||||
else
|
||||
{
|
||||
int localBadCount = 0;
|
||||
for( int k = 0; k < needMatchCount; k++ )
|
||||
{
|
||||
DMatch match = matches[i][k];
|
||||
{
|
||||
if( i < queryDescCount/2 )
|
||||
{
|
||||
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor + k + shift) ||
|
||||
(match.imgIdx != 0) )
|
||||
localBadCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (match.queryIdx != (int)i) || (match.trainIdx != ((int)i-queryDescCount/2)*countFactor + k + shift) ||
|
||||
(match.imgIdx != 1) )
|
||||
localBadCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
badCount += localBadCount > 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (badCount > 0)
|
||||
{
|
||||
curRes = CvTS::FAIL_INVALID_OUTPUT;
|
||||
ts->printf( CvTS::LOG, "%f - too large bad matches part while test radiusMatch() function (2).\n",
|
||||
(float)badCount/(float)queryDescCount );
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CV_GpuBruteForceMatcherTest::dataTest(int dim)
|
||||
{
|
||||
GpuMat query, train;
|
||||
generateData(query, train, dim);
|
||||
|
||||
matchTest(query, train);
|
||||
knnMatchTest(query, train);
|
||||
radiusMatchTest(query, train);
|
||||
|
||||
dmatcher.clear();
|
||||
}
|
||||
|
||||
void CV_GpuBruteForceMatcherTest::run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
emptyDataTest();
|
||||
|
||||
dataTest(50);
|
||||
dataTest(64);
|
||||
dataTest(100);
|
||||
dataTest(128);
|
||||
dataTest(200);
|
||||
dataTest(256);
|
||||
dataTest(300);
|
||||
}
|
||||
catch(cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CV_GpuBruteForceMatcherTest CV_GpuBruteForceMatcher_test;
|
@ -1,415 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
using namespace std;
|
||||
|
||||
struct CV_GpuMulSpectrumsTest: CvTest
|
||||
{
|
||||
CV_GpuMulSpectrumsTest(): CvTest("GPU-MulSpectrumsTest", "mulSpectrums") {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
test(0);
|
||||
testConj(0);
|
||||
testScaled(0);
|
||||
testScaledConj(0);
|
||||
test(DFT_ROWS);
|
||||
testConj(DFT_ROWS);
|
||||
testScaled(DFT_ROWS);
|
||||
testScaledConj(DFT_ROWS);
|
||||
}
|
||||
catch (const Exception& e)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, e.what());
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void gen(int cols, int rows, Mat& mat)
|
||||
{
|
||||
RNG rng;
|
||||
mat.create(rows, cols, CV_32FC2);
|
||||
rng.fill(mat, RNG::UNIFORM, Scalar::all(0.f), Scalar::all(10.f));
|
||||
}
|
||||
|
||||
bool cmp(const Mat& gold, const Mat& mine, float max_err=1e-3f)
|
||||
{
|
||||
if (gold.size() != mine.size())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad sizes: gold: %d d%, mine: %d %d\n", gold.cols, gold.rows, mine.cols, mine.rows);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
if (gold.type() != mine.type())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad types: gold=%d, mine=%d\n", gold.type(), mine.type());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < gold.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < gold.cols * 2; ++j)
|
||||
{
|
||||
float gold_ = gold.at<float>(i, j);
|
||||
float mine_ = mine.at<float>(i, j);
|
||||
if (fabs(gold_ - mine_) > max_err)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad values at %d %d: gold=%f, mine=%f\n", j, i, gold_, mine_);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmpScaled(const Mat& gold, const Mat& mine, float scale, float max_err=1e-3f)
|
||||
{
|
||||
if (gold.size() != mine.size())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad sizes: gold: %d d%, mine: %d %d\n", gold.cols, gold.rows, mine.cols, mine.rows);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
if (gold.type() != mine.type())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad types: gold=%d, mine=%d\n", gold.type(), mine.type());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < gold.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < gold.cols * 2; ++j)
|
||||
{
|
||||
float gold_ = gold.at<float>(i, j) * scale;
|
||||
float mine_ = mine.at<float>(i, j);
|
||||
if (fabs(gold_ - mine_) > max_err)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad values at %d %d: gold=%f, mine=%f\n", j, i, gold_, mine_);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void test(int flags)
|
||||
{
|
||||
int cols = 1 + rand() % 100, rows = 1 + rand() % 1000;
|
||||
|
||||
Mat a, b;
|
||||
gen(cols, rows, a);
|
||||
gen(cols, rows, b);
|
||||
|
||||
Mat c_gold;
|
||||
mulSpectrums(a, b, c_gold, flags, false);
|
||||
|
||||
GpuMat d_c;
|
||||
mulSpectrums(GpuMat(a), GpuMat(b), d_c, flags, false);
|
||||
|
||||
if (!cmp(c_gold, Mat(d_c)))
|
||||
ts->printf(CvTS::CONSOLE, "test failed: cols=%d, rows=%d, flags=%d\n", cols, rows, flags);
|
||||
}
|
||||
|
||||
void testConj(int flags)
|
||||
{
|
||||
int cols = 1 + rand() % 100, rows = 1 + rand() % 1000;
|
||||
|
||||
Mat a, b;
|
||||
gen(cols, rows, a);
|
||||
gen(cols, rows, b);
|
||||
|
||||
Mat c_gold;
|
||||
mulSpectrums(a, b, c_gold, flags, true);
|
||||
|
||||
GpuMat d_c;
|
||||
mulSpectrums(GpuMat(a), GpuMat(b), d_c, flags, true);
|
||||
|
||||
if (!cmp(c_gold, Mat(d_c)))
|
||||
ts->printf(CvTS::CONSOLE, "testConj failed: cols=%d, rows=%d, flags=%d\n", cols, rows, flags);
|
||||
}
|
||||
|
||||
void testScaled(int flags)
|
||||
{
|
||||
int cols = 1 + rand() % 100, rows = 1 + rand() % 1000;
|
||||
|
||||
Mat a, b;
|
||||
gen(cols, rows, a);
|
||||
gen(cols, rows, b);
|
||||
float scale = 1.f / a.size().area();
|
||||
|
||||
Mat c_gold;
|
||||
mulSpectrums(a, b, c_gold, flags, false);
|
||||
|
||||
GpuMat d_c;
|
||||
mulAndScaleSpectrums(GpuMat(a), GpuMat(b), d_c, flags, scale, false);
|
||||
|
||||
if (!cmpScaled(c_gold, Mat(d_c), scale))
|
||||
ts->printf(CvTS::CONSOLE, "testScaled failed: cols=%d, rows=%d, flags=%d\n", cols, rows, flags);
|
||||
}
|
||||
|
||||
void testScaledConj(int flags)
|
||||
{
|
||||
int cols = 1 + rand() % 100, rows = 1 + rand() % 1000;
|
||||
|
||||
Mat a, b;
|
||||
gen(cols, rows, a);
|
||||
gen(cols, rows, b);
|
||||
float scale = 1.f / a.size().area();
|
||||
|
||||
Mat c_gold;
|
||||
mulSpectrums(a, b, c_gold, flags, true);
|
||||
|
||||
GpuMat d_c;
|
||||
mulAndScaleSpectrums(GpuMat(a), GpuMat(b), d_c, flags, scale, true);
|
||||
|
||||
if (!cmpScaled(c_gold, Mat(d_c), scale))
|
||||
ts->printf(CvTS::CONSOLE, "testScaledConj failed: cols=%d, rows=%d, flags=%D\n", cols, rows, flags);
|
||||
}
|
||||
} CV_GpuMulSpectrumsTest_inst;
|
||||
|
||||
|
||||
struct CV_GpuDftTest: CvTest
|
||||
{
|
||||
CV_GpuDftTest(): CvTest("GPU-DftTest", "dft") {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
srand(0);
|
||||
int cols = 2 + rand() % 100, rows = 2 + rand() % 100;
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
bool inplace = i != 0;
|
||||
testC2C("no flags", cols, rows, 0, inplace);
|
||||
testC2C("no flags 0 1", cols, rows + 1, 0, inplace);
|
||||
testC2C("no flags 1 0", cols, rows + 1, 0, inplace);
|
||||
testC2C("no flags 1 1", cols + 1, rows, 0, inplace);
|
||||
testC2C("DFT_INVERSE", cols, rows, DFT_INVERSE, inplace);
|
||||
testC2C("DFT_ROWS", cols, rows, DFT_ROWS, inplace);
|
||||
testC2C("single col", 1, rows, 0, inplace);
|
||||
testC2C("single row", cols, 1, 0, inplace);
|
||||
testC2C("single col inversed", 1, rows, DFT_INVERSE, inplace);
|
||||
testC2C("single row inversed", cols, 1, DFT_INVERSE, inplace);
|
||||
testC2C("single row DFT_ROWS", cols, 1, DFT_ROWS, inplace);
|
||||
testC2C("size 1 2", 1, 2, 0, inplace);
|
||||
testC2C("size 2 1", 2, 1, 0, inplace);
|
||||
}
|
||||
|
||||
testR2CThenC2R("sanity", cols, rows);
|
||||
testR2CThenC2R("sanity 0 1", cols, rows + 1);
|
||||
testR2CThenC2R("sanity 1 0", cols + 1, rows);
|
||||
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1);
|
||||
testR2CThenC2R("single col", 1, rows);
|
||||
testR2CThenC2R("single col 1", 1, rows + 1);
|
||||
testR2CThenC2R("single row", cols, 1);
|
||||
testR2CThenC2R("single row 1", cols + 1, 1);
|
||||
|
||||
testR2CThenC2R("sanity", cols, rows, true);
|
||||
testR2CThenC2R("sanity 0 1", cols, rows + 1, true);
|
||||
testR2CThenC2R("sanity 1 0", cols + 1, rows, true);
|
||||
testR2CThenC2R("sanity 1 1", cols + 1, rows + 1, true);
|
||||
testR2CThenC2R("single row", cols, 1, true);
|
||||
testR2CThenC2R("single row 1", cols + 1, 1, true);
|
||||
}
|
||||
catch (const Exception& e)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, e.what());
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void gen(int cols, int rows, int cn, Mat& mat)
|
||||
{
|
||||
RNG rng(1);
|
||||
mat.create(rows, cols, CV_MAKETYPE(CV_32F, cn));
|
||||
rng.fill(mat, RNG::UNIFORM, Scalar::all(0.f), Scalar::all(10.f));
|
||||
}
|
||||
|
||||
bool cmp(const Mat& gold, const Mat& mine, float max_err=1e-3f)
|
||||
{
|
||||
if (gold.size() != mine.size())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad sizes: gold: %d %d, mine: %d %d\n", gold.cols, gold.rows, mine.cols, mine.rows);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
if (gold.depth() != mine.depth())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad depth: gold=%d, mine=%d\n", gold.depth(), mine.depth());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
if (gold.channels() != mine.channels())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad channel count: gold=%d, mine=%d\n", gold.channels(), mine.channels());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < gold.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < gold.cols * gold.channels(); ++j)
|
||||
{
|
||||
float gold_ = gold.at<float>(i, j);
|
||||
float mine_ = mine.at<float>(i, j);
|
||||
if (fabs(gold_ - mine_) > max_err)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad values at %d %d: gold=%f, mine=%f\n", j / gold.channels(), i, gold_, mine_);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void testC2C(const std::string& hint, int cols, int rows, int flags, bool inplace=false)
|
||||
{
|
||||
Mat a;
|
||||
gen(cols, rows, 2, a);
|
||||
|
||||
Mat b_gold;
|
||||
dft(a, b_gold, flags);
|
||||
|
||||
GpuMat d_b;
|
||||
GpuMat d_b_data;
|
||||
if (inplace)
|
||||
{
|
||||
d_b_data.create(1, a.size().area(), CV_32FC2);
|
||||
d_b = GpuMat(a.rows, a.cols, CV_32FC2, d_b_data.ptr(), a.cols * d_b_data.elemSize());
|
||||
}
|
||||
|
||||
dft(GpuMat(a), d_b, Size(cols, rows), flags);
|
||||
|
||||
bool ok = true;
|
||||
if (ok && inplace && d_b.ptr() != d_b_data.ptr())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "unnecessary reallocation was done\n");
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
ok = false;
|
||||
}
|
||||
if (ok && d_b.depth() != CV_32F)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad depth: %d\n", d_b.depth());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
ok = false;
|
||||
}
|
||||
if (ok && d_b.channels() != 2)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad channel count: %d\n", d_b.channels());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
ok = false;
|
||||
}
|
||||
if (ok) ok = cmp(b_gold, Mat(d_b), rows * cols * 1e-4f);
|
||||
if (!ok)
|
||||
ts->printf(CvTS::CONSOLE, "testC2C failed: hint=%s, cols=%d, rows=%d, flags=%d, inplace=%d\n",
|
||||
hint.c_str(), cols, rows, flags, inplace);
|
||||
}
|
||||
|
||||
void testR2CThenC2R(const std::string& hint, int cols, int rows, bool inplace=false)
|
||||
{
|
||||
Mat a;
|
||||
gen(cols, rows, 1, a);
|
||||
|
||||
bool ok = true;
|
||||
|
||||
GpuMat d_b, d_c;
|
||||
GpuMat d_b_data, d_c_data;
|
||||
if (inplace)
|
||||
{
|
||||
if (a.cols == 1)
|
||||
{
|
||||
d_b_data.create(1, (a.rows / 2 + 1) * a.cols, CV_32FC2);
|
||||
d_b = GpuMat(a.rows / 2 + 1, a.cols, CV_32FC2, d_b_data.ptr(), a.cols * d_b_data.elemSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
d_b_data.create(1, a.rows * (a.cols / 2 + 1), CV_32FC2);
|
||||
d_b = GpuMat(a.rows, a.cols / 2 + 1, CV_32FC2, d_b_data.ptr(), (a.cols / 2 + 1) * d_b_data.elemSize());
|
||||
}
|
||||
d_c_data.create(1, a.size().area(), CV_32F);
|
||||
d_c = GpuMat(a.rows, a.cols, CV_32F, d_c_data.ptr(), a.cols * d_c_data.elemSize());
|
||||
}
|
||||
|
||||
dft(GpuMat(a), d_b, Size(cols, rows), 0);
|
||||
dft(d_b, d_c, Size(cols, rows), DFT_REAL_OUTPUT | DFT_SCALE);
|
||||
|
||||
if (ok && inplace && d_b.ptr() != d_b_data.ptr())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "unnecessary reallocation was done for b\n");
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
ok = false;
|
||||
}
|
||||
if (ok && inplace && d_c.ptr() != d_c_data.ptr())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "unnecessary reallocation was done for c\n");
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
ok = false;
|
||||
}
|
||||
if (ok && d_c.depth() != CV_32F)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad depth: %d\n", d_c.depth());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
ok = false;
|
||||
}
|
||||
if (ok && d_c.channels() != 1)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad channel count: %d\n", d_c.channels());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
ok = false;
|
||||
}
|
||||
if (ok) ok = cmp(a, Mat(d_c), rows * cols * 1e-5f);
|
||||
if (!ok)
|
||||
ts->printf(CvTS::CONSOLE, "testR2CThenC2R failed: hint=%s, cols=%d, rows=%d, inplace=%d\n",
|
||||
hint.c_str(), cols, rows, inplace);
|
||||
}
|
||||
} CV_GpuDftTest_inst;
|
@ -1,239 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
using namespace std;
|
||||
|
||||
const string FEATURES2D_DIR = "features2d";
|
||||
const string IMAGE_FILENAME = "aloe.png";
|
||||
const string VALID_FILE_NAME = "surf.xml.gz";
|
||||
|
||||
class CV_GPU_SURFTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GPU_SURFTest() :
|
||||
CvTest( "GPU-SURF", "SURF_GPU")
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
bool isSimilarKeypoints(const KeyPoint& p1, const KeyPoint& p2);
|
||||
void compareKeypointSets(const vector<KeyPoint>& validKeypoints, const vector<KeyPoint>& calcKeypoints,
|
||||
const Mat& validDescriptors, const Mat& calcDescriptors);
|
||||
|
||||
void emptyDataTest(SURF_GPU& fdetector);
|
||||
void regressionTest(SURF_GPU& fdetector);
|
||||
|
||||
virtual void run(int);
|
||||
};
|
||||
|
||||
void CV_GPU_SURFTest::emptyDataTest(SURF_GPU& fdetector)
|
||||
{
|
||||
GpuMat image;
|
||||
vector<KeyPoint> keypoints;
|
||||
vector<float> descriptors;
|
||||
try
|
||||
{
|
||||
fdetector(image, GpuMat(), keypoints, descriptors);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->printf( CvTS::LOG, "detect() on empty image must not generate exception (1).\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
}
|
||||
|
||||
if( !keypoints.empty() )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "detect() on empty image must return empty keypoints vector (1).\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
if( !descriptors.empty() )
|
||||
{
|
||||
ts->printf( CvTS::LOG, "detect() on empty image must return empty descriptors vector (1).\n" );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool CV_GPU_SURFTest::isSimilarKeypoints(const KeyPoint& p1, const KeyPoint& p2)
|
||||
{
|
||||
const float maxPtDif = 1.f;
|
||||
const float maxSizeDif = 1.f;
|
||||
const float maxAngleDif = 2.f;
|
||||
const float maxResponseDif = 0.1f;
|
||||
|
||||
float dist = (float)norm( p1.pt - p2.pt );
|
||||
return (dist < maxPtDif &&
|
||||
fabs(p1.size - p2.size) < maxSizeDif &&
|
||||
abs(p1.angle - p2.angle) < maxAngleDif &&
|
||||
abs(p1.response - p2.response) < maxResponseDif &&
|
||||
p1.octave == p2.octave &&
|
||||
p1.class_id == p2.class_id );
|
||||
}
|
||||
|
||||
void CV_GPU_SURFTest::compareKeypointSets(const vector<KeyPoint>& validKeypoints, const vector<KeyPoint>& calcKeypoints,
|
||||
const Mat& validDescriptors, const Mat& calcDescriptors)
|
||||
{
|
||||
if (validKeypoints.size() != calcKeypoints.size())
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Keypoints sizes doesn't equal (validCount = %d, calcCount = %d).\n",
|
||||
validKeypoints.size(), calcKeypoints.size());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
if (validDescriptors.size() != calcDescriptors.size())
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Descriptors sizes doesn't equal.\n");
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
for (size_t v = 0; v < validKeypoints.size(); v++)
|
||||
{
|
||||
int nearestIdx = -1;
|
||||
float minDist = std::numeric_limits<float>::max();
|
||||
|
||||
for (size_t c = 0; c < calcKeypoints.size(); c++)
|
||||
{
|
||||
float curDist = (float)norm(calcKeypoints[c].pt - validKeypoints[v].pt);
|
||||
if (curDist < minDist)
|
||||
{
|
||||
minDist = curDist;
|
||||
nearestIdx = c;
|
||||
}
|
||||
}
|
||||
|
||||
assert(minDist >= 0);
|
||||
if (!isSimilarKeypoints(validKeypoints[v], calcKeypoints[nearestIdx]))
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Bad keypoints accuracy.\n");
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
|
||||
if (norm(validDescriptors.row(v), calcDescriptors.row(nearestIdx), NORM_L2) > 1.5f)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Bad descriptors accuracy.\n");
|
||||
ts->set_failed_test_info( CvTS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CV_GPU_SURFTest::regressionTest(SURF_GPU& fdetector)
|
||||
{
|
||||
string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;
|
||||
string resFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + VALID_FILE_NAME;
|
||||
|
||||
// Read the test image.
|
||||
GpuMat image(imread(imgFilename, 0));
|
||||
if (image.empty())
|
||||
{
|
||||
ts->printf( CvTS::LOG, "Image %s can not be read.\n", imgFilename.c_str() );
|
||||
ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
FileStorage fs(resFilename, FileStorage::READ);
|
||||
|
||||
// Compute keypoints.
|
||||
GpuMat mask(image.size(), CV_8UC1, Scalar::all(1));
|
||||
mask(Range(0, image.rows / 2), Range(0, image.cols / 2)).setTo(Scalar::all(0));
|
||||
vector<KeyPoint> calcKeypoints;
|
||||
GpuMat calcDespcriptors;
|
||||
fdetector(image, mask, calcKeypoints, calcDespcriptors);
|
||||
|
||||
if (fs.isOpened()) // Compare computed and valid keypoints.
|
||||
{
|
||||
// Read validation keypoints set.
|
||||
vector<KeyPoint> validKeypoints;
|
||||
Mat validDespcriptors;
|
||||
read(fs["keypoints"], validKeypoints);
|
||||
read(fs["descriptors"], validDespcriptors);
|
||||
if (validKeypoints.empty() || validDespcriptors.empty())
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Validation file can not be read.\n");
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
compareKeypointSets(validKeypoints, calcKeypoints, validDespcriptors, calcDespcriptors);
|
||||
}
|
||||
else // Write detector parameters and computed keypoints as validation data.
|
||||
{
|
||||
fs.open(resFilename, FileStorage::WRITE);
|
||||
if (!fs.isOpened())
|
||||
{
|
||||
ts->printf(CvTS::LOG, "File %s can not be opened to write.\n", resFilename.c_str());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
write(fs, "keypoints", calcKeypoints);
|
||||
write(fs, "descriptors", (Mat)calcDespcriptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CV_GPU_SURFTest::run( int /*start_from*/ )
|
||||
{
|
||||
try
|
||||
{
|
||||
SURF_GPU fdetector;
|
||||
|
||||
emptyDataTest(fdetector);
|
||||
regressionTest(fdetector);
|
||||
}
|
||||
catch(cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CV_GPU_SURFTest CV_GPU_SURF_test;
|
@ -1,382 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include "gputest.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
using namespace gpu;
|
||||
|
||||
class CV_GpuNppFilterTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GpuNppFilterTest(const char* test_name, const char* test_funcs) : CvTest(test_name, test_funcs) {}
|
||||
virtual ~CV_GpuNppFilterTest() {}
|
||||
|
||||
protected:
|
||||
void run(int);
|
||||
virtual int test(const Mat& img) = 0;
|
||||
|
||||
int test8UC1(const Mat& img)
|
||||
{
|
||||
cv::Mat img_C1;
|
||||
cvtColor(img, img_C1, CV_BGR2GRAY);
|
||||
return test(img_C1);
|
||||
}
|
||||
|
||||
int test8UC4(const Mat& img)
|
||||
{
|
||||
cv::Mat img_C4;
|
||||
cvtColor(img, img_C4, CV_BGR2BGRA);
|
||||
return test(img_C4);
|
||||
}
|
||||
|
||||
int CheckNorm(const Mat& m1, const Mat& m2, const Size& ksize)
|
||||
{
|
||||
Rect roi = Rect(ksize.width, ksize.height, m1.cols - 2 * ksize.width, m1.rows - 2 * ksize.height);
|
||||
Mat m1ROI = m1(roi);
|
||||
Mat m2ROI = m2(roi);
|
||||
|
||||
double res = norm(m1ROI, m2ROI, NORM_INF);
|
||||
|
||||
// Max difference (2.0) in GaussianBlur
|
||||
if (res <= 2)
|
||||
return CvTS::OK;
|
||||
|
||||
ts->printf(CvTS::LOG, "Norm: %f\n", res);
|
||||
return CvTS::FAIL_GENERIC;
|
||||
}
|
||||
};
|
||||
|
||||
void CV_GpuNppFilterTest::run( int )
|
||||
{
|
||||
cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-L.png");
|
||||
|
||||
if (img.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//run tests
|
||||
int testResult = CvTS::OK;
|
||||
|
||||
if (test8UC1(img) != CvTS::OK)
|
||||
testResult = CvTS::FAIL_GENERIC;
|
||||
|
||||
if (test8UC4(img) != CvTS::OK)
|
||||
testResult = CvTS::FAIL_GENERIC;
|
||||
|
||||
ts->set_failed_test_info(testResult);
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// blur
|
||||
struct CV_GpuNppImageBlurTest : public CV_GpuNppFilterTest
|
||||
{
|
||||
CV_GpuNppImageBlurTest() : CV_GpuNppFilterTest( "GPU-NppImageBlur", "blur" ) {}
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
int ksizes[] = {3, 5, 7};
|
||||
int ksizes_num = sizeof(ksizes) / sizeof(int);
|
||||
|
||||
int test_res = CvTS::OK;
|
||||
|
||||
for (int i = 0; i < ksizes_num; ++i)
|
||||
{
|
||||
for (int j = 0; j < ksizes_num; ++j)
|
||||
{
|
||||
Size ksize(ksizes[i], ksizes[j]);
|
||||
|
||||
ts->printf(CvTS::LOG, "\nksize = (%dx%d)\n", ksizes[i], ksizes[j]);
|
||||
|
||||
Mat cpudst;
|
||||
cv::blur(img, cpudst, ksize);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpudst;
|
||||
cv::gpu::blur(gpu1, gpudst, ksize);
|
||||
|
||||
if (CheckNorm(cpudst, gpudst, ksize) != CvTS::OK)
|
||||
test_res = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
}
|
||||
|
||||
return test_res;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Sobel
|
||||
struct CV_GpuNppImageSobelTest : public CV_GpuNppFilterTest
|
||||
{
|
||||
CV_GpuNppImageSobelTest() : CV_GpuNppFilterTest( "GPU-NppImageSobel", "Sobel" ) {}
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
int ksizes[] = {3, 5, 7};
|
||||
int ksizes_num = sizeof(ksizes) / sizeof(int);
|
||||
|
||||
int dx = 1, dy = 0;
|
||||
|
||||
int test_res = CvTS::OK;
|
||||
|
||||
for (int i = 0; i < ksizes_num; ++i)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nksize = %d\n", ksizes[i]);
|
||||
|
||||
Mat cpudst;
|
||||
cv::Sobel(img, cpudst, -1, dx, dy, ksizes[i]);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpudst;
|
||||
cv::gpu::Sobel(gpu1, gpudst, -1, dx, dy, ksizes[i]);
|
||||
|
||||
if (CheckNorm(cpudst, gpudst, Size(ksizes[i], ksizes[i])) != CvTS::OK)
|
||||
test_res = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
return test_res;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Scharr
|
||||
struct CV_GpuNppImageScharrTest : public CV_GpuNppFilterTest
|
||||
{
|
||||
CV_GpuNppImageScharrTest() : CV_GpuNppFilterTest( "GPU-NppImageScharr", "Scharr" ) {}
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
int dx = 1, dy = 0;
|
||||
|
||||
Mat cpudst;
|
||||
cv::Scharr(img, cpudst, -1, dx, dy);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpudst;
|
||||
cv::gpu::Scharr(gpu1, gpudst, -1, dx, dy);
|
||||
|
||||
return CheckNorm(cpudst, gpudst, Size(3, 3));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// GaussianBlur
|
||||
struct CV_GpuNppImageGaussianBlurTest : public CV_GpuNppFilterTest
|
||||
{
|
||||
CV_GpuNppImageGaussianBlurTest() : CV_GpuNppFilterTest( "GPU-NppImageGaussianBlur", "GaussianBlur" ) {}
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
int ksizes[] = {3, 5, 7};
|
||||
int ksizes_num = sizeof(ksizes) / sizeof(int);
|
||||
|
||||
int test_res = CvTS::OK;
|
||||
|
||||
const double sigma1 = 3.0;
|
||||
|
||||
for (int i = 0; i < ksizes_num; ++i)
|
||||
{
|
||||
for (int j = 0; j < ksizes_num; ++j)
|
||||
{
|
||||
cv::Size ksize(ksizes[i], ksizes[j]);
|
||||
|
||||
ts->printf(CvTS::LOG, "ksize = (%dx%d)\t\n", ksizes[i], ksizes[j]);
|
||||
|
||||
Mat cpudst;
|
||||
cv::GaussianBlur(img, cpudst, ksize, sigma1);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpudst;
|
||||
cv::gpu::GaussianBlur(gpu1, gpudst, ksize, sigma1);
|
||||
|
||||
if (CheckNorm(cpudst, gpudst, ksize) != CvTS::OK)
|
||||
test_res = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
}
|
||||
|
||||
return test_res;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Laplacian
|
||||
struct CV_GpuNppImageLaplacianTest : public CV_GpuNppFilterTest
|
||||
{
|
||||
CV_GpuNppImageLaplacianTest() : CV_GpuNppFilterTest( "GPU-NppImageLaplacian", "Laplacian" ) {}
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
int ksizes[] = {1, 3};
|
||||
int ksizes_num = sizeof(ksizes) / sizeof(int);
|
||||
|
||||
int test_res = CvTS::OK;
|
||||
|
||||
for (int i = 0; i < ksizes_num; ++i)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nksize = %d\n", ksizes[i]);
|
||||
|
||||
Mat cpudst;
|
||||
cv::Laplacian(img, cpudst, -1, ksizes[i]);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpudst;
|
||||
cv::gpu::Laplacian(gpu1, gpudst, -1, ksizes[i]);
|
||||
|
||||
if (CheckNorm(cpudst, gpudst, Size(3, 3)) != CvTS::OK)
|
||||
test_res = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
return test_res;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Erode
|
||||
class CV_GpuErodeTest : public CV_GpuNppFilterTest
|
||||
{
|
||||
public:
|
||||
CV_GpuErodeTest() : CV_GpuNppFilterTest( "GPU-NppErode", "erode" ) {}
|
||||
|
||||
protected:
|
||||
virtual int test(const Mat& img)
|
||||
{
|
||||
Mat kernel(Mat::ones(3, 3, CV_8U));
|
||||
|
||||
cv::Mat cpuRes;
|
||||
cv::erode(img, cpuRes, kernel);
|
||||
|
||||
GpuMat gpuRes;
|
||||
cv::gpu::erode(GpuMat(img), gpuRes, kernel);
|
||||
|
||||
return CheckNorm(cpuRes, gpuRes, Size(3, 3));
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Dilate
|
||||
class CV_GpuDilateTest : public CV_GpuNppFilterTest
|
||||
{
|
||||
public:
|
||||
CV_GpuDilateTest() : CV_GpuNppFilterTest( "GPU-NppDilate", "dilate" ) {}
|
||||
|
||||
protected:
|
||||
virtual int test(const Mat& img)
|
||||
{
|
||||
Mat kernel(Mat::ones(3, 3, CV_8U));
|
||||
|
||||
cv::Mat cpuRes;
|
||||
cv::dilate(img, cpuRes, kernel);
|
||||
|
||||
GpuMat gpuRes;
|
||||
cv::gpu::dilate(GpuMat(img), gpuRes, kernel);
|
||||
|
||||
return CheckNorm(cpuRes, gpuRes, Size(3, 3));
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// MorphologyEx
|
||||
class CV_GpuMorphExTest : public CV_GpuNppFilterTest
|
||||
{
|
||||
public:
|
||||
CV_GpuMorphExTest() : CV_GpuNppFilterTest( "GPU-NppMorphologyEx", "morphologyEx" ) {}
|
||||
|
||||
protected:
|
||||
virtual int test(const Mat& img)
|
||||
{
|
||||
static int ops[] = { MORPH_OPEN, CV_MOP_CLOSE, CV_MOP_GRADIENT, CV_MOP_TOPHAT, CV_MOP_BLACKHAT};
|
||||
const char *names[] = { "MORPH_OPEN", "CV_MOP_CLOSE", "CV_MOP_GRADIENT", "CV_MOP_TOPHAT", "CV_MOP_BLACKHAT"};
|
||||
int num = sizeof(ops)/sizeof(ops[0]);
|
||||
|
||||
GpuMat kernel(Mat::ones(3, 3, CV_8U));
|
||||
|
||||
int res = CvTS::OK;
|
||||
|
||||
for(int i = 0; i < num; ++i)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Tesing %s\n", names[i]);
|
||||
|
||||
cv::Mat cpuRes;
|
||||
cv::morphologyEx(img, cpuRes, ops[i], kernel);
|
||||
|
||||
GpuMat gpuRes;
|
||||
cv::gpu::morphologyEx(GpuMat(img), gpuRes, ops[i], kernel);
|
||||
|
||||
if (CvTS::OK != CheckNorm(cpuRes, gpuRes, Size(4, 4)))
|
||||
res = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_GpuNppImageBlurTest CV_GpuNppImageBlur_test;
|
||||
CV_GpuNppImageSobelTest CV_GpuNppImageSobel_test;
|
||||
CV_GpuNppImageScharrTest CV_GpuNppImageScharr_test;
|
||||
CV_GpuNppImageGaussianBlurTest CV_GpuNppImageGaussianBlur_test;
|
||||
CV_GpuNppImageLaplacianTest CV_GpuNppImageLaplacian_test;
|
||||
CV_GpuErodeTest CV_GpuErode_test;
|
||||
CV_GpuDilateTest CV_GpuDilate_test;
|
||||
CV_GpuMorphExTest CV_GpuMorphEx_test;
|
@ -1,95 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GPU_TEST_H_
|
||||
#define _GPU_TEST_H_
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#include <windows.h>
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#include <opencv2/gpu/gpu.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
#include <opencv2/calib3d/calib3d.hpp>
|
||||
#include "cxts.h"
|
||||
|
||||
/****************************************************************************************/
|
||||
/* Warnings Disabling */
|
||||
/****************************************************************************************/
|
||||
#if _MSC_VER > 1000
|
||||
#pragma warning(disable : 4514) /* unreferenced inline function has been */
|
||||
/* removed */
|
||||
#pragma warning(disable : 4127) /* conditional expression is constant */
|
||||
/* for no warnings in _ASSERT */
|
||||
#pragma warning(disable : 4996) /* deprecated function */
|
||||
#endif
|
||||
|
||||
|
||||
static inline bool check_and_treat_gpu_exception(const cv::Exception& e, CvTS* ts)
|
||||
{
|
||||
switch (e.code)
|
||||
{
|
||||
case CV_GpuNotSupported:
|
||||
ts->printf(CvTS::LOG, "\nGpu not supported by the library");
|
||||
break;
|
||||
|
||||
case CV_GpuApiCallError:
|
||||
ts->printf(CvTS::LOG, "\nGPU Error: %s", e.what());
|
||||
break;
|
||||
|
||||
case CV_GpuNppCallError:
|
||||
ts->printf(CvTS::LOG, "\nNPP Error: %s", e.what());
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
@ -1,57 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
|
||||
CvTS test_system("gpu");
|
||||
|
||||
//const char* blacklist[] =
|
||||
//{
|
||||
// "GPU-NVidia",
|
||||
// 0
|
||||
//};
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
return test_system.run( argc, argv );
|
||||
}
|
||||
|
||||
/* End of file. */
|
@ -1,332 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//#define DUMP
|
||||
|
||||
#define CHECK(pred, err) if (!(pred)) { \
|
||||
ts->printf(CvTS::CONSOLE, "Fail: \"%s\" at line: %d\n", #pred, __LINE__); \
|
||||
ts->set_failed_test_info(err); \
|
||||
return; }
|
||||
|
||||
struct CV_GpuHogDetectTestRunner: cv::gpu::HOGDescriptor
|
||||
{
|
||||
CV_GpuHogDetectTestRunner(CvTS* ts_): ts(ts_) {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
cv::Mat img_rgb = cv::imread(std::string(ts->get_data_path()) + "hog/road.png");
|
||||
CHECK(!img_rgb.empty(), CvTS::FAIL_MISSING_TEST_DATA);
|
||||
|
||||
#ifdef DUMP
|
||||
f.open((std::string(ts->get_data_path()) + "hog/expected_output.bin").c_str(), std::ios_base::binary);
|
||||
CHECK(f.is_open(), CvTS::FAIL_GENERIC);
|
||||
#else
|
||||
f.open((std::string(ts->get_data_path()) + "hog/expected_output.bin").c_str(), std::ios_base::binary);
|
||||
CHECK(f.is_open(), CvTS::FAIL_MISSING_TEST_DATA);
|
||||
#endif
|
||||
|
||||
// Test on color image
|
||||
cv::Mat img;
|
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||
test(img);
|
||||
|
||||
// Test on gray image
|
||||
cv::cvtColor(img_rgb, img, CV_BGR2GRAY);
|
||||
test(img);
|
||||
|
||||
f.close();
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
f.close();
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DUMP
|
||||
void dump(const cv::Mat& block_hists, const std::vector<cv::Point>& locations)
|
||||
{
|
||||
f.write((char*)&block_hists.rows, sizeof(block_hists.rows));
|
||||
f.write((char*)&block_hists.cols, sizeof(block_hists.cols));
|
||||
for (int i = 0; i < block_hists.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < block_hists.cols; ++j)
|
||||
{
|
||||
float val = block_hists.at<float>(i, j);
|
||||
f.write((char*)&val, sizeof(val));
|
||||
}
|
||||
}
|
||||
size_t nlocations = locations.size();
|
||||
f.write((char*)&nlocations, sizeof(nlocations));
|
||||
for (size_t i = 0; i < locations.size(); ++i)
|
||||
f.write((char*)&locations[i], sizeof(locations[i]));
|
||||
}
|
||||
#else
|
||||
void compare(const cv::Mat& block_hists, const std::vector<cv::Point>& locations)
|
||||
{
|
||||
int rows, cols;
|
||||
size_t nlocations;
|
||||
|
||||
f.read((char*)&rows, sizeof(rows));
|
||||
f.read((char*)&cols, sizeof(cols));
|
||||
CHECK(rows == block_hists.rows, CvTS::FAIL_INVALID_OUTPUT);
|
||||
CHECK(cols == block_hists.cols, CvTS::FAIL_INVALID_OUTPUT);
|
||||
for (int i = 0; i < block_hists.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < block_hists.cols; ++j)
|
||||
{
|
||||
float val;
|
||||
f.read((char*)&val, sizeof(val));
|
||||
CHECK(fabs(val - block_hists.at<float>(i, j)) < 1e-3f, CvTS::FAIL_INVALID_OUTPUT);
|
||||
}
|
||||
}
|
||||
f.read((char*)&nlocations, sizeof(nlocations));
|
||||
CHECK(nlocations == locations.size(), CvTS::FAIL_INVALID_OUTPUT);
|
||||
for (size_t i = 0; i < nlocations; ++i)
|
||||
{
|
||||
cv::Point location;
|
||||
f.read((char*)&location, sizeof(location));
|
||||
CHECK(location == locations[i], CvTS::FAIL_INVALID_OUTPUT);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void test(const cv::Mat& img)
|
||||
{
|
||||
cv::gpu::GpuMat d_img(img);
|
||||
|
||||
gamma_correction = false;
|
||||
setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
|
||||
//cpu detector may be updated soon
|
||||
//hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());
|
||||
|
||||
std::vector<cv::Point> locations;
|
||||
|
||||
// Test detect
|
||||
detect(d_img, locations, 0);
|
||||
|
||||
#ifdef DUMP
|
||||
dump(block_hists, locations);
|
||||
#else
|
||||
compare(block_hists, locations);
|
||||
#endif
|
||||
|
||||
// Test detect on smaller image
|
||||
cv::Mat img2;
|
||||
cv::resize(img, img2, cv::Size(img.cols / 2, img.rows / 2));
|
||||
detect(cv::gpu::GpuMat(img2), locations, 0);
|
||||
|
||||
#ifdef DUMP
|
||||
dump(block_hists, locations);
|
||||
#else
|
||||
compare(block_hists, locations);
|
||||
#endif
|
||||
|
||||
// Test detect on greater image
|
||||
cv::resize(img, img2, cv::Size(img.cols * 2, img.rows * 2));
|
||||
detect(cv::gpu::GpuMat(img2), locations, 0);
|
||||
|
||||
#ifdef DUMP
|
||||
dump(block_hists, locations);
|
||||
#else
|
||||
compare(block_hists, locations);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DUMP
|
||||
std::ofstream f;
|
||||
#else
|
||||
std::ifstream f;
|
||||
#endif
|
||||
|
||||
CvTS* ts;
|
||||
};
|
||||
|
||||
|
||||
struct CV_GpuHogDetectTest: CvTest
|
||||
{
|
||||
CV_GpuHogDetectTest(): CvTest("GPU-HogDetectTest", "HOGDescriptor::detect") {}
|
||||
|
||||
void run(int i)
|
||||
{
|
||||
CV_GpuHogDetectTestRunner runner(ts);
|
||||
runner.run(i);
|
||||
}
|
||||
} CV_GpuHogDetectTest_inst;
|
||||
|
||||
|
||||
struct CV_GpuHogGetDescriptorsTestRunner: cv::gpu::HOGDescriptor
|
||||
{
|
||||
CV_GpuHogGetDescriptorsTestRunner(CvTS* ts_): HOGDescriptor(cv::Size(64, 128)), ts(ts_) {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Load image (e.g. train data, composed from windows)
|
||||
cv::Mat img_rgb = cv::imread(std::string(ts->get_data_path()) + "hog/train_data.png");
|
||||
CHECK(!img_rgb.empty(), CvTS::FAIL_MISSING_TEST_DATA);
|
||||
|
||||
// Convert to C4
|
||||
cv::Mat img;
|
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||
cv::gpu::GpuMat d_img(img);
|
||||
|
||||
|
||||
// Convert train images into feature vectors (train table)
|
||||
cv::gpu::GpuMat descriptors, descriptors_by_cols;
|
||||
getDescriptors(d_img, win_size, descriptors, DESCR_FORMAT_ROW_BY_ROW);
|
||||
getDescriptors(d_img, win_size, descriptors_by_cols, DESCR_FORMAT_COL_BY_COL);
|
||||
|
||||
// Check size of the result train table
|
||||
wins_per_img_x = 3;
|
||||
wins_per_img_y = 2;
|
||||
blocks_per_win_x = 7;
|
||||
blocks_per_win_y = 15;
|
||||
block_hist_size = 36;
|
||||
cv::Size descr_size_expected = cv::Size(blocks_per_win_x * blocks_per_win_y * block_hist_size,
|
||||
wins_per_img_x * wins_per_img_y);
|
||||
CHECK(descriptors.size() == descr_size_expected, CvTS::FAIL_INVALID_OUTPUT);
|
||||
|
||||
// Check both formats of output descriptors are handled correctly
|
||||
cv::Mat dr(descriptors);
|
||||
cv::Mat dc(descriptors_by_cols);
|
||||
for (int i = 0; i < wins_per_img_x * wins_per_img_y; ++i)
|
||||
{
|
||||
const float* l = dr.rowRange(i, i + 1).ptr<float>();
|
||||
const float* r = dc.rowRange(i, i + 1).ptr<float>();
|
||||
for (int y = 0; y < blocks_per_win_y; ++y)
|
||||
for (int x = 0; x < blocks_per_win_x; ++x)
|
||||
for (int k = 0; k < block_hist_size; ++k)
|
||||
CHECK(l[(y * blocks_per_win_x + x) * block_hist_size + k] ==
|
||||
r[(x * blocks_per_win_y + y) * block_hist_size + k], CvTS::FAIL_INVALID_OUTPUT);
|
||||
}
|
||||
|
||||
/* Now we want to extract the same feature vectors, but from single images. NOTE: results will
|
||||
be defferent, due to border values interpolation. Using of many small images is slower, however we
|
||||
wont't call getDescriptors and will use computeBlockHistograms instead of. computeBlockHistograms
|
||||
works good, it can be checked in the gpu_hog sample */
|
||||
|
||||
img_rgb = cv::imread(std::string(ts->get_data_path()) + "hog/positive1.png");
|
||||
CHECK(!img_rgb.empty(), CvTS::FAIL_MISSING_TEST_DATA);
|
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||
// Everything is fine with interpolation for left top subimage
|
||||
CHECK(cv::norm(block_hists, descriptors.rowRange(0, 1)) == 0.f, CvTS::FAIL_INVALID_OUTPUT);
|
||||
|
||||
img_rgb = cv::imread(std::string(ts->get_data_path()) + "hog/positive2.png");
|
||||
CHECK(!img_rgb.empty(), CvTS::FAIL_MISSING_TEST_DATA);
|
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||
compare_inner_parts(block_hists, descriptors.rowRange(1, 2));
|
||||
|
||||
img_rgb = cv::imread(std::string(ts->get_data_path()) + "hog/negative1.png");
|
||||
CHECK(!img_rgb.empty(), CvTS::FAIL_MISSING_TEST_DATA);
|
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||
compare_inner_parts(block_hists, descriptors.rowRange(2, 3));
|
||||
|
||||
img_rgb = cv::imread(std::string(ts->get_data_path()) + "hog/negative2.png");
|
||||
CHECK(!img_rgb.empty(), CvTS::FAIL_MISSING_TEST_DATA);
|
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||
compare_inner_parts(block_hists, descriptors.rowRange(3, 4));
|
||||
|
||||
img_rgb = cv::imread(std::string(ts->get_data_path()) + "hog/positive3.png");
|
||||
CHECK(!img_rgb.empty(), CvTS::FAIL_MISSING_TEST_DATA);
|
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||
compare_inner_parts(block_hists, descriptors.rowRange(4, 5));
|
||||
|
||||
img_rgb = cv::imread(std::string(ts->get_data_path()) + "hog/negative3.png");
|
||||
CHECK(!img_rgb.empty(), CvTS::FAIL_MISSING_TEST_DATA);
|
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||
computeBlockHistograms(cv::gpu::GpuMat(img));
|
||||
compare_inner_parts(block_hists, descriptors.rowRange(5, 6));
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Does not compare border value, as interpolation leads to delta
|
||||
void compare_inner_parts(cv::Mat d1, cv::Mat d2)
|
||||
{
|
||||
for (int i = 1; i < blocks_per_win_y - 1; ++i)
|
||||
for (int j = 1; j < blocks_per_win_x - 1; ++j)
|
||||
for (int k = 0; k < block_hist_size; ++k)
|
||||
{
|
||||
float a = d1.at<float>(0, (i * blocks_per_win_x + j) * block_hist_size);
|
||||
float b = d2.at<float>(0, (i * blocks_per_win_x + j) * block_hist_size);
|
||||
CHECK(a == b, CvTS::FAIL_INVALID_OUTPUT)
|
||||
}
|
||||
}
|
||||
|
||||
int wins_per_img_x;
|
||||
int wins_per_img_y;
|
||||
int blocks_per_win_x;
|
||||
int blocks_per_win_y;
|
||||
int block_hist_size;
|
||||
|
||||
CvTS* ts;
|
||||
};
|
||||
|
||||
|
||||
struct CV_GpuHogGetDescriptorsTest: CvTest
|
||||
{
|
||||
CV_GpuHogGetDescriptorsTest(): CvTest("GPU-HogGetDescriptorsTest", "HOGDescriptor::getDescriptors") {}
|
||||
|
||||
void run(int i)
|
||||
{
|
||||
CV_GpuHogGetDescriptorsTestRunner runner(ts);
|
||||
runner.run(i);
|
||||
}
|
||||
} CV_GpuHogGetDescriptorsTest_inst;
|
@ -1,987 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include "gputest.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
using namespace gpu;
|
||||
|
||||
class CV_GpuImageProcTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GpuImageProcTest(const char* test_name, const char* test_funcs) : CvTest(test_name, test_funcs) {}
|
||||
virtual ~CV_GpuImageProcTest() {}
|
||||
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
int test8UC1 (const Mat& img);
|
||||
int test8UC4 (const Mat& img);
|
||||
int test32SC1(const Mat& img);
|
||||
int test32FC1(const Mat& img);
|
||||
|
||||
virtual int test(const Mat& img) = 0;
|
||||
|
||||
int CheckNorm(const Mat& m1, const Mat& m2);
|
||||
|
||||
// Checks whether two images are similar enough using normalized
|
||||
// cross-correlation as an error measure
|
||||
int CheckSimilarity(const Mat& m1, const Mat& m2, float max_err=1e-3f);
|
||||
};
|
||||
|
||||
|
||||
int CV_GpuImageProcTest::test8UC1(const Mat& img)
|
||||
{
|
||||
cv::Mat img_C1;
|
||||
cvtColor(img, img_C1, CV_BGR2GRAY);
|
||||
|
||||
return test(img_C1);
|
||||
}
|
||||
|
||||
int CV_GpuImageProcTest::test8UC4(const Mat& img)
|
||||
{
|
||||
cv::Mat img_C4;
|
||||
cvtColor(img, img_C4, CV_BGR2BGRA);
|
||||
|
||||
return test(img_C4);
|
||||
}
|
||||
|
||||
int CV_GpuImageProcTest::test32SC1(const Mat& img)
|
||||
{
|
||||
cv::Mat img_C1;
|
||||
cvtColor(img, img_C1, CV_BGR2GRAY);
|
||||
img_C1.convertTo(img_C1, CV_32S);
|
||||
|
||||
return test(img_C1);
|
||||
}
|
||||
|
||||
int CV_GpuImageProcTest::test32FC1(const Mat& img)
|
||||
{
|
||||
cv::Mat temp, img_C1;
|
||||
img.convertTo(temp, CV_32F, 1.f / 255.f);
|
||||
cvtColor(temp, img_C1, CV_BGR2GRAY);
|
||||
|
||||
return test(img_C1);
|
||||
}
|
||||
|
||||
int CV_GpuImageProcTest::CheckNorm(const Mat& m1, const Mat& m2)
|
||||
{
|
||||
double ret = norm(m1, m2, NORM_INF);
|
||||
|
||||
if (ret < std::numeric_limits<double>::epsilon())
|
||||
{
|
||||
return CvTS::OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Norm: %f\n", ret);
|
||||
return CvTS::FAIL_GENERIC;
|
||||
}
|
||||
}
|
||||
|
||||
int CV_GpuImageProcTest::CheckSimilarity(const Mat& m1, const Mat& m2, float max_err)
|
||||
{
|
||||
Mat diff;
|
||||
cv::matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED);
|
||||
|
||||
float err = abs(diff.at<float>(0, 0) - 1.f);
|
||||
|
||||
if (err > max_err)
|
||||
return CvTS::FAIL_INVALID_OUTPUT;
|
||||
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
void CV_GpuImageProcTest::run( int )
|
||||
{
|
||||
//load image
|
||||
cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-L.png");
|
||||
|
||||
if (img.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
int testResult = CvTS::OK;
|
||||
try
|
||||
{
|
||||
//run tests
|
||||
ts->printf(CvTS::LOG, "\n========Start test 8UC1========\n");
|
||||
if (test8UC1(img) == CvTS::OK)
|
||||
ts->printf(CvTS::LOG, "SUCCESS\n");
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "FAIL\n");
|
||||
testResult = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
ts->printf(CvTS::LOG, "\n========Start test 8UC4========\n");
|
||||
if (test8UC4(img) == CvTS::OK)
|
||||
ts->printf(CvTS::LOG, "SUCCESS\n");
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "FAIL\n");
|
||||
testResult = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
ts->printf(CvTS::LOG, "\n========Start test 32SC1========\n");
|
||||
if (test32SC1(img) == CvTS::OK)
|
||||
ts->printf(CvTS::LOG, "SUCCESS\n");
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "FAIL\n");
|
||||
testResult = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
ts->printf(CvTS::LOG, "\n========Start test 32FC1========\n");
|
||||
if (test32FC1(img) == CvTS::OK)
|
||||
ts->printf(CvTS::LOG, "SUCCESS\n");
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "FAIL\n");
|
||||
testResult = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(testResult);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// threshold
|
||||
struct CV_GpuImageThresholdTest : public CV_GpuImageProcTest
|
||||
{
|
||||
public:
|
||||
CV_GpuImageThresholdTest() : CV_GpuImageProcTest( "GPU-ImageThreshold", "threshold" ) {}
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
if (img.type() != CV_8UC1 && img.type() != CV_32FC1)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nUnsupported type\n");
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
const double maxVal = img.type() == CV_8UC1 ? 255 : 1.0;
|
||||
|
||||
cv::RNG rng(*ts->get_rng());
|
||||
|
||||
int res = CvTS::OK;
|
||||
|
||||
for (int type = THRESH_BINARY; type <= THRESH_TOZERO_INV; ++type)
|
||||
{
|
||||
const double thresh = rng.uniform(0.0, maxVal);
|
||||
|
||||
cv::Mat cpuRes;
|
||||
cv::threshold(img, cpuRes, thresh, maxVal, type);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpuRes;
|
||||
cv::gpu::threshold(gpu1, gpuRes, thresh, maxVal, type);
|
||||
|
||||
if (CheckNorm(cpuRes, gpuRes) != CvTS::OK)
|
||||
res = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// resize
|
||||
struct CV_GpuNppImageResizeTest : public CV_GpuImageProcTest
|
||||
{
|
||||
CV_GpuNppImageResizeTest() : CV_GpuImageProcTest( "GPU-NppImageResize", "resize" ) {}
|
||||
int test(const Mat& img)
|
||||
{
|
||||
if (img.type() != CV_8UC1 && img.type() != CV_8UC4)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Unsupported type\n");
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
int interpolations[] = {INTER_NEAREST, INTER_LINEAR, /*INTER_CUBIC,*/ /*INTER_LANCZOS4*/};
|
||||
const char* interpolations_str[] = {"INTER_NEAREST", "INTER_LINEAR", /*"INTER_CUBIC",*/ /*"INTER_LANCZOS4"*/};
|
||||
int interpolations_num = sizeof(interpolations) / sizeof(int);
|
||||
|
||||
int test_res = CvTS::OK;
|
||||
|
||||
for (int i = 0; i < interpolations_num; ++i)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "Interpolation: %s\n", interpolations_str[i]);
|
||||
|
||||
Mat cpu_res1, cpu_res2;
|
||||
cv::resize(img, cpu_res1, Size(), 2.0, 2.0, interpolations[i]);
|
||||
cv::resize(cpu_res1, cpu_res2, Size(), 0.5, 0.5, interpolations[i]);
|
||||
|
||||
GpuMat gpu1(img), gpu_res1, gpu_res2;
|
||||
cv::gpu::resize(gpu1, gpu_res1, Size(), 2.0, 2.0, interpolations[i]);
|
||||
cv::gpu::resize(gpu_res1, gpu_res2, Size(), 0.5, 0.5, interpolations[i]);
|
||||
|
||||
if (CheckSimilarity(cpu_res2, gpu_res2) != CvTS::OK)
|
||||
test_res = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
return test_res;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// copyMakeBorder
|
||||
struct CV_GpuNppImageCopyMakeBorderTest : public CV_GpuImageProcTest
|
||||
{
|
||||
CV_GpuNppImageCopyMakeBorderTest() : CV_GpuImageProcTest( "GPU-NppImageCopyMakeBorder", "copyMakeBorder" ) {}
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
if (img.type() != CV_8UC1 && img.type() != CV_8UC4 && img.type() != CV_32SC1)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nUnsupported type\n");
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
cv::RNG rng(*ts->get_rng());
|
||||
int top = rng.uniform(1, 10);
|
||||
int botton = rng.uniform(1, 10);
|
||||
int left = rng.uniform(1, 10);
|
||||
int right = rng.uniform(1, 10);
|
||||
cv::Scalar val(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
|
||||
|
||||
Mat cpudst;
|
||||
cv::copyMakeBorder(img, cpudst, top, botton, left, right, BORDER_CONSTANT, val);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpudst;
|
||||
cv::gpu::copyMakeBorder(gpu1, gpudst, top, botton, left, right, val);
|
||||
|
||||
return CheckNorm(cpudst, gpudst);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// warpAffine
|
||||
struct CV_GpuNppImageWarpAffineTest : public CV_GpuImageProcTest
|
||||
{
|
||||
CV_GpuNppImageWarpAffineTest() : CV_GpuImageProcTest( "GPU-NppImageWarpAffine", "warpAffine" ) {}
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
if (img.type() == CV_32SC1)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nUnsupported type\n");
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
static double reflect[2][3] = { {-1, 0, 0},
|
||||
{ 0, -1, 0} };
|
||||
reflect[0][2] = img.cols;
|
||||
reflect[1][2] = img.rows;
|
||||
|
||||
Mat M(2, 3, CV_64F, (void*)reflect);
|
||||
|
||||
int flags[] = {INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_NEAREST | WARP_INVERSE_MAP, INTER_LINEAR | WARP_INVERSE_MAP, INTER_CUBIC | WARP_INVERSE_MAP};
|
||||
const char* flags_str[] = {"INTER_NEAREST", "INTER_LINEAR", "INTER_CUBIC", "INTER_NEAREST | WARP_INVERSE_MAP", "INTER_LINEAR | WARP_INVERSE_MAP", "INTER_CUBIC | WARP_INVERSE_MAP"};
|
||||
int flags_num = sizeof(flags) / sizeof(int);
|
||||
|
||||
int test_res = CvTS::OK;
|
||||
|
||||
for (int i = 0; i < flags_num; ++i)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nFlags: %s\n", flags_str[i]);
|
||||
|
||||
Mat cpudst;
|
||||
cv::warpAffine(img, cpudst, M, img.size(), flags[i]);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpudst;
|
||||
cv::gpu::warpAffine(gpu1, gpudst, M, gpu1.size(), flags[i]);
|
||||
|
||||
// Check inner parts (ignoring 1 pixel width border)
|
||||
if (CheckSimilarity(cpudst.rowRange(1, cpudst.rows - 1).colRange(1, cpudst.cols - 1),
|
||||
gpudst.rowRange(1, gpudst.rows - 1).colRange(1, gpudst.cols - 1)) != CvTS::OK)
|
||||
test_res = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
return test_res;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// warpPerspective
|
||||
struct CV_GpuNppImageWarpPerspectiveTest : public CV_GpuImageProcTest
|
||||
{
|
||||
CV_GpuNppImageWarpPerspectiveTest() : CV_GpuImageProcTest( "GPU-NppImageWarpPerspective", "warpPerspective" ) {}
|
||||
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
if (img.type() == CV_32SC1)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nUnsupported type\n");
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
static double reflect[3][3] = { { -1, 0, 0},
|
||||
{ 0, -1, 0},
|
||||
{ 0, 0, 1 }};
|
||||
reflect[0][2] = img.cols;
|
||||
reflect[1][2] = img.rows;
|
||||
Mat M(3, 3, CV_64F, (void*)reflect);
|
||||
|
||||
int flags[] = {INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_NEAREST | WARP_INVERSE_MAP, INTER_LINEAR | WARP_INVERSE_MAP, INTER_CUBIC | WARP_INVERSE_MAP};
|
||||
const char* flags_str[] = {"INTER_NEAREST", "INTER_LINEAR", "INTER_CUBIC", "INTER_NEAREST | WARP_INVERSE_MAP", "INTER_LINEAR | WARP_INVERSE_MAP", "INTER_CUBIC | WARP_INVERSE_MAP"};
|
||||
int flags_num = sizeof(flags) / sizeof(int);
|
||||
|
||||
int test_res = CvTS::OK;
|
||||
|
||||
for (int i = 0; i < flags_num; ++i)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nFlags: %s\n", flags_str[i]);
|
||||
|
||||
Mat cpudst;
|
||||
cv::warpPerspective(img, cpudst, M, img.size(), flags[i]);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpudst;
|
||||
cv::gpu::warpPerspective(gpu1, gpudst, M, gpu1.size(), flags[i]);
|
||||
|
||||
// Check inner parts (ignoring 1 pixel width border)
|
||||
if (CheckSimilarity(cpudst.rowRange(1, cpudst.rows - 1).colRange(1, cpudst.cols - 1),
|
||||
gpudst.rowRange(1, gpudst.rows - 1).colRange(1, gpudst.cols - 1)) != CvTS::OK)
|
||||
test_res = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
return test_res;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// integral
|
||||
struct CV_GpuNppImageIntegralTest : public CV_GpuImageProcTest
|
||||
{
|
||||
CV_GpuNppImageIntegralTest() : CV_GpuImageProcTest( "GPU-NppImageIntegral", "integral" ) {}
|
||||
|
||||
int test(const Mat& img)
|
||||
{
|
||||
if (img.type() != CV_8UC1)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nUnsupported type\n");
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
Mat cpusum;
|
||||
cv::integral(img, cpusum, CV_32S);
|
||||
|
||||
GpuMat gpu1(img);
|
||||
GpuMat gpusum;
|
||||
cv::gpu::integral(gpu1, gpusum);
|
||||
|
||||
return CheckNorm(cpusum, gpusum) == CvTS::OK ? CvTS::OK : CvTS::FAIL_GENERIC;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Canny
|
||||
//struct CV_GpuNppImageCannyTest : public CV_GpuImageProcTest
|
||||
//{
|
||||
// CV_GpuNppImageCannyTest() : CV_GpuImageProcTest( "GPU-NppImageCanny", "Canny" ) {}
|
||||
//
|
||||
// int test(const Mat& img)
|
||||
// {
|
||||
// if (img.type() != CV_8UC1)
|
||||
// {
|
||||
// ts->printf(CvTS::LOG, "\nUnsupported type\n");
|
||||
// return CvTS::OK;
|
||||
// }
|
||||
//
|
||||
// const double threshold1 = 1.0, threshold2 = 10.0;
|
||||
//
|
||||
// Mat cpudst;
|
||||
// cv::Canny(img, cpudst, threshold1, threshold2);
|
||||
//
|
||||
// GpuMat gpu1(img);
|
||||
// GpuMat gpudst;
|
||||
// cv::gpu::Canny(gpu1, gpudst, threshold1, threshold2);
|
||||
//
|
||||
// return CheckNorm(cpudst, gpudst);
|
||||
// }
|
||||
//};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// cvtColor
|
||||
class CV_GpuCvtColorTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GpuCvtColorTest() : CvTest("GPU-CvtColor", "cvtColor") {}
|
||||
~CV_GpuCvtColorTest() {};
|
||||
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
int CheckNorm(const Mat& m1, const Mat& m2);
|
||||
};
|
||||
|
||||
|
||||
int CV_GpuCvtColorTest::CheckNorm(const Mat& m1, const Mat& m2)
|
||||
{
|
||||
double ret = norm(m1, m2, NORM_INF);
|
||||
|
||||
if (ret <= 3)
|
||||
{
|
||||
return CvTS::OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nNorm: %f\n", ret);
|
||||
return CvTS::FAIL_GENERIC;
|
||||
}
|
||||
}
|
||||
|
||||
void CV_GpuCvtColorTest::run( int )
|
||||
{
|
||||
cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-L.png");
|
||||
|
||||
if (img.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
int testResult = CvTS::OK;
|
||||
cv::Mat cpuRes;
|
||||
cv::gpu::GpuMat gpuImg(img), gpuRes;
|
||||
try
|
||||
{
|
||||
int codes[] = { CV_BGR2RGB, CV_RGB2BGRA, CV_BGRA2RGB,
|
||||
CV_RGB2BGR555, CV_BGR5552BGR, CV_BGR2BGR565, CV_BGR5652RGB,
|
||||
CV_RGB2YCrCb, CV_YCrCb2BGR, CV_BGR2YUV, CV_YUV2RGB,
|
||||
CV_RGB2XYZ, CV_XYZ2BGR, CV_BGR2XYZ, CV_XYZ2RGB,
|
||||
CV_RGB2HSV, CV_HSV2BGR, CV_BGR2HSV_FULL, CV_HSV2RGB_FULL,
|
||||
CV_RGB2HLS, CV_HLS2BGR, CV_BGR2HLS_FULL, CV_HLS2RGB_FULL,
|
||||
CV_RGB2GRAY, CV_GRAY2BGRA, CV_BGRA2GRAY,
|
||||
CV_GRAY2BGR555, CV_BGR5552GRAY, CV_GRAY2BGR565, CV_BGR5652GRAY};
|
||||
const char* codes_str[] = { "CV_BGR2RGB", "CV_RGB2BGRA", "CV_BGRA2RGB",
|
||||
"CV_RGB2BGR555", "CV_BGR5552BGR", "CV_BGR2BGR565", "CV_BGR5652RGB",
|
||||
"CV_RGB2YCrCb", "CV_YCrCb2BGR", "CV_BGR2YUV", "CV_YUV2RGB",
|
||||
"CV_RGB2XYZ", "CV_XYZ2BGR", "CV_BGR2XYZ", "CV_XYZ2RGB",
|
||||
"CV_RGB2HSV", "CV_HSV2RGB", "CV_BGR2HSV_FULL", "CV_HSV2RGB_FULL",
|
||||
"CV_RGB2HLS", "CV_HLS2RGB", "CV_BGR2HLS_FULL", "CV_HLS2RGB_FULL",
|
||||
"CV_RGB2GRAY", "CV_GRAY2BGRA", "CV_BGRA2GRAY",
|
||||
"CV_GRAY2BGR555", "CV_BGR5552GRAY", "CV_GRAY2BGR565", "CV_BGR5652GRAY"};
|
||||
int codes_num = sizeof(codes) / sizeof(int);
|
||||
|
||||
for (int i = 0; i < codes_num; ++i)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\n%s\n", codes_str[i]);
|
||||
|
||||
cv::cvtColor(img, cpuRes, codes[i]);
|
||||
cv::gpu::cvtColor(gpuImg, gpuRes, codes[i]);
|
||||
|
||||
if (CheckNorm(cpuRes, gpuRes) == CvTS::OK)
|
||||
ts->printf(CvTS::LOG, "\nSUCCESS\n");
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nFAIL\n");
|
||||
testResult = CvTS::FAIL_GENERIC;
|
||||
}
|
||||
|
||||
img = cpuRes;
|
||||
gpuImg = gpuRes;
|
||||
}
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(testResult);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Histograms
|
||||
class CV_GpuHistogramsTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GpuHistogramsTest() : CvTest("GPU-Histograms", "histEven") {}
|
||||
~CV_GpuHistogramsTest() {};
|
||||
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
int CheckNorm(const Mat& m1, const Mat& m2)
|
||||
{
|
||||
double ret = norm(m1, m2, NORM_INF);
|
||||
|
||||
if (ret < std::numeric_limits<double>::epsilon())
|
||||
{
|
||||
return CvTS::OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nNorm: %f\n", ret);
|
||||
return CvTS::FAIL_GENERIC;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void CV_GpuHistogramsTest::run( int )
|
||||
{
|
||||
//load image
|
||||
cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-L.png");
|
||||
|
||||
if (img.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Mat hsv;
|
||||
cv::cvtColor(img, hsv, CV_BGR2HSV);
|
||||
|
||||
int hbins = 30;
|
||||
int histSize[] = {hbins};
|
||||
|
||||
float hranges[] = {0, 180};
|
||||
const float* ranges[] = {hranges};
|
||||
|
||||
MatND hist;
|
||||
|
||||
int channels[] = {0};
|
||||
calcHist(&hsv, 1, channels, Mat(), hist, 1, histSize, ranges);
|
||||
|
||||
GpuMat gpuHsv(hsv);
|
||||
std::vector<GpuMat> srcs;
|
||||
cv::gpu::split(gpuHsv, srcs);
|
||||
GpuMat gpuHist;
|
||||
histEven(srcs[0], gpuHist, hbins, (int)hranges[0], (int)hranges[1]);
|
||||
|
||||
Mat cpuHist = hist;
|
||||
cpuHist = cpuHist.t();
|
||||
cpuHist.convertTo(cpuHist, CV_32S);
|
||||
|
||||
ts->set_failed_test_info(CheckNorm(cpuHist, gpuHist));
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Corner Harris feature detector
|
||||
|
||||
struct CV_GpuCornerHarrisTest: CvTest
|
||||
{
|
||||
CV_GpuCornerHarrisTest(): CvTest("GPU-CornerHarrisTest", "cornerHarris") {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
int rows = 25 + rand() % 300, cols = 25 + rand() % 300;
|
||||
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, 1 + 2 * (rand() % 4))) return;
|
||||
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, -1)) return;
|
||||
if (!compareToCpuTest(rows, cols, CV_8U, 1 + rand() % 5, 1 + 2 * (rand() % 4))) return;
|
||||
if (!compareToCpuTest(rows, cols, CV_8U, 1 + rand() % 5, -1)) return;
|
||||
}
|
||||
}
|
||||
catch (const Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool compareToCpuTest(int rows, int cols, int depth, int blockSize, int apertureSize)
|
||||
{
|
||||
RNG rng;
|
||||
cv::Mat src(rows, cols, depth);
|
||||
if (depth == CV_32F)
|
||||
rng.fill(src, RNG::UNIFORM, cv::Scalar(0), cv::Scalar(1));
|
||||
else if (depth == CV_8U)
|
||||
rng.fill(src, RNG::UNIFORM, cv::Scalar(0), cv::Scalar(256));
|
||||
|
||||
double k = 0.1;
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::gpu::GpuMat dst;
|
||||
cv::Mat dsth;
|
||||
int borderType;
|
||||
|
||||
borderType = BORDER_REFLECT101;
|
||||
cv::cornerHarris(src, dst_gold, blockSize, apertureSize, k, borderType);
|
||||
cv::gpu::cornerHarris(cv::gpu::GpuMat(src), dst, blockSize, apertureSize, k, borderType);
|
||||
|
||||
dsth = dst;
|
||||
for (int i = 0; i < dst.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < dst.cols; ++j)
|
||||
{
|
||||
float a = dst_gold.at<float>(i, j);
|
||||
float b = dsth.at<float>(i, j);
|
||||
if (fabs(a - b) > 1e-3f)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "%d %d %f %f %d\n", i, j, a, b, apertureSize);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
borderType = BORDER_REPLICATE;
|
||||
cv::cornerHarris(src, dst_gold, blockSize, apertureSize, k, borderType);
|
||||
cv::gpu::cornerHarris(cv::gpu::GpuMat(src), dst, blockSize, apertureSize, k, borderType);
|
||||
|
||||
dsth = dst;
|
||||
for (int i = 0; i < dst.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < dst.cols; ++j)
|
||||
{
|
||||
float a = dst_gold.at<float>(i, j);
|
||||
float b = dsth.at<float>(i, j);
|
||||
if (fabs(a - b) > 1e-3f)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "%d %d %f %f %d\n", i, j, a, b, apertureSize);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Corner Min Eigen Val
|
||||
|
||||
struct CV_GpuCornerMinEigenValTest: CvTest
|
||||
{
|
||||
CV_GpuCornerMinEigenValTest(): CvTest("GPU-CornerMinEigenValTest", "cornerMinEigenVal") {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
int rows = 25 + rand() % 300, cols = 25 + rand() % 300;
|
||||
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, -1)) return;
|
||||
if (!compareToCpuTest(rows, cols, CV_32F, 1 + rand() % 5, 1 + 2 * (rand() % 4))) return;
|
||||
if (!compareToCpuTest(rows, cols, CV_8U, 1 + rand() % 5, -1)) return;
|
||||
if (!compareToCpuTest(rows, cols, CV_8U, 1 + rand() % 5, 1 + 2 * (rand() % 4))) return;
|
||||
}
|
||||
}
|
||||
catch (const Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool compareToCpuTest(int rows, int cols, int depth, int blockSize, int apertureSize)
|
||||
{
|
||||
RNG rng;
|
||||
cv::Mat src(rows, cols, depth);
|
||||
if (depth == CV_32F)
|
||||
rng.fill(src, RNG::UNIFORM, cv::Scalar(0), cv::Scalar(1));
|
||||
else if (depth == CV_8U)
|
||||
rng.fill(src, RNG::UNIFORM, cv::Scalar(0), cv::Scalar(256));
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::gpu::GpuMat dst;
|
||||
cv::Mat dsth;
|
||||
|
||||
int borderType;
|
||||
|
||||
borderType = BORDER_REFLECT101;
|
||||
cv::cornerMinEigenVal(src, dst_gold, blockSize, apertureSize, borderType);
|
||||
cv::gpu::cornerMinEigenVal(cv::gpu::GpuMat(src), dst, blockSize, apertureSize, borderType);
|
||||
|
||||
dsth = dst;
|
||||
for (int i = 0; i < dst.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < dst.cols; ++j)
|
||||
{
|
||||
float a = dst_gold.at<float>(i, j);
|
||||
float b = dsth.at<float>(i, j);
|
||||
if (fabs(a - b) > 1e-2f)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "%d %d %f %f %d %d\n", i, j, a, b, apertureSize, blockSize);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
borderType = BORDER_REPLICATE;
|
||||
cv::cornerMinEigenVal(src, dst_gold, blockSize, apertureSize, borderType);
|
||||
cv::gpu::cornerMinEigenVal(cv::gpu::GpuMat(src), dst, blockSize, apertureSize, borderType);
|
||||
|
||||
dsth = dst;
|
||||
for (int i = 0; i < dst.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < dst.cols; ++j)
|
||||
{
|
||||
float a = dst_gold.at<float>(i, j);
|
||||
float b = dsth.at<float>(i, j);
|
||||
if (fabs(a - b) > 1e-2f)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "%d %d %f %f %d %d\n", i, j, a, b, apertureSize, blockSize);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct CV_GpuColumnSumTest: CvTest
|
||||
{
|
||||
CV_GpuColumnSumTest(): CvTest("GPU-ColumnSumTest", "columnSum") {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
int cols = 375;
|
||||
int rows = 1072;
|
||||
|
||||
Mat src(rows, cols, CV_32F);
|
||||
RNG rng(1);
|
||||
rng.fill(src, RNG::UNIFORM, Scalar(0), Scalar(1));
|
||||
|
||||
GpuMat d_dst;
|
||||
columnSum(GpuMat(src), d_dst);
|
||||
|
||||
Mat dst = d_dst;
|
||||
for (int j = 0; j < src.cols; ++j)
|
||||
{
|
||||
float a = src.at<float>(0, j);
|
||||
float b = dst.at<float>(0, j);
|
||||
if (fabs(a - b) > 0.5f)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "big diff at %d %d: %f %f\n", 0, j, a, b);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < src.rows; ++i)
|
||||
{
|
||||
for (int j = 0; j < src.cols; ++j)
|
||||
{
|
||||
float a = src.at<float>(i, j) += src.at<float>(i - 1, j);
|
||||
float b = dst.at<float>(i, j);
|
||||
if (fabs(a - b) > 0.5f)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "big diff at %d %d: %f %f\n", i, j, a, b);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const Exception& e)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, e.what());
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct CV_GpuNormTest : CvTest
|
||||
{
|
||||
CV_GpuNormTest() : CvTest("GPU-Norm", "norm") {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
RNG rng(0);
|
||||
|
||||
int rows = rng.uniform(1, 500);
|
||||
int cols = rng.uniform(1, 500);
|
||||
|
||||
for (int cn = 1; cn <= 4; ++cn)
|
||||
{
|
||||
test(NORM_L1, rows, cols, CV_8U, cn, Scalar::all(0), Scalar::all(10));
|
||||
test(NORM_L1, rows, cols, CV_8S, cn, Scalar::all(-10), Scalar::all(10));
|
||||
test(NORM_L1, rows, cols, CV_16U, cn, Scalar::all(0), Scalar::all(10));
|
||||
test(NORM_L1, rows, cols, CV_16S, cn, Scalar::all(-10), Scalar::all(10));
|
||||
test(NORM_L1, rows, cols, CV_32S, cn, Scalar::all(-10), Scalar::all(10));
|
||||
test(NORM_L1, rows, cols, CV_32F, cn, Scalar::all(0), Scalar::all(1));
|
||||
|
||||
test(NORM_L2, rows, cols, CV_8U, cn, Scalar::all(0), Scalar::all(10));
|
||||
test(NORM_L2, rows, cols, CV_8S, cn, Scalar::all(-10), Scalar::all(10));
|
||||
test(NORM_L2, rows, cols, CV_16U, cn, Scalar::all(0), Scalar::all(10));
|
||||
test(NORM_L2, rows, cols, CV_16S, cn, Scalar::all(-10), Scalar::all(10));
|
||||
test(NORM_L2, rows, cols, CV_32S, cn, Scalar::all(-10), Scalar::all(10));
|
||||
test(NORM_L2, rows, cols, CV_32F, cn, Scalar::all(0), Scalar::all(1));
|
||||
|
||||
test(NORM_INF, rows, cols, CV_8U, cn, Scalar::all(0), Scalar::all(10));
|
||||
test(NORM_INF, rows, cols, CV_8S, cn, Scalar::all(-10), Scalar::all(10));
|
||||
test(NORM_INF, rows, cols, CV_16U, cn, Scalar::all(0), Scalar::all(10));
|
||||
test(NORM_INF, rows, cols, CV_16S, cn, Scalar::all(-10), Scalar::all(10));
|
||||
test(NORM_INF, rows, cols, CV_32S, cn, Scalar::all(-10), Scalar::all(10));
|
||||
test(NORM_INF, rows, cols, CV_32F, cn, Scalar::all(0), Scalar::all(1));
|
||||
}
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, e.what());
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void gen(Mat& mat, int rows, int cols, int type, Scalar low, Scalar high)
|
||||
{
|
||||
mat.create(rows, cols, type);
|
||||
RNG rng(0);
|
||||
rng.fill(mat, RNG::UNIFORM, low, high);
|
||||
}
|
||||
|
||||
void test(int norm_type, int rows, int cols, int depth, int cn, Scalar low, Scalar high)
|
||||
{
|
||||
int type = CV_MAKE_TYPE(depth, cn);
|
||||
|
||||
Mat src;
|
||||
gen(src, rows, cols, type, low, high);
|
||||
|
||||
double gold = norm(src, norm_type);
|
||||
double mine = norm(GpuMat(src), norm_type);
|
||||
|
||||
if (abs(gold - mine) > 1e-3)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "failed test: gold=%f, mine=%f, norm_type=%d, rows=%d, "
|
||||
"cols=%d, depth=%d, cn=%d\n", gold, mine, norm_type, rows, cols, depth, cn);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// reprojectImageTo3D
|
||||
class CV_GpuReprojectImageTo3DTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GpuReprojectImageTo3DTest() : CvTest("GPU-ReprojectImageTo3D", "reprojectImageTo3D") {}
|
||||
|
||||
protected:
|
||||
void run(int)
|
||||
{
|
||||
Mat disp(320, 240, CV_8UC1);
|
||||
|
||||
RNG rng(*ts->get_rng());
|
||||
rng.fill(disp, RNG::UNIFORM, Scalar(5), Scalar(30));
|
||||
|
||||
Mat Q(4, 4, CV_32FC1);
|
||||
rng.fill(Q, RNG::UNIFORM, Scalar(0.1), Scalar(1));
|
||||
|
||||
Mat cpures;
|
||||
GpuMat gpures;
|
||||
|
||||
reprojectImageTo3D(disp, cpures, Q, false);
|
||||
reprojectImageTo3D(GpuMat(disp), gpures, Q);
|
||||
|
||||
Mat temp = gpures;
|
||||
|
||||
for (int y = 0; y < cpures.rows; ++y)
|
||||
{
|
||||
const Vec3f* cpu_row = cpures.ptr<Vec3f>(y);
|
||||
const Vec4f* gpu_row = temp.ptr<Vec4f>(y);
|
||||
for (int x = 0; x < cpures.cols; ++x)
|
||||
{
|
||||
Vec3f a = cpu_row[x];
|
||||
Vec4f b = gpu_row[x];
|
||||
|
||||
if (fabs(a[0] - b[0]) > 1e-5 || fabs(a[1] - b[1]) > 1e-5 || fabs(a[2] - b[2]) > 1e-5)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// If we comment some tests, we may foget/miss to uncomment it after.
|
||||
// Placing all test definitions in one place
|
||||
// makes us know about what tests are commented.
|
||||
|
||||
CV_GpuImageThresholdTest CV_GpuImageThreshold_test;
|
||||
CV_GpuNppImageResizeTest CV_GpuNppImageResize_test;
|
||||
CV_GpuNppImageCopyMakeBorderTest CV_GpuNppImageCopyMakeBorder_test;
|
||||
CV_GpuNppImageWarpAffineTest CV_GpuNppImageWarpAffine_test;
|
||||
CV_GpuNppImageWarpPerspectiveTest CV_GpuNppImageWarpPerspective_test;
|
||||
CV_GpuNppImageIntegralTest CV_GpuNppImageIntegral_test;
|
||||
//CV_GpuNppImageCannyTest CV_GpuNppImageCanny_test;
|
||||
CV_GpuCvtColorTest CV_GpuCvtColor_test;
|
||||
CV_GpuHistogramsTest CV_GpuHistograms_test;
|
||||
CV_GpuCornerHarrisTest CV_GpuCornerHarris_test;
|
||||
CV_GpuCornerMinEigenValTest CV_GpuCornerMinEigenVal_test;
|
||||
CV_GpuColumnSumTest CV_GpuColumnSum_test;
|
||||
CV_GpuNormTest CV_GpuNormTest_test;
|
||||
CV_GpuReprojectImageTo3DTest CV_GpuReprojectImageTo3D_test;
|
@ -1,310 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other GpuMaterials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or bpied warranties, including, but not limited to, the bpied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
//#define SHOW_TIME
|
||||
|
||||
#ifdef SHOW_TIME
|
||||
#include <ctime>
|
||||
#define F(x) x
|
||||
#else
|
||||
#define F(x)
|
||||
#endif
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
struct CV_GpuMatchTemplateTest: CvTest
|
||||
{
|
||||
CV_GpuMatchTemplateTest(): CvTest("GPU-MatchTemplateTest", "matchTemplate") {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) &&
|
||||
gpu::DeviceInfo().supports(gpu::NATIVE_DOUBLE);
|
||||
if (!double_ok)
|
||||
{
|
||||
// For sqrIntegral
|
||||
ts->printf(CvTS::CONSOLE, "\nCode and device double support is required (CC >= 1.3)");
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
|
||||
Mat image, templ;
|
||||
Mat dst_gold;
|
||||
gpu::GpuMat dst;
|
||||
int n, m, h, w;
|
||||
F(clock_t t;)
|
||||
|
||||
RNG rng(*ts->get_rng());
|
||||
|
||||
for (int cn = 1; cn <= 4; ++cn)
|
||||
{
|
||||
F(ts->printf(CvTS::CONSOLE, "cn: %d\n", cn);)
|
||||
for (int i = 0; i <= 0; ++i)
|
||||
{
|
||||
n = rng.uniform(30, 100);
|
||||
m = rng.uniform(30, 100);
|
||||
h = rng.uniform(5, n - 1);
|
||||
w = rng.uniform(5, m - 1);
|
||||
|
||||
gen(image, n, m, CV_8U, cn);
|
||||
gen(templ, h, w, CV_8U, cn);
|
||||
F(t = clock();)
|
||||
matchTemplate(image, templ, dst_gold, CV_TM_SQDIFF);
|
||||
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
|
||||
F(cout << "cpu:" << clock() - t << endl;)
|
||||
F(t = clock();)
|
||||
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF);
|
||||
F(cout << "gpu_block: " << clock() - t << endl;)
|
||||
if (!check(dst_gold, Mat(dst), 5 * h * w * 1e-4f, "SQDIFF 8U")) return;
|
||||
|
||||
gen(image, n, m, CV_8U, cn);
|
||||
gen(templ, h, w, CV_8U, cn);
|
||||
F(t = clock();)
|
||||
matchTemplate(image, templ, dst_gold, CV_TM_SQDIFF_NORMED);
|
||||
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
|
||||
F(cout << "cpu:" << clock() - t << endl;)
|
||||
F(t = clock();)
|
||||
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF_NORMED);
|
||||
F(cout << "gpu_block: " << clock() - t << endl;)
|
||||
if (!check(dst_gold, Mat(dst), h * w * 1e-5f, "SQDIFF_NOREMD 8U")) return;
|
||||
|
||||
gen(image, n, m, CV_8U, cn);
|
||||
gen(templ, h, w, CV_8U, cn);
|
||||
F(t = clock();)
|
||||
matchTemplate(image, templ, dst_gold, CV_TM_CCORR);
|
||||
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
|
||||
F(cout << "cpu:" << clock() - t << endl;)
|
||||
F(t = clock();)
|
||||
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR);
|
||||
F(cout << "gpu_block: " << clock() - t << endl;)
|
||||
if (!check(dst_gold, Mat(dst), 5 * h * w * cn * cn * 1e-5f, "CCORR 8U")) return;
|
||||
|
||||
gen(image, n, m, CV_8U, cn);
|
||||
gen(templ, h, w, CV_8U, cn);
|
||||
F(t = clock();)
|
||||
matchTemplate(image, templ, dst_gold, CV_TM_CCORR_NORMED);
|
||||
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
|
||||
F(cout << "cpu:" << clock() - t << endl;)
|
||||
F(t = clock();)
|
||||
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR_NORMED);
|
||||
F(cout << "gpu_block: " << clock() - t << endl;)
|
||||
if (!check(dst_gold, Mat(dst), h * w * 1e-6f, "CCORR_NORMED 8U")) return;
|
||||
|
||||
gen(image, n, m, CV_8U, cn);
|
||||
gen(templ, h, w, CV_8U, cn);
|
||||
F(t = clock();)
|
||||
matchTemplate(image, templ, dst_gold, CV_TM_CCOEFF);
|
||||
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
|
||||
F(cout << "cpu:" << clock() - t << endl;)
|
||||
F(t = clock();)
|
||||
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCOEFF);
|
||||
F(cout << "gpu_block: " << clock() - t << endl;)
|
||||
if (!check(dst_gold, Mat(dst), 5 * h * w * cn * cn * 1e-5f, "CCOEFF 8U")) return;
|
||||
|
||||
gen(image, n, m, CV_8U, cn);
|
||||
gen(templ, h, w, CV_8U, cn);
|
||||
F(t = clock();)
|
||||
matchTemplate(image, templ, dst_gold, CV_TM_CCOEFF_NORMED);
|
||||
F(cout << "depth: 8U cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
|
||||
F(cout << "cpu:" << clock() - t << endl;)
|
||||
F(t = clock();)
|
||||
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCOEFF_NORMED);
|
||||
F(cout << "gpu_block: " << clock() - t << endl;)
|
||||
if (!check(dst_gold, Mat(dst), h * w * 1e-6f, "CCOEFF_NORMED 8U")) return;
|
||||
|
||||
gen(image, n, m, CV_32F, cn);
|
||||
gen(templ, h, w, CV_32F, cn);
|
||||
F(t = clock();)
|
||||
matchTemplate(image, templ, dst_gold, CV_TM_SQDIFF);
|
||||
F(cout << "depth: 32F cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
|
||||
F(cout << "cpu:" << clock() - t << endl;)
|
||||
F(t = clock();)
|
||||
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_SQDIFF);
|
||||
F(cout << "gpu_block: " << clock() - t << endl;)
|
||||
if (!check(dst_gold, Mat(dst), 0.25f * h * w * 1e-5f, "SQDIFF 32F")) return;
|
||||
|
||||
gen(image, n, m, CV_32F, cn);
|
||||
gen(templ, h, w, CV_32F, cn);
|
||||
F(t = clock();)
|
||||
matchTemplate(image, templ, dst_gold, CV_TM_CCORR);
|
||||
F(cout << "depth: 32F cn: " << cn << " n: " << n << " m: " << m << " w: " << w << " h: " << h << endl;)
|
||||
F(cout << "cpu:" << clock() - t << endl;)
|
||||
F(t = clock();)
|
||||
gpu::matchTemplate(gpu::GpuMat(image), gpu::GpuMat(templ), dst, CV_TM_CCORR);
|
||||
F(cout << "gpu_block: " << clock() - t << endl;)
|
||||
if (!check(dst_gold, Mat(dst), 0.25f * h * w * 1e-5f, "CCORR 32F")) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const Exception& e)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, e.what());
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void gen(Mat& a, int rows, int cols, int depth, int cn)
|
||||
{
|
||||
RNG rng;
|
||||
a.create(rows, cols, CV_MAKETYPE(depth, cn));
|
||||
if (depth == CV_8U)
|
||||
rng.fill(a, RNG::UNIFORM, Scalar::all(1), Scalar::all(10));
|
||||
else if (depth == CV_32F)
|
||||
rng.fill(a, RNG::UNIFORM, Scalar::all(0.001f), Scalar::all(1.f));
|
||||
}
|
||||
|
||||
bool check(const Mat& a, const Mat& b, float max_err, const string& method="")
|
||||
{
|
||||
if (a.size() != b.size())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad size, method=%s\n", method.c_str());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
|
||||
//for (int i = 0; i < a.rows; ++i)
|
||||
//{
|
||||
// for (int j = 0; j < a.cols; ++j)
|
||||
// {
|
||||
// float a_ = a.at<float>(i, j);
|
||||
// float b_ = b.at<float>(i, j);
|
||||
// if (fabs(a_ - b_) > max_err)
|
||||
// {
|
||||
// ts->printf(CvTS::CONSOLE, "a=%f, b=%f, i=%d, j=%d\n", a_, b_, i, j);
|
||||
// cin.get();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
float err = (float)norm(a, b, NORM_INF);
|
||||
if (err > max_err)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad accuracy: %f, method=%s\n", err, method.c_str());
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} match_template_test;
|
||||
|
||||
struct CV_GpuMatchTemplateFindPatternInBlackTest: CvTest
|
||||
{
|
||||
CV_GpuMatchTemplateFindPatternInBlackTest()
|
||||
: CvTest("GPU-MatchTemplateFindPatternInBlackTest", "matchTemplate") {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) &&
|
||||
gpu::DeviceInfo().supports(gpu::NATIVE_DOUBLE);
|
||||
if (!double_ok)
|
||||
{
|
||||
// For sqrIntegral
|
||||
ts->printf(CvTS::CONSOLE, "\nCode and device double support is required (CC >= 1.3)");
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
|
||||
Mat image = imread(std::string(ts->get_data_path()) + "matchtemplate/black.png");
|
||||
if (image.empty())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "can't open file '%s'", (std::string(ts->get_data_path())
|
||||
+ "matchtemplate/black.png").c_str());
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
Mat pattern = imread(std::string(ts->get_data_path()) + "matchtemplate/cat.png");
|
||||
if (pattern.empty())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "can't open file '%s'", (std::string(ts->get_data_path())
|
||||
+ "matchtemplate/cat.png").c_str());
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
gpu::GpuMat d_image(image);
|
||||
gpu::GpuMat d_pattern(pattern);
|
||||
gpu::GpuMat d_result;
|
||||
|
||||
double maxValue;
|
||||
Point maxLoc;
|
||||
Point maxLocGold(284, 12);
|
||||
|
||||
gpu::matchTemplate(d_image, d_pattern, d_result, CV_TM_CCOEFF_NORMED);
|
||||
gpu::minMaxLoc(d_result, NULL, &maxValue, NULL, &maxLoc );
|
||||
if (maxLoc != maxLocGold)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad match (CV_TM_CCOEFF_NORMED): %d %d, must be at: %d %d",
|
||||
maxLoc.x, maxLoc.y, maxLocGold.x, maxLocGold.y);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
|
||||
gpu::matchTemplate(d_image, d_pattern, d_result, CV_TM_CCORR_NORMED);
|
||||
gpu::minMaxLoc(d_result, NULL, &maxValue, NULL, &maxLoc );
|
||||
if (maxLoc != maxLocGold)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "bad match (CV_TM_CCORR_NORMED): %d %d, must be at: %d %d",
|
||||
maxLoc.x, maxLoc.y, maxLocGold.x, maxLocGold.y);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (const Exception& e)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, e.what());
|
||||
if (!check_and_treat_gpu_exception(e, ts)) throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} match_templet_find_bordered_pattern_test;
|
@ -1,255 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
|
||||
struct CV_GpuMeanShiftTest : public CvTest
|
||||
{
|
||||
CV_GpuMeanShiftTest(): CvTest( "GPU-MeanShift", "MeanShift" ){}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
bool cc12_ok = TargetArchs::builtWith(FEATURE_SET_COMPUTE_12) && DeviceInfo().supports(FEATURE_SET_COMPUTE_12);
|
||||
if (!cc12_ok)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "\nCompute capability 1.2 is required");
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
|
||||
int spatialRad = 30;
|
||||
int colorRad = 30;
|
||||
|
||||
cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "meanshift/cones.png");
|
||||
cv::Mat img_template;
|
||||
|
||||
if (cv::gpu::TargetArchs::builtWith(cv::gpu::FEATURE_SET_COMPUTE_20) &&
|
||||
cv::gpu::DeviceInfo().supports(cv::gpu::FEATURE_SET_COMPUTE_20))
|
||||
img_template = cv::imread(std::string(ts->get_data_path()) + "meanshift/con_result.png");
|
||||
else
|
||||
img_template = cv::imread(std::string(ts->get_data_path()) + "meanshift/con_result_CC1X.png");
|
||||
|
||||
if (img.empty() || img_template.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
cv::Mat rgba;
|
||||
cvtColor(img, rgba, CV_BGR2BGRA);
|
||||
|
||||
try
|
||||
{
|
||||
cv::gpu::GpuMat res;
|
||||
cv::gpu::meanShiftFiltering( cv::gpu::GpuMat(rgba), res, spatialRad, colorRad );
|
||||
|
||||
if (res.type() != CV_8UC4)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
|
||||
cv::Mat result;
|
||||
res.download(result);
|
||||
|
||||
uchar maxDiff = 0;
|
||||
for (int j = 0; j < result.rows; ++j)
|
||||
{
|
||||
const uchar* res_line = result.ptr<uchar>(j);
|
||||
const uchar* ref_line = img_template.ptr<uchar>(j);
|
||||
|
||||
for (int i = 0; i < result.cols; ++i)
|
||||
{
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
const uchar& ch1 = res_line[result.channels()*i + k];
|
||||
const uchar& ch2 = ref_line[img_template.channels()*i + k];
|
||||
uchar diff = static_cast<uchar>(abs(ch1 - ch2));
|
||||
if (maxDiff < diff)
|
||||
maxDiff = diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (maxDiff > 0)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nMeanShift maxDiff = %d\n", maxDiff);
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_GpuMeanShiftTest CV_GpuMeanShift_test;
|
||||
|
||||
struct CV_GpuMeanShiftProcTest : public CvTest
|
||||
{
|
||||
CV_GpuMeanShiftProcTest(): CvTest( "GPU-MeanShiftProc", "MeanShiftProc" ){}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
bool cc12_ok = TargetArchs::builtWith(FEATURE_SET_COMPUTE_12) && DeviceInfo().supports(FEATURE_SET_COMPUTE_12);
|
||||
if (!cc12_ok)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "\nCompute capability 1.2 is required");
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
|
||||
int spatialRad = 30;
|
||||
int colorRad = 30;
|
||||
|
||||
cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "meanshift/cones.png");
|
||||
|
||||
if (img.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
cv::Mat rgba;
|
||||
cvtColor(img, rgba, CV_BGR2BGRA);
|
||||
|
||||
try
|
||||
{
|
||||
cv::gpu::GpuMat h_rmap_filtered;
|
||||
cv::gpu::meanShiftFiltering( cv::gpu::GpuMat(rgba), h_rmap_filtered, spatialRad, colorRad );
|
||||
|
||||
cv::gpu::GpuMat d_rmap;
|
||||
cv::gpu::GpuMat d_spmap;
|
||||
cv::gpu::meanShiftProc( cv::gpu::GpuMat(rgba), d_rmap, d_spmap, spatialRad, colorRad );
|
||||
|
||||
if (d_rmap.type() != CV_8UC4)
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
|
||||
cv::Mat rmap_filtered;
|
||||
h_rmap_filtered.download(rmap_filtered);
|
||||
|
||||
cv::Mat rmap;
|
||||
d_rmap.download(rmap);
|
||||
|
||||
uchar maxDiff = 0;
|
||||
for (int j = 0; j < rmap_filtered.rows; ++j)
|
||||
{
|
||||
const uchar* res_line = rmap_filtered.ptr<uchar>(j);
|
||||
const uchar* ref_line = rmap.ptr<uchar>(j);
|
||||
|
||||
for (int i = 0; i < rmap_filtered.cols; ++i)
|
||||
{
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
const uchar& ch1 = res_line[rmap_filtered.channels()*i + k];
|
||||
const uchar& ch2 = ref_line[rmap.channels()*i + k];
|
||||
uchar diff = static_cast<uchar>(abs(ch1 - ch2));
|
||||
if (maxDiff < diff)
|
||||
maxDiff = diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (maxDiff > 0)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nMeanShiftProc maxDiff = %d\n", maxDiff);
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
|
||||
cv::Mat spmap;
|
||||
d_spmap.download(spmap);
|
||||
|
||||
cv::Mat spmap_template;
|
||||
cv::FileStorage fs;
|
||||
|
||||
if (cv::gpu::TargetArchs::builtWith(cv::gpu::FEATURE_SET_COMPUTE_20) &&
|
||||
cv::gpu::DeviceInfo().supports(cv::gpu::FEATURE_SET_COMPUTE_20))
|
||||
fs.open(std::string(ts->get_data_path()) + "meanshift/spmap.yaml", cv::FileStorage::READ);
|
||||
else
|
||||
fs.open(std::string(ts->get_data_path()) + "meanshift/spmap_CC1X.yaml", cv::FileStorage::READ);
|
||||
fs["spmap"] >> spmap_template;
|
||||
|
||||
for (int y = 0; y < spmap.rows; ++y) {
|
||||
for (int x = 0; x < spmap.cols; ++x) {
|
||||
cv::Point_<short> expected = spmap_template.at<cv::Point_<short> >(y, x);
|
||||
cv::Point_<short> actual = spmap.at<cv::Point_<short> >(y, x);
|
||||
int diff = (expected - actual).dot(expected - actual);
|
||||
if (actual != expected) {
|
||||
ts->printf(CvTS::LOG, "\nMeanShiftProc SpMap is bad, diff=%d\n", diff);
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CV_GpuMeanShiftProcTest CV_GpuMeanShiftProc_test;
|
@ -1,128 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
#include "gputest.hpp"
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
using namespace std;
|
||||
|
||||
struct CV_GpuMeanShiftSegmentationTest : public CvTest {
|
||||
CV_GpuMeanShiftSegmentationTest() : CvTest( "GPU-MeanShiftSegmentation", "MeanShiftSegmentation" ) {}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool cc12_ok = TargetArchs::builtWith(FEATURE_SET_COMPUTE_12) && DeviceInfo().supports(FEATURE_SET_COMPUTE_12);
|
||||
if (!cc12_ok)
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "\nCompute capability 1.2 is required");
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
|
||||
Mat img_rgb = imread(string(ts->get_data_path()) + "meanshift/cones.png");
|
||||
if (img_rgb.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
Mat img;
|
||||
cvtColor(img_rgb, img, CV_BGR2BGRA);
|
||||
|
||||
|
||||
for (int minsize = 0; minsize < 2000; minsize = (minsize + 1) * 4)
|
||||
{
|
||||
stringstream path;
|
||||
path << ts->get_data_path() << "meanshift/cones_segmented_sp10_sr10_minsize" << minsize;
|
||||
if (TargetArchs::builtWith(FEATURE_SET_COMPUTE_20) && DeviceInfo().supports(FEATURE_SET_COMPUTE_20))
|
||||
path << ".png";
|
||||
else
|
||||
path << "_CC1X.png";
|
||||
|
||||
Mat dst;
|
||||
meanShiftSegmentation((GpuMat)img, dst, 10, 10, minsize);
|
||||
Mat dst_rgb;
|
||||
cvtColor(dst, dst_rgb, CV_BGRA2BGR);
|
||||
|
||||
//imwrite(path.str(), dst_rgb);
|
||||
Mat dst_ref = imread(path.str());
|
||||
if (dst_ref.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
if (CheckSimilarity(dst_rgb, dst_ref, 1e-3f) != CvTS::OK)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\ndiffers from image *minsize%d.png\n", minsize);
|
||||
ts->set_failed_test_info(CvTS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
|
||||
int CheckSimilarity(const Mat& m1, const Mat& m2, float max_err)
|
||||
{
|
||||
Mat diff;
|
||||
cv::matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED);
|
||||
|
||||
float err = abs(diff.at<float>(0, 0) - 1.f);
|
||||
|
||||
if (err > max_err)
|
||||
return CvTS::FAIL_INVALID_OUTPUT;
|
||||
|
||||
return CvTS::OK;
|
||||
}
|
||||
|
||||
|
||||
} ms_segm_test;
|
@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _ncvautotestlister_hpp_
|
||||
#define _ncvautotestlister_hpp_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
|
||||
class NCVAutoTestLister
|
||||
{
|
||||
public:
|
||||
|
||||
NCVAutoTestLister(std::string testSuiteName, NcvBool bStopOnFirstFail=false, NcvBool bCompactOutput=true)
|
||||
:
|
||||
testSuiteName(testSuiteName),
|
||||
bStopOnFirstFail(bStopOnFirstFail),
|
||||
bCompactOutput(bCompactOutput)
|
||||
{
|
||||
}
|
||||
|
||||
void add(INCVTest *test)
|
||||
{
|
||||
this->tests.push_back(test);
|
||||
}
|
||||
|
||||
bool invoke()
|
||||
{
|
||||
Ncv32u nPassed = 0;
|
||||
Ncv32u nFailed = 0;
|
||||
Ncv32u nFailedMem = 0;
|
||||
|
||||
if (bCompactOutput)
|
||||
{
|
||||
printf("Test suite '%s' with %d tests\n",
|
||||
testSuiteName.c_str(),
|
||||
(int)(this->tests.size()));
|
||||
}
|
||||
|
||||
for (Ncv32u i=0; i<this->tests.size(); i++)
|
||||
{
|
||||
INCVTest &curTest = *tests[i];
|
||||
|
||||
NCVTestReport curReport;
|
||||
bool res = curTest.executeTest(curReport);
|
||||
|
||||
if (!bCompactOutput)
|
||||
{
|
||||
printf("Test %3i %16s; Consumed mem GPU = %8d, CPU = %8d; %s\n",
|
||||
i,
|
||||
curTest.getName().c_str(),
|
||||
curReport.statsNums["MemGPU"],
|
||||
curReport.statsNums["MemCPU"],
|
||||
curReport.statsText["rcode"].c_str());
|
||||
}
|
||||
|
||||
if (res)
|
||||
{
|
||||
nPassed++;
|
||||
if (bCompactOutput)
|
||||
{
|
||||
printf(".");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!curReport.statsText["rcode"].compare("FAILED"))
|
||||
{
|
||||
nFailed++;
|
||||
if (bCompactOutput)
|
||||
{
|
||||
printf("x");
|
||||
}
|
||||
if (bStopOnFirstFail)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nFailedMem++;
|
||||
if (bCompactOutput)
|
||||
{
|
||||
printf("m");
|
||||
}
|
||||
}
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
if (bCompactOutput)
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("Test suite '%s' complete: %d total, %d passed, %d memory errors, %d failed\n\n",
|
||||
testSuiteName.c_str(),
|
||||
(int)(this->tests.size()),
|
||||
nPassed,
|
||||
nFailedMem,
|
||||
nFailed);
|
||||
|
||||
bool passed = nFailed == 0 && nFailedMem == 0;
|
||||
return passed;
|
||||
}
|
||||
|
||||
~NCVAutoTestLister()
|
||||
{
|
||||
for (Ncv32u i=0; i<this->tests.size(); i++)
|
||||
{
|
||||
delete tests[i];
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
NcvBool bStopOnFirstFail;
|
||||
NcvBool bCompactOutput;
|
||||
std::string testSuiteName;
|
||||
std::vector<INCVTest *> tests;
|
||||
};
|
||||
|
||||
#endif // _ncvautotestlister_hpp_
|
@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _ncvtest_hpp_
|
||||
#define _ncvtest_hpp_
|
||||
|
||||
#pragma warning( disable : 4201 4408 4127 4100)
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include "NPP_staging.hpp"
|
||||
|
||||
|
||||
struct NCVTestReport
|
||||
{
|
||||
std::map<std::string, Ncv32u> statsNums;
|
||||
std::map<std::string, std::string> statsText;
|
||||
};
|
||||
|
||||
|
||||
class INCVTest
|
||||
{
|
||||
public:
|
||||
virtual bool executeTest(NCVTestReport &report) = 0;
|
||||
virtual std::string getName() const = 0;
|
||||
};
|
||||
|
||||
|
||||
class NCVTestProvider : public INCVTest
|
||||
{
|
||||
public:
|
||||
|
||||
NCVTestProvider(std::string testName)
|
||||
:
|
||||
testName(testName)
|
||||
{
|
||||
int devId;
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDevice(&devId), "Error returned from cudaGetDevice", );
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDeviceProperties(&this->devProp, devId), "Error returned from cudaGetDeviceProperties", );
|
||||
}
|
||||
|
||||
virtual bool init() = 0;
|
||||
virtual bool process() = 0;
|
||||
virtual bool deinit() = 0;
|
||||
virtual bool toString(std::ofstream &strOut) = 0;
|
||||
|
||||
virtual std::string getName() const
|
||||
{
|
||||
return this->testName;
|
||||
}
|
||||
|
||||
virtual ~NCVTestProvider()
|
||||
{
|
||||
deinitMemory();
|
||||
}
|
||||
|
||||
virtual bool executeTest(NCVTestReport &report)
|
||||
{
|
||||
bool res;
|
||||
report.statsText["rcode"] = "FAILED";
|
||||
|
||||
res = initMemory(report);
|
||||
if (!res)
|
||||
{
|
||||
dumpToFile(report);
|
||||
deinitMemory();
|
||||
return false;
|
||||
}
|
||||
|
||||
res = init();
|
||||
if (!res)
|
||||
{
|
||||
dumpToFile(report);
|
||||
deinit();
|
||||
deinitMemory();
|
||||
return false;
|
||||
}
|
||||
|
||||
res = process();
|
||||
if (!res)
|
||||
{
|
||||
dumpToFile(report);
|
||||
deinit();
|
||||
deinitMemory();
|
||||
return false;
|
||||
}
|
||||
|
||||
res = deinit();
|
||||
if (!res)
|
||||
{
|
||||
dumpToFile(report);
|
||||
deinitMemory();
|
||||
return false;
|
||||
}
|
||||
|
||||
deinitMemory();
|
||||
|
||||
report.statsText["rcode"] = "Passed";
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
cudaDeviceProp devProp;
|
||||
std::auto_ptr<INCVMemAllocator> allocatorGPU;
|
||||
std::auto_ptr<INCVMemAllocator> allocatorCPU;
|
||||
|
||||
private:
|
||||
|
||||
std::string testName;
|
||||
|
||||
bool initMemory(NCVTestReport &report)
|
||||
{
|
||||
this->allocatorGPU.reset(new NCVMemStackAllocator(devProp.textureAlignment));
|
||||
this->allocatorCPU.reset(new NCVMemStackAllocator(devProp.textureAlignment));
|
||||
|
||||
if (!this->allocatorGPU.get()->isInitialized() ||
|
||||
!this->allocatorCPU.get()->isInitialized())
|
||||
{
|
||||
report.statsText["rcode"] = "Memory FAILED";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->process())
|
||||
{
|
||||
report.statsText["rcode"] = "Memory FAILED";
|
||||
return false;
|
||||
}
|
||||
|
||||
Ncv32u maxGPUsize = (Ncv32u)this->allocatorGPU.get()->maxSize();
|
||||
Ncv32u maxCPUsize = (Ncv32u)this->allocatorCPU.get()->maxSize();
|
||||
|
||||
report.statsNums["MemGPU"] = maxGPUsize;
|
||||
report.statsNums["MemCPU"] = maxCPUsize;
|
||||
|
||||
this->allocatorGPU.reset(new NCVMemStackAllocator(NCVMemoryTypeDevice, maxGPUsize, devProp.textureAlignment));
|
||||
|
||||
this->allocatorCPU.reset(new NCVMemStackAllocator(NCVMemoryTypeHostPinned, maxCPUsize, devProp.textureAlignment));
|
||||
|
||||
if (!this->allocatorGPU.get()->isInitialized() ||
|
||||
!this->allocatorCPU.get()->isInitialized())
|
||||
{
|
||||
report.statsText["rcode"] = "Memory FAILED";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void deinitMemory()
|
||||
{
|
||||
this->allocatorGPU.reset();
|
||||
this->allocatorCPU.reset();
|
||||
}
|
||||
|
||||
void dumpToFile(NCVTestReport &report)
|
||||
{
|
||||
bool bReasonMem = (0 == report.statsText["rcode"].compare("Memory FAILED"));
|
||||
std::string fname = "TestDump_";
|
||||
fname += (bReasonMem ? "m_" : "") + this->testName + ".log";
|
||||
std::ofstream stream(fname.c_str(), std::ios::trunc | std::ios::out);
|
||||
if (!stream.is_open()) return;
|
||||
|
||||
stream << "NCV Test Failure Log: " << this->testName << std::endl;
|
||||
stream << "====================================================" << std::endl << std::endl;
|
||||
stream << "Test initialization report: " << std::endl;
|
||||
for (std::map<std::string,std::string>::iterator it=report.statsText.begin();
|
||||
it != report.statsText.end(); it++)
|
||||
{
|
||||
stream << it->first << "=" << it->second << std::endl;
|
||||
}
|
||||
for (std::map<std::string,Ncv32u>::iterator it=report.statsNums.begin();
|
||||
it != report.statsNums.end(); it++)
|
||||
{
|
||||
stream << it->first << "=" << it->second << std::endl;
|
||||
}
|
||||
stream << std::endl;
|
||||
|
||||
stream << "Test initialization parameters: " << std::endl;
|
||||
bool bSerializeRes = false;
|
||||
try
|
||||
{
|
||||
bSerializeRes = this->toString(stream);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
if (!bSerializeRes)
|
||||
{
|
||||
stream << "Couldn't retrieve object dump" << std::endl;
|
||||
}
|
||||
|
||||
stream.flush();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _ncvtest_hpp_
|
@ -1,161 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _ncvtestsourceprovider_hpp_
|
||||
#define _ncvtestsourceprovider_hpp_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "NCV.hpp"
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
|
||||
|
||||
template <class T>
|
||||
class NCVTestSourceProvider
|
||||
{
|
||||
public:
|
||||
|
||||
NCVTestSourceProvider(Ncv32u seed, T rangeLow, T rangeHigh, Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
:
|
||||
bInit(false)
|
||||
{
|
||||
ncvAssertPrintReturn(rangeLow < rangeHigh, "NCVTestSourceProvider ctor:: Invalid range", );
|
||||
|
||||
int devId;
|
||||
cudaDeviceProp devProp;
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDevice(&devId), "Error returned from cudaGetDevice", );
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDeviceProperties(&devProp, devId), "Error returned from cudaGetDeviceProperties", );
|
||||
|
||||
//Ncv32u maxWpitch = alignUp(maxWidth * sizeof(T), devProp.textureAlignment);
|
||||
|
||||
allocatorCPU.reset(new NCVMemNativeAllocator(NCVMemoryTypeHostPinned, devProp.textureAlignment));
|
||||
data.reset(new NCVMatrixAlloc<T>(*this->allocatorCPU.get(), maxWidth, maxHeight));
|
||||
ncvAssertPrintReturn(data.get()->isMemAllocated(), "NCVTestSourceProvider ctor:: Matrix not allocated", );
|
||||
|
||||
this->dataWidth = maxWidth;
|
||||
this->dataHeight = maxHeight;
|
||||
|
||||
srand(seed);
|
||||
|
||||
for (Ncv32u i=0; i<maxHeight; i++)
|
||||
{
|
||||
for (Ncv32u j=0; j<data.get()->stride(); j++)
|
||||
{
|
||||
data.get()->ptr()[i * data.get()->stride() + j] =
|
||||
(T)(((1.0 * rand()) / RAND_MAX) * (rangeHigh - rangeLow) + rangeLow);
|
||||
}
|
||||
}
|
||||
|
||||
this->bInit = true;
|
||||
}
|
||||
|
||||
NCVTestSourceProvider(std::string pgmFilename)
|
||||
:
|
||||
bInit(false)
|
||||
{
|
||||
ncvAssertPrintReturn(sizeof(T) == 1, "NCVTestSourceProvider ctor:: PGM constructor complies only with 8bit types", );
|
||||
|
||||
cv::Mat image = cv::imread(pgmFilename);
|
||||
ncvAssertPrintReturn(!image.empty(), "NCVTestSourceProvider ctor:: PGM file error", );
|
||||
|
||||
int devId;
|
||||
cudaDeviceProp devProp;
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDevice(&devId), "Error returned from cudaGetDevice", );
|
||||
ncvAssertPrintReturn(cudaSuccess == cudaGetDeviceProperties(&devProp, devId), "Error returned from cudaGetDeviceProperties", );
|
||||
|
||||
allocatorCPU.reset(new NCVMemNativeAllocator(NCVMemoryTypeHostPinned, devProp.textureAlignment));
|
||||
data.reset(new NCVMatrixAlloc<T>(*this->allocatorCPU.get(), image.cols, image.rows));
|
||||
ncvAssertPrintReturn(data.get()->isMemAllocated(), "NCVTestSourceProvider ctor:: Matrix not allocated", );
|
||||
|
||||
this->dataWidth = image.cols;
|
||||
this->dataHeight = image.rows;
|
||||
|
||||
cv::Mat hdr(image.size(), CV_8UC1, data.get()->ptr(), data.get()->pitch());
|
||||
image.copyTo(hdr);
|
||||
|
||||
this->bInit = true;
|
||||
}
|
||||
|
||||
NcvBool fill(NCVMatrix<T> &dst)
|
||||
{
|
||||
ncvAssertReturn(this->isInit() &&
|
||||
dst.memType() == allocatorCPU.get()->memType(), false);
|
||||
|
||||
if (dst.width() == 0 || dst.height() == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Ncv32u i=0; i<dst.height(); i++)
|
||||
{
|
||||
Ncv32u srcLine = i % this->dataHeight;
|
||||
|
||||
Ncv32u srcFullChunks = dst.width() / this->dataWidth;
|
||||
for (Ncv32u j=0; j<srcFullChunks; j++)
|
||||
{
|
||||
memcpy(dst.ptr() + i * dst.stride() + j * this->dataWidth,
|
||||
this->data.get()->ptr() + this->data.get()->stride() * srcLine,
|
||||
this->dataWidth * sizeof(T));
|
||||
}
|
||||
|
||||
Ncv32u srcLastChunk = dst.width() % this->dataWidth;
|
||||
memcpy(dst.ptr() + i * dst.stride() + srcFullChunks * this->dataWidth,
|
||||
this->data.get()->ptr() + this->data.get()->stride() * srcLine,
|
||||
srcLastChunk * sizeof(T));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NcvBool fill(NCVVector<T> &dst)
|
||||
{
|
||||
ncvAssertReturn(this->isInit() &&
|
||||
dst.memType() == allocatorCPU.get()->memType(), false);
|
||||
|
||||
if (dst.length() == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Ncv32u srcLen = this->dataWidth * this->dataHeight;
|
||||
|
||||
Ncv32u srcFullChunks = (Ncv32u)dst.length() / srcLen;
|
||||
for (Ncv32u j=0; j<srcFullChunks; j++)
|
||||
{
|
||||
memcpy(dst.ptr() + j * srcLen, this->data.get()->ptr(), srcLen * sizeof(T));
|
||||
}
|
||||
|
||||
Ncv32u srcLastChunk = dst.length() % srcLen;
|
||||
memcpy(dst.ptr() + srcFullChunks * srcLen, this->data.get()->ptr(), srcLastChunk * sizeof(T));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
~NCVTestSourceProvider()
|
||||
{
|
||||
data.reset();
|
||||
allocatorCPU.reset();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
NcvBool isInit(void)
|
||||
{
|
||||
return this->bInit;
|
||||
}
|
||||
|
||||
NcvBool bInit;
|
||||
std::auto_ptr< INCVMemAllocator > allocatorCPU;
|
||||
std::auto_ptr< NCVMatrixAlloc<T> > data;
|
||||
Ncv32u dataWidth;
|
||||
Ncv32u dataHeight;
|
||||
};
|
||||
|
||||
#endif // _ncvtestsourceprovider_hpp_
|
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include "TestCompact.h"
|
||||
|
||||
|
||||
TestCompact::TestCompact(std::string testName, NCVTestSourceProvider<Ncv32u> &src,
|
||||
Ncv32u length, Ncv32u badElem, Ncv32u badElemPercentage)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
length(length),
|
||||
badElem(badElem),
|
||||
badElemPercentage(badElemPercentage > 100 ? 100 : badElemPercentage)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestCompact::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "length=" << length << std::endl;
|
||||
strOut << "badElem=" << badElem << std::endl;
|
||||
strOut << "badElemPercentage=" << badElemPercentage << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestCompact::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestCompact::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_vecSrc(*this->allocatorCPU.get(), this->length);
|
||||
ncvAssertReturn(h_vecSrc.isMemAllocated(), false);
|
||||
NCVVectorAlloc<Ncv32u> d_vecSrc(*this->allocatorGPU.get(), this->length);
|
||||
ncvAssertReturn(d_vecSrc.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_vecDst(*this->allocatorCPU.get(), this->length);
|
||||
ncvAssertReturn(h_vecDst.isMemAllocated(), false);
|
||||
NCVVectorAlloc<Ncv32u> d_vecDst(*this->allocatorGPU.get(), this->length);
|
||||
ncvAssertReturn(d_vecDst.isMemAllocated(), false);
|
||||
NCVVectorAlloc<Ncv32u> h_vecDst_d(*this->allocatorCPU.get(), this->length);
|
||||
ncvAssertReturn(h_vecDst_d.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_vecSrc), false);
|
||||
for (Ncv32u i=0; i<this->length; i++)
|
||||
{
|
||||
Ncv32u tmp = (h_vecSrc.ptr()[i]) & 0xFF;
|
||||
tmp = tmp * 99 / 255;
|
||||
if (tmp < this->badElemPercentage)
|
||||
{
|
||||
h_vecSrc.ptr()[i] = this->badElem;
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_dstLen(*this->allocatorCPU.get(), 1);
|
||||
ncvAssertReturn(h_dstLen.isMemAllocated(), false);
|
||||
Ncv32u bufSize;
|
||||
ncvStat = nppsStCompactGetSize_32u(this->length, &bufSize, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
|
||||
ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
|
||||
|
||||
Ncv32u h_outElemNum_h = 0;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvStat = h_vecSrc.copySolid(d_vecSrc, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
ncvStat = nppsStCompact_32u(d_vecSrc.ptr(), this->length,
|
||||
d_vecDst.ptr(), h_dstLen.ptr(), this->badElem,
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
ncvStat = d_vecDst.copySolid(h_vecDst_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppsStCompact_32u_host(h_vecSrc.ptr(), this->length, h_vecDst.ptr(), &h_outElemNum_h, this->badElem);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (h_dstLen.ptr()[0] != h_outElemNum_h)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_outElemNum_h; i++)
|
||||
{
|
||||
if (h_vecDst.ptr()[i] != h_vecDst_d.ptr()[i])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestCompact::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testhypothesescompact_h_
|
||||
#define _testhypothesescompact_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestCompact : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestCompact(std::string testName, NCVTestSourceProvider<Ncv32u> &src,
|
||||
Ncv32u length, Ncv32u badElem, Ncv32u badElemPercentage);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestCompact(const TestCompact&);
|
||||
TestCompact& operator=(const TestCompact&);
|
||||
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> &src;
|
||||
Ncv32u length;
|
||||
Ncv32u badElem;
|
||||
Ncv32u badElemPercentage;
|
||||
};
|
||||
|
||||
#endif // _testhypothesescompact_h_
|
@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include "TestDrawRects.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
template <class T>
|
||||
TestDrawRects<T>::TestDrawRects(std::string testName, NCVTestSourceProvider<T> &src, NCVTestSourceProvider<Ncv32u> &src32u,
|
||||
Ncv32u width, Ncv32u height, Ncv32u numRects, T color)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
src32u(src32u),
|
||||
width(width),
|
||||
height(height),
|
||||
numRects(numRects),
|
||||
color(color)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestDrawRects<T>::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "sizeof(T)=" << sizeof(T) << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
strOut << "numRects=" << numRects << std::endl;
|
||||
strOut << "color=" << color << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestDrawRects<T>::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestDrawRects<T>::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_img_d(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img_d.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<NcvRect32u> d_rects(*this->allocatorGPU.get(), this->numRects);
|
||||
ncvAssertReturn(d_rects.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> h_rects(*this->allocatorCPU.get(), this->numRects);
|
||||
ncvAssertReturn(h_rects.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
//fill vector of rectangles with random rects covering the input
|
||||
NCVVectorReuse<Ncv32u> h_rects_as32u(h_rects.getSegment());
|
||||
ncvAssertReturn(h_rects_as32u.isMemReused(), false);
|
||||
ncvAssertReturn(this->src32u.fill(h_rects_as32u), false);
|
||||
for (Ncv32u i=0; i<this->numRects; i++)
|
||||
{
|
||||
h_rects.ptr()[i].x = (Ncv32u)(((1.0 * h_rects.ptr()[i].x) / RAND_MAX) * (this->width-2));
|
||||
h_rects.ptr()[i].y = (Ncv32u)(((1.0 * h_rects.ptr()[i].y) / RAND_MAX) * (this->height-2));
|
||||
h_rects.ptr()[i].width = (Ncv32u)(((1.0 * h_rects.ptr()[i].width) / RAND_MAX) * (this->width+10 - h_rects.ptr()[i].x));
|
||||
h_rects.ptr()[i].height = (Ncv32u)(((1.0 * h_rects.ptr()[i].height) / RAND_MAX) * (this->height+10 - h_rects.ptr()[i].y));
|
||||
}
|
||||
ncvStat = h_rects.copySolid(d_rects, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = ncvDrawRects_32u_device((Ncv32u *)d_img.ptr(), d_img.stride(), this->width, this->height,
|
||||
(NcvRect32u *)d_rects.ptr(), this->numRects, this->color, 0);
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = ncvDrawRects_8u_device((Ncv8u *)d_img.ptr(), d_img.stride(), this->width, this->height,
|
||||
(NcvRect32u *)d_rects.ptr(), this->numRects, (Ncv8u)this->color, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect drawrects test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
ncvStat = d_img.copySolid(h_img_d, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = ncvDrawRects_32u_host((Ncv32u *)h_img.ptr(), h_img.stride(), this->width, this->height,
|
||||
(NcvRect32u *)h_rects.ptr(), this->numRects, this->color);
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = ncvDrawRects_8u_host((Ncv8u *)h_img.ptr(), h_img.stride(), this->width, this->height,
|
||||
(NcvRect32u *)h_rects.ptr(), this->numRects, (Ncv8u)this->color);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect drawrects test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
//const Ncv64f relEPS = 0.005;
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_img.height(); i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_img.width(); j++)
|
||||
{
|
||||
if (h_img.ptr()[h_img.stride()*i+j] != h_img_d.ptr()[h_img_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestDrawRects<T>::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template class TestDrawRects<Ncv8u>;
|
||||
template class TestDrawRects<Ncv32u>;
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testdrawrects_h_
|
||||
#define _testdrawrects_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
template <class T>
|
||||
class TestDrawRects : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestDrawRects(std::string testName, NCVTestSourceProvider<T> &src, NCVTestSourceProvider<Ncv32u> &src32u,
|
||||
Ncv32u width, Ncv32u height, Ncv32u numRects, T color);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
|
||||
TestDrawRects(const TestDrawRects&);
|
||||
TestDrawRects& operator=(const TestDrawRects&);
|
||||
|
||||
NCVTestSourceProvider<T> &src;
|
||||
NCVTestSourceProvider<Ncv32u> &src32u;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
Ncv32u numRects;
|
||||
T color;
|
||||
};
|
||||
|
||||
#endif // _testdrawrects_h_
|
@ -1,290 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#include <fpu_control.h>
|
||||
#endif
|
||||
|
||||
#include "TestHaarCascadeApplication.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
TestHaarCascadeApplication::TestHaarCascadeApplication(std::string testName, NCVTestSourceProvider<Ncv8u> &src,
|
||||
std::string cascadeName, Ncv32u width, Ncv32u height)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
cascadeName(cascadeName),
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeApplication::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "cascadeName=" << cascadeName << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeApplication::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeApplication::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32u numStages, numNodes, numFeatures;
|
||||
|
||||
ncvStat = ncvHaarGetClassifierSize(this->cascadeName, numStages, numNodes, numFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
NCVVectorAlloc<HaarStage64> h_HaarStages(*this->allocatorCPU.get(), numStages);
|
||||
ncvAssertReturn(h_HaarStages.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes(*this->allocatorCPU.get(), numNodes);
|
||||
ncvAssertReturn(h_HaarNodes.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarFeature64> h_HaarFeatures(*this->allocatorCPU.get(), numFeatures);
|
||||
ncvAssertReturn(h_HaarFeatures.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<HaarStage64> d_HaarStages(*this->allocatorGPU.get(), numStages);
|
||||
ncvAssertReturn(d_HaarStages.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarClassifierNode128> d_HaarNodes(*this->allocatorGPU.get(), numNodes);
|
||||
ncvAssertReturn(d_HaarNodes.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarFeature64> d_HaarFeatures(*this->allocatorGPU.get(), numFeatures);
|
||||
ncvAssertReturn(d_HaarFeatures.isMemAllocated(), false);
|
||||
|
||||
HaarClassifierCascadeDescriptor haar;
|
||||
haar.ClassifierSize.width = haar.ClassifierSize.height = 1;
|
||||
haar.bNeedsTiltedII = false;
|
||||
haar.NumClassifierRootNodes = numNodes;
|
||||
haar.NumClassifierTotalNodes = numNodes;
|
||||
haar.NumFeatures = numFeatures;
|
||||
haar.NumStages = numStages;
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvStat = ncvHaarLoadFromFile_host(this->cascadeName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
ncvAssertReturn(NCV_SUCCESS == h_HaarStages.copySolid(d_HaarStages, 0), false);
|
||||
ncvAssertReturn(NCV_SUCCESS == h_HaarNodes.copySolid(d_HaarNodes, 0), false);
|
||||
ncvAssertReturn(NCV_SUCCESS == h_HaarFeatures.copySolid(d_HaarFeatures, 0), false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
NcvSize32s srcRoi, srcIIRoi, searchRoi;
|
||||
srcRoi.width = this->width;
|
||||
srcRoi.height = this->height;
|
||||
srcIIRoi.width = srcRoi.width + 1;
|
||||
srcIIRoi.height = srcRoi.height + 1;
|
||||
searchRoi.width = srcIIRoi.width - haar.ClassifierSize.width;
|
||||
searchRoi.height = srcIIRoi.height - haar.ClassifierSize.height;
|
||||
if (searchRoi.width <= 0 || searchRoi.height <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
NcvSize32u searchRoiU(searchRoi.width, searchRoi.height);
|
||||
|
||||
NCVMatrixAlloc<Ncv8u> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv8u> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
|
||||
Ncv32u integralWidth = this->width + 1;
|
||||
Ncv32u integralHeight = this->height + 1;
|
||||
|
||||
NCVMatrixAlloc<Ncv32u> d_integralImage(*this->allocatorGPU.get(), integralWidth, integralHeight);
|
||||
ncvAssertReturn(d_integralImage.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> d_sqIntegralImage(*this->allocatorGPU.get(), integralWidth, integralHeight);
|
||||
ncvAssertReturn(d_sqIntegralImage.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32u> h_integralImage(*this->allocatorCPU.get(), integralWidth, integralHeight);
|
||||
ncvAssertReturn(h_integralImage.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> h_sqIntegralImage(*this->allocatorCPU.get(), integralWidth, integralHeight);
|
||||
ncvAssertReturn(h_sqIntegralImage.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<Ncv32f> d_rectStdDev(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_rectStdDev.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32u> d_pixelMask(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_pixelMask.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32f> h_rectStdDev(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_rectStdDev.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32u> h_pixelMask(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_pixelMask.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<NcvRect32u> d_hypotheses(*this->allocatorGPU.get(), this->width * this->height);
|
||||
ncvAssertReturn(d_hypotheses.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> h_hypotheses(*this->allocatorCPU.get(), this->width * this->height);
|
||||
ncvAssertReturn(h_hypotheses.isMemAllocated(), false);
|
||||
|
||||
NCVStatus nppStat;
|
||||
Ncv32u szTmpBufIntegral, szTmpBufSqIntegral;
|
||||
nppStat = nppiStIntegralGetSize_8u32u(NcvSize32u(this->width, this->height), &szTmpBufIntegral, this->devProp);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
nppStat = nppiStSqrIntegralGetSize_8u64u(NcvSize32u(this->width, this->height), &szTmpBufSqIntegral, this->devProp);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
NCVVectorAlloc<Ncv8u> d_tmpIIbuf(*this->allocatorGPU.get(), std::max(szTmpBufIntegral, szTmpBufSqIntegral));
|
||||
ncvAssertReturn(d_tmpIIbuf.isMemAllocated(), false);
|
||||
|
||||
Ncv32u detectionsOnThisScale_d = 0;
|
||||
Ncv32u detectionsOnThisScale_h = 0;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
nppStat = nppiStIntegral_8u32u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_integralImage.ptr(), d_integralImage.pitch(),
|
||||
NcvSize32u(d_img.width(), d_img.height()),
|
||||
d_tmpIIbuf.ptr(), szTmpBufIntegral, this->devProp);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
|
||||
nppStat = nppiStSqrIntegral_8u64u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_sqIntegralImage.ptr(), d_sqIntegralImage.pitch(),
|
||||
NcvSize32u(d_img.width(), d_img.height()),
|
||||
d_tmpIIbuf.ptr(), szTmpBufSqIntegral, this->devProp);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
|
||||
const NcvRect32u rect(
|
||||
HAAR_STDDEV_BORDER,
|
||||
HAAR_STDDEV_BORDER,
|
||||
haar.ClassifierSize.width - 2*HAAR_STDDEV_BORDER,
|
||||
haar.ClassifierSize.height - 2*HAAR_STDDEV_BORDER);
|
||||
nppStat = nppiStRectStdDev_32f_C1R(
|
||||
d_integralImage.ptr(), d_integralImage.pitch(),
|
||||
d_sqIntegralImage.ptr(), d_sqIntegralImage.pitch(),
|
||||
d_rectStdDev.ptr(), d_rectStdDev.pitch(),
|
||||
NcvSize32u(searchRoi.width, searchRoi.height), rect,
|
||||
1.0f, true);
|
||||
ncvAssertReturn(nppStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = d_integralImage.copySolid(h_integralImage, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvStat = d_rectStdDev.copySolid(h_rectStdDev, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
for (Ncv32u i=0; i<searchRoiU.height; i++)
|
||||
{
|
||||
for (Ncv32u j=0; j<h_pixelMask.stride(); j++)
|
||||
{
|
||||
if (j<searchRoiU.width)
|
||||
{
|
||||
h_pixelMask.ptr()[i*h_pixelMask.stride()+j] = (i << 16) | j;
|
||||
}
|
||||
else
|
||||
{
|
||||
h_pixelMask.ptr()[i*h_pixelMask.stride()+j] = OBJDET_MASK_ELEMENT_INVALID_32U;
|
||||
}
|
||||
}
|
||||
}
|
||||
ncvAssertReturn(cudaSuccess == cudaStreamSynchronize(0), false);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
//http://www.christian-seiler.de/projekte/fpmath/
|
||||
|
||||
fpu_control_t fpu_oldcw, fpu_cw;
|
||||
_FPU_GETCW(fpu_oldcw); // store old cw
|
||||
fpu_cw = (fpu_oldcw & ~_FPU_EXTENDED & ~_FPU_DOUBLE & ~_FPU_SINGLE) | _FPU_SINGLE;
|
||||
_FPU_SETCW(fpu_cw);
|
||||
|
||||
// calculations here
|
||||
ncvStat = ncvApplyHaarClassifierCascade_host(
|
||||
h_integralImage, h_rectStdDev, h_pixelMask,
|
||||
detectionsOnThisScale_h,
|
||||
haar, h_HaarStages, h_HaarNodes, h_HaarFeatures, false,
|
||||
searchRoiU, 1, 1.0f);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
_FPU_SETCW(fpu_oldcw); // restore old cw
|
||||
#else
|
||||
Ncv32u fpu_oldcw, fpu_cw;
|
||||
_controlfp_s(&fpu_cw, 0, 0);
|
||||
fpu_oldcw = fpu_cw;
|
||||
_controlfp_s(&fpu_cw, _PC_24, _MCW_PC);
|
||||
ncvStat = ncvApplyHaarClassifierCascade_host(
|
||||
h_integralImage, h_rectStdDev, h_pixelMask,
|
||||
detectionsOnThisScale_h,
|
||||
haar, h_HaarStages, h_HaarNodes, h_HaarFeatures, false,
|
||||
searchRoiU, 1, 1.0f);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
_controlfp_s(&fpu_cw, fpu_oldcw, _MCW_PC);
|
||||
#endif
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
int devId;
|
||||
ncvAssertCUDAReturn(cudaGetDevice(&devId), false);
|
||||
cudaDeviceProp devProp;
|
||||
ncvAssertCUDAReturn(cudaGetDeviceProperties(&devProp, devId), false);
|
||||
|
||||
ncvStat = ncvApplyHaarClassifierCascade_device(
|
||||
d_integralImage, d_rectStdDev, d_pixelMask,
|
||||
detectionsOnThisScale_d,
|
||||
haar, h_HaarStages, d_HaarStages, d_HaarNodes, d_HaarFeatures, false,
|
||||
searchRoiU, 1, 1.0f,
|
||||
*this->allocatorGPU.get(), *this->allocatorCPU.get(),
|
||||
devProp, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
NCVMatrixAlloc<Ncv32u> h_pixelMask_d(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_pixelMask_d.isMemAllocated(), false);
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvStat = d_pixelMask.copySolid(h_pixelMask_d, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
if (detectionsOnThisScale_d != detectionsOnThisScale_h)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::sort(h_pixelMask_d.ptr(), h_pixelMask_d.ptr() + detectionsOnThisScale_d);
|
||||
for (Ncv32u i=0; i<detectionsOnThisScale_d && bLoopVirgin; i++)
|
||||
{
|
||||
if (h_pixelMask.ptr()[i] != h_pixelMask_d.ptr()[i])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeApplication::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testhaarcascadeapplication_h_
|
||||
#define _testhaarcascadeapplication_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestHaarCascadeApplication : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestHaarCascadeApplication(std::string testName, NCVTestSourceProvider<Ncv8u> &src,
|
||||
std::string cascadeName, Ncv32u width, Ncv32u height);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestHaarCascadeApplication(const TestHaarCascadeApplication&);
|
||||
TestHaarCascadeApplication& operator=(const TestHaarCascadeApplication&);
|
||||
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> &src;
|
||||
std::string cascadeName;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
};
|
||||
|
||||
#endif // _testhaarcascadeapplication_h_
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include "TestHaarCascadeLoader.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
TestHaarCascadeLoader::TestHaarCascadeLoader(std::string testName, std::string cascadeName)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
cascadeName(cascadeName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeLoader::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "cascadeName=" << cascadeName << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeLoader::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeLoader::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32u numStages, numNodes, numFeatures;
|
||||
Ncv32u numStages_2 = 0, numNodes_2 = 0, numFeatures_2 = 0;
|
||||
|
||||
ncvStat = ncvHaarGetClassifierSize(this->cascadeName, numStages, numNodes, numFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
NCVVectorAlloc<HaarStage64> h_HaarStages(*this->allocatorCPU.get(), numStages);
|
||||
ncvAssertReturn(h_HaarStages.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes(*this->allocatorCPU.get(), numNodes);
|
||||
ncvAssertReturn(h_HaarNodes.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarFeature64> h_HaarFeatures(*this->allocatorCPU.get(), numFeatures);
|
||||
ncvAssertReturn(h_HaarFeatures.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<HaarStage64> h_HaarStages_2(*this->allocatorCPU.get(), numStages);
|
||||
ncvAssertReturn(h_HaarStages_2.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes_2(*this->allocatorCPU.get(), numNodes);
|
||||
ncvAssertReturn(h_HaarNodes_2.isMemAllocated(), false);
|
||||
NCVVectorAlloc<HaarFeature64> h_HaarFeatures_2(*this->allocatorCPU.get(), numFeatures);
|
||||
ncvAssertReturn(h_HaarFeatures_2.isMemAllocated(), false);
|
||||
|
||||
HaarClassifierCascadeDescriptor haar;
|
||||
HaarClassifierCascadeDescriptor haar_2;
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
const std::string testNvbinName = "test.nvbin";
|
||||
ncvStat = ncvHaarLoadFromFile_host(this->cascadeName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
ncvStat = ncvHaarStoreNVBIN_host(testNvbinName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
ncvStat = ncvHaarGetClassifierSize(testNvbinName, numStages_2, numNodes_2, numFeatures_2);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
ncvStat = ncvHaarLoadFromFile_host(testNvbinName, haar_2, h_HaarStages_2, h_HaarNodes_2, h_HaarFeatures_2);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
if (
|
||||
numStages_2 != numStages ||
|
||||
numNodes_2 != numNodes ||
|
||||
numFeatures_2 != numFeatures ||
|
||||
haar.NumStages != haar_2.NumStages ||
|
||||
haar.NumClassifierRootNodes != haar_2.NumClassifierRootNodes ||
|
||||
haar.NumClassifierTotalNodes != haar_2.NumClassifierTotalNodes ||
|
||||
haar.NumFeatures != haar_2.NumFeatures ||
|
||||
haar.ClassifierSize.width != haar_2.ClassifierSize.width ||
|
||||
haar.ClassifierSize.height != haar_2.ClassifierSize.height ||
|
||||
haar.bNeedsTiltedII != haar_2.bNeedsTiltedII ||
|
||||
haar.bHasStumpsOnly != haar_2.bHasStumpsOnly )
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
if (memcmp(h_HaarStages.ptr(), h_HaarStages_2.ptr(), haar.NumStages * sizeof(HaarStage64)) ||
|
||||
memcmp(h_HaarNodes.ptr(), h_HaarNodes_2.ptr(), haar.NumClassifierTotalNodes * sizeof(HaarClassifierNode128)) ||
|
||||
memcmp(h_HaarFeatures.ptr(), h_HaarFeatures_2.ptr(), haar.NumFeatures * sizeof(HaarFeature64)) )
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestHaarCascadeLoader::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testhaarcascadeloader_h_
|
||||
#define _testhaarcascadeloader_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestHaarCascadeLoader : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestHaarCascadeLoader(std::string testName, std::string cascadeName);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
|
||||
std::string cascadeName;
|
||||
};
|
||||
|
||||
#endif // _testhaarcascadeloader_h_
|
@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include "TestHypothesesFilter.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
TestHypothesesFilter::TestHypothesesFilter(std::string testName, NCVTestSourceProvider<Ncv32u> &src,
|
||||
Ncv32u numDstRects, Ncv32u minNeighbors, Ncv32f eps)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
numDstRects(numDstRects),
|
||||
minNeighbors(minNeighbors),
|
||||
eps(eps)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesFilter::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "numDstRects=" << numDstRects << std::endl;
|
||||
strOut << "minNeighbors=" << minNeighbors << std::endl;
|
||||
strOut << "eps=" << eps << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesFilter::init()
|
||||
{
|
||||
this->canvasWidth = 4096;
|
||||
this->canvasHeight = 4096;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool compareRects(const NcvRect32u &r1, const NcvRect32u &r2, Ncv32f eps)
|
||||
{
|
||||
double delta = eps*(std::min(r1.width, r2.width) + std::min(r1.height, r2.height))*0.5;
|
||||
return std::abs((Ncv32s)r1.x - (Ncv32s)r2.x) <= delta &&
|
||||
std::abs((Ncv32s)r1.y - (Ncv32s)r2.y) <= delta &&
|
||||
std::abs((Ncv32s)r1.x + (Ncv32s)r1.width - (Ncv32s)r2.x - (Ncv32s)r2.width) <= delta &&
|
||||
std::abs((Ncv32s)r1.y + (Ncv32s)r1.height - (Ncv32s)r2.y - (Ncv32s)r2.height) <= delta;
|
||||
}
|
||||
|
||||
|
||||
inline bool operator < (const NcvRect32u &a, const NcvRect32u &b)
|
||||
{
|
||||
return a.x < b.x;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesFilter::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_random32u(*this->allocatorCPU.get(), this->numDstRects * sizeof(NcvRect32u) / sizeof(Ncv32u));
|
||||
ncvAssertReturn(h_random32u.isMemAllocated(), false);
|
||||
|
||||
Ncv32u srcSlotSize = 2 * this->minNeighbors + 1;
|
||||
|
||||
NCVVectorAlloc<NcvRect32u> h_vecSrc(*this->allocatorCPU.get(), this->numDstRects*srcSlotSize);
|
||||
ncvAssertReturn(h_vecSrc.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> h_vecDst_groundTruth(*this->allocatorCPU.get(), this->numDstRects);
|
||||
ncvAssertReturn(h_vecDst_groundTruth.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorCPU.get()->isCounting());
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_random32u), false);
|
||||
Ncv32u randCnt = 0;
|
||||
Ncv64f randVal;
|
||||
|
||||
for (Ncv32u i=0; i<this->numDstRects; i++)
|
||||
{
|
||||
h_vecDst_groundTruth.ptr()[i].x = i * this->canvasWidth / this->numDstRects + this->canvasWidth / (this->numDstRects * 4);
|
||||
h_vecDst_groundTruth.ptr()[i].y = i * this->canvasHeight / this->numDstRects + this->canvasHeight / (this->numDstRects * 4);
|
||||
h_vecDst_groundTruth.ptr()[i].width = this->canvasWidth / (this->numDstRects * 2);
|
||||
h_vecDst_groundTruth.ptr()[i].height = this->canvasHeight / (this->numDstRects * 2);
|
||||
|
||||
Ncv32u numNeighbors = this->minNeighbors + 1 + (Ncv32u)(((1.0 * h_random32u.ptr()[i]) * (this->minNeighbors + 1)) / 0xFFFFFFFF);
|
||||
numNeighbors = (numNeighbors > srcSlotSize) ? srcSlotSize : numNeighbors;
|
||||
|
||||
//fill in strong hypotheses (2 * ((1.0 * randVal) / 0xFFFFFFFF) - 1)
|
||||
for (Ncv32u j=0; j<numNeighbors; j++)
|
||||
{
|
||||
randVal = (1.0 * h_random32u.ptr()[randCnt++]) / 0xFFFFFFFF; randCnt = randCnt % h_random32u.length();
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].x =
|
||||
h_vecDst_groundTruth.ptr()[i].x +
|
||||
(Ncv32s)(h_vecDst_groundTruth.ptr()[i].width * this->eps * (randVal - 0.5));
|
||||
randVal = (1.0 * h_random32u.ptr()[randCnt++]) / 0xFFFFFFFF; randCnt = randCnt % h_random32u.length();
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].y =
|
||||
h_vecDst_groundTruth.ptr()[i].y +
|
||||
(Ncv32s)(h_vecDst_groundTruth.ptr()[i].height * this->eps * (randVal - 0.5));
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].width = h_vecDst_groundTruth.ptr()[i].width;
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].height = h_vecDst_groundTruth.ptr()[i].height;
|
||||
}
|
||||
|
||||
//generate weak hypotheses (to be removed in processing)
|
||||
for (Ncv32u j=numNeighbors; j<srcSlotSize; j++)
|
||||
{
|
||||
randVal = (1.0 * h_random32u.ptr()[randCnt++]) / 0xFFFFFFFF; randCnt = randCnt % h_random32u.length();
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].x =
|
||||
this->canvasWidth + h_vecDst_groundTruth.ptr()[i].x +
|
||||
(Ncv32s)(h_vecDst_groundTruth.ptr()[i].width * this->eps * (randVal - 0.5));
|
||||
randVal = (1.0 * h_random32u.ptr()[randCnt++]) / 0xFFFFFFFF; randCnt = randCnt % h_random32u.length();
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].y =
|
||||
this->canvasHeight + h_vecDst_groundTruth.ptr()[i].y +
|
||||
(Ncv32s)(h_vecDst_groundTruth.ptr()[i].height * this->eps * (randVal - 0.5));
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].width = h_vecDst_groundTruth.ptr()[i].width;
|
||||
h_vecSrc.ptr()[srcSlotSize * i + j].height = h_vecDst_groundTruth.ptr()[i].height;
|
||||
}
|
||||
}
|
||||
|
||||
//shuffle
|
||||
for (Ncv32u i=0; i<this->numDstRects*srcSlotSize-1; i++)
|
||||
{
|
||||
Ncv32u randVal = h_random32u.ptr()[randCnt++]; randCnt = randCnt % h_random32u.length();
|
||||
Ncv32u secondSwap = randVal % (this->numDstRects*srcSlotSize-1 - i);
|
||||
NcvRect32u tmp = h_vecSrc.ptr()[i + secondSwap];
|
||||
h_vecSrc.ptr()[i + secondSwap] = h_vecSrc.ptr()[i];
|
||||
h_vecSrc.ptr()[i] = tmp;
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
Ncv32u numHypothesesSrc = h_vecSrc.length();
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvStat = ncvFilterHypotheses_host(h_vecSrc, numHypothesesSrc, this->minNeighbors, this->eps, NULL);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//verification
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (numHypothesesSrc != this->numDstRects)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<NcvRect32u> tmpRects(numHypothesesSrc);
|
||||
memcpy(&tmpRects[0], h_vecSrc.ptr(), numHypothesesSrc * sizeof(NcvRect32u));
|
||||
std::sort(tmpRects.begin(), tmpRects.end());
|
||||
for (Ncv32u i=0; i<numHypothesesSrc && bLoopVirgin; i++)
|
||||
{
|
||||
if (!compareRects(tmpRects[i], h_vecDst_groundTruth.ptr()[i], this->eps))
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesFilter::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testhypothesesfilter_h_
|
||||
#define _testhypothesesfilter_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestHypothesesFilter : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestHypothesesFilter(std::string testName, NCVTestSourceProvider<Ncv32u> &src,
|
||||
Ncv32u numDstRects, Ncv32u minNeighbors, Ncv32f eps);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
|
||||
TestHypothesesFilter(const TestHypothesesFilter&);
|
||||
TestHypothesesFilter& operator=(const TestHypothesesFilter&);
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> &src;
|
||||
Ncv32u numDstRects;
|
||||
Ncv32u minNeighbors;
|
||||
Ncv32f eps;
|
||||
|
||||
Ncv32u canvasWidth;
|
||||
Ncv32u canvasHeight;
|
||||
};
|
||||
|
||||
#endif // _testhypothesesfilter_h_
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include "TestHypothesesGrow.h"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
|
||||
TestHypothesesGrow::TestHypothesesGrow(std::string testName, NCVTestSourceProvider<Ncv32u> &src,
|
||||
Ncv32u rectWidth, Ncv32u rectHeight, Ncv32f rectScale,
|
||||
Ncv32u maxLenSrc, Ncv32u lenSrc, Ncv32u maxLenDst, Ncv32u lenDst)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
rectWidth(rectWidth),
|
||||
rectHeight(rectHeight),
|
||||
rectScale(rectScale),
|
||||
maxLenSrc(maxLenSrc),
|
||||
lenSrc(lenSrc),
|
||||
maxLenDst(maxLenDst),
|
||||
lenDst(lenDst)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesGrow::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "rectWidth=" << rectWidth << std::endl;
|
||||
strOut << "rectHeight=" << rectHeight << std::endl;
|
||||
strOut << "rectScale=" << rectScale << std::endl;
|
||||
strOut << "maxLenSrc=" << maxLenSrc << std::endl;
|
||||
strOut << "lenSrc=" << lenSrc << std::endl;
|
||||
strOut << "maxLenDst=" << maxLenDst << std::endl;
|
||||
strOut << "lenDst=" << lenDst << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesGrow::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesGrow::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NCVVectorAlloc<Ncv32u> h_vecSrc(*this->allocatorCPU.get(), this->maxLenSrc);
|
||||
ncvAssertReturn(h_vecSrc.isMemAllocated(), false);
|
||||
NCVVectorAlloc<Ncv32u> d_vecSrc(*this->allocatorGPU.get(), this->maxLenSrc);
|
||||
ncvAssertReturn(d_vecSrc.isMemAllocated(), false);
|
||||
|
||||
NCVVectorAlloc<NcvRect32u> h_vecDst(*this->allocatorCPU.get(), this->maxLenDst);
|
||||
ncvAssertReturn(h_vecDst.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> d_vecDst(*this->allocatorGPU.get(), this->maxLenDst);
|
||||
ncvAssertReturn(d_vecDst.isMemAllocated(), false);
|
||||
NCVVectorAlloc<NcvRect32u> h_vecDst_d(*this->allocatorCPU.get(), this->maxLenDst);
|
||||
ncvAssertReturn(h_vecDst_d.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_vecSrc), false);
|
||||
memset(h_vecDst.ptr(), 0, h_vecDst.length() * sizeof(NcvRect32u));
|
||||
NCVVectorReuse<Ncv32u> h_vecDst_as32u(h_vecDst.getSegment(), lenDst * sizeof(NcvRect32u) / sizeof(Ncv32u));
|
||||
ncvAssertReturn(h_vecDst_as32u.isMemReused(), false);
|
||||
ncvAssertReturn(this->src.fill(h_vecDst_as32u), false);
|
||||
memcpy(h_vecDst_d.ptr(), h_vecDst.ptr(), h_vecDst.length() * sizeof(NcvRect32u));
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
ncvStat = h_vecSrc.copySolid(d_vecSrc, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvStat = h_vecDst.copySolid(d_vecDst, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
Ncv32u h_outElemNum_d = 0;
|
||||
Ncv32u h_outElemNum_h = 0;
|
||||
NCV_SKIP_COND_BEGIN
|
||||
h_outElemNum_d = this->lenDst;
|
||||
ncvStat = ncvGrowDetectionsVector_device(d_vecSrc, this->lenSrc,
|
||||
d_vecDst, h_outElemNum_d, this->maxLenDst,
|
||||
this->rectWidth, this->rectHeight, this->rectScale, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvStat = d_vecDst.copySolid(h_vecDst_d, 0);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
ncvAssertCUDAReturn(cudaStreamSynchronize(0), false);
|
||||
|
||||
h_outElemNum_h = this->lenDst;
|
||||
ncvStat = ncvGrowDetectionsVector_host(h_vecSrc, this->lenSrc,
|
||||
h_vecDst, h_outElemNum_h, this->maxLenDst,
|
||||
this->rectWidth, this->rectHeight, this->rectScale);
|
||||
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (h_outElemNum_d != h_outElemNum_h)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (memcmp(h_vecDst.ptr(), h_vecDst_d.ptr(), this->maxLenDst * sizeof(NcvRect32u)))
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestHypothesesGrow::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testhypothesesgrow_h_
|
||||
#define _testhypothesesgrow_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestHypothesesGrow : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestHypothesesGrow(std::string testName, NCVTestSourceProvider<Ncv32u> &src,
|
||||
Ncv32u rectWidth, Ncv32u rectHeight, Ncv32f rectScale,
|
||||
Ncv32u maxLenSrc, Ncv32u lenSrc, Ncv32u maxLenDst, Ncv32u lenDst);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestHypothesesGrow(const TestHypothesesGrow&);
|
||||
TestHypothesesGrow& operator=(const TestHypothesesGrow&);
|
||||
|
||||
|
||||
NCVTestSourceProvider<Ncv32u> &src;
|
||||
Ncv32u rectWidth;
|
||||
Ncv32u rectHeight;
|
||||
Ncv32f rectScale;
|
||||
Ncv32u maxLenSrc;
|
||||
Ncv32u lenSrc;
|
||||
Ncv32u maxLenDst;
|
||||
Ncv32u lenDst;
|
||||
};
|
||||
|
||||
#endif // _testhypothesesgrow_h_
|
@ -1,185 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "TestIntegralImage.h"
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
TestIntegralImage<T_in, T_out>::TestIntegralImage(std::string testName, NCVTestSourceProvider<T_in> &src,
|
||||
Ncv32u width, Ncv32u height)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
bool TestIntegralImage<T_in, T_out>::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "sizeof(T_in)=" << sizeof(T_in) << std::endl;
|
||||
strOut << "sizeof(T_out)=" << sizeof(T_out) << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
bool TestIntegralImage<T_in, T_out>::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
bool TestIntegralImage<T_in, T_out>::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32u widthII = this->width + 1;
|
||||
Ncv32u heightII = this->height + 1;
|
||||
|
||||
NCVMatrixAlloc<T_in> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T_in> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T_out> d_imgII(*this->allocatorGPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(d_imgII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T_out> h_imgII(*this->allocatorCPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(h_imgII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T_out> h_imgII_d(*this->allocatorCPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(h_imgII_d.isMemAllocated(), false);
|
||||
|
||||
Ncv32u bufSize;
|
||||
if (sizeof(T_in) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = nppiStIntegralGetSize_8u32u(NcvSize32u(this->width, this->height), &bufSize, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
}
|
||||
else if (sizeof(T_in) == sizeof(Ncv32f))
|
||||
{
|
||||
ncvStat = nppiStIntegralGetSize_32f32f(NcvSize32u(this->width, this->height), &bufSize, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
|
||||
}
|
||||
|
||||
NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
|
||||
ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
if (sizeof(T_in) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = nppiStIntegral_8u32u_C1R((Ncv8u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv32u *)d_imgII.ptr(), d_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
}
|
||||
else if (sizeof(T_in) == sizeof(Ncv32f))
|
||||
{
|
||||
ncvStat = nppiStIntegral_32f32f_C1R((Ncv32f *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv32f *)d_imgII.ptr(), d_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
|
||||
}
|
||||
|
||||
ncvStat = d_imgII.copySolid(h_imgII_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
if (sizeof(T_in) == sizeof(Ncv8u))
|
||||
{
|
||||
ncvStat = nppiStIntegral_8u32u_C1R_host((Ncv8u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv32u *)h_imgII.ptr(), h_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
}
|
||||
else if (sizeof(T_in) == sizeof(Ncv32f))
|
||||
{
|
||||
ncvStat = nppiStIntegral_32f32f_C1R_host((Ncv32f *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv32f *)h_imgII.ptr(), h_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
|
||||
}
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_img.height() + 1; i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_img.width() + 1; j++)
|
||||
{
|
||||
if (sizeof(T_in) == sizeof(Ncv8u))
|
||||
{
|
||||
if (h_imgII.ptr()[h_imgII.stride()*i+j] != h_imgII_d.ptr()[h_imgII_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
else if (sizeof(T_in) == sizeof(Ncv32f))
|
||||
{
|
||||
if (fabsf((float)h_imgII.ptr()[h_imgII.stride()*i+j] - (float)h_imgII_d.ptr()[h_imgII_d.stride()*i+j]) > 0.01f)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect integral image test instance", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
bool TestIntegralImage<T_in, T_out>::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template class TestIntegralImage<Ncv8u, Ncv32u>;
|
||||
template class TestIntegralImage<Ncv32f, Ncv32f>;
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testintegralimage_h_
|
||||
#define _testintegralimage_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
class TestIntegralImage : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestIntegralImage(std::string testName, NCVTestSourceProvider<T_in> &src,
|
||||
Ncv32u width, Ncv32u height);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestIntegralImage(const TestIntegralImage&);
|
||||
TestIntegralImage& operator=(const TestIntegralImage&);
|
||||
|
||||
NCVTestSourceProvider<T_in> &src;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
};
|
||||
|
||||
#endif // _testintegralimage_h_
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include "TestIntegralImageSquared.h"
|
||||
|
||||
|
||||
TestIntegralImageSquared::TestIntegralImageSquared(std::string testName, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u width, Ncv32u height)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestIntegralImageSquared::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestIntegralImageSquared::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestIntegralImageSquared::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32u widthSII = this->width + 1;
|
||||
Ncv32u heightSII = this->height + 1;
|
||||
|
||||
NCVMatrixAlloc<Ncv8u> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv8u> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> d_imgSII(*this->allocatorGPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(d_imgSII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> h_imgSII(*this->allocatorCPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(h_imgSII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> h_imgSII_d(*this->allocatorCPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(h_imgSII_d.isMemAllocated(), false);
|
||||
|
||||
Ncv32u bufSize;
|
||||
ncvStat = nppiStSqrIntegralGetSize_8u64u(NcvSize32u(this->width, this->height), &bufSize, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
|
||||
ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStSqrIntegral_8u64u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_imgSII.ptr(), d_imgSII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = d_imgSII.copySolid(h_imgSII_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStSqrIntegral_8u64u_C1R_host(h_img.ptr(), h_img.pitch(),
|
||||
h_imgSII.ptr(), h_imgSII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_img.height() + 1; i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_img.width() + 1; j++)
|
||||
{
|
||||
if (h_imgSII.ptr()[h_imgSII.stride()*i+j] != h_imgSII_d.ptr()[h_imgSII_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestIntegralImageSquared::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testintegralimagesquared_h_
|
||||
#define _testintegralimagesquared_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestIntegralImageSquared : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestIntegralImageSquared(std::string testName, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u width, Ncv32u height);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestIntegralImageSquared(const TestIntegralImageSquared&);
|
||||
TestIntegralImageSquared& operator=(const TestIntegralImageSquared&);
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> &src;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
};
|
||||
|
||||
#endif // _testintegralimagesquared_h_
|
@ -1,180 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "TestRectStdDev.h"
|
||||
|
||||
|
||||
TestRectStdDev::TestRectStdDev(std::string testName, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u width, Ncv32u height, NcvRect32u rect, Ncv32f scaleFactor,
|
||||
NcvBool bTextureCache)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
width(width),
|
||||
height(height),
|
||||
rect(rect),
|
||||
scaleFactor(scaleFactor),
|
||||
bTextureCache(bTextureCache)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool TestRectStdDev::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "height=" << height << std::endl;
|
||||
strOut << "rect=[" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << "]\n";
|
||||
strOut << "scaleFactor=" << scaleFactor << std::endl;
|
||||
strOut << "bTextureCache=" << bTextureCache << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestRectStdDev::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TestRectStdDev::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32s _normWidth = (Ncv32s)this->width - this->rect.x - this->rect.width + 1;
|
||||
Ncv32s _normHeight = (Ncv32s)this->height - this->rect.y - this->rect.height + 1;
|
||||
if (_normWidth <= 0 || _normHeight <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
Ncv32u normWidth = (Ncv32u)_normWidth;
|
||||
Ncv32u normHeight = (Ncv32u)_normHeight;
|
||||
NcvSize32u szNormRoi(normWidth, normHeight);
|
||||
|
||||
Ncv32u widthII = this->width + 1;
|
||||
Ncv32u heightII = this->height + 1;
|
||||
Ncv32u widthSII = this->width + 1;
|
||||
Ncv32u heightSII = this->height + 1;
|
||||
|
||||
NCVMatrixAlloc<Ncv8u> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv8u> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<Ncv32u> d_imgII(*this->allocatorGPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(d_imgII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32u> h_imgII(*this->allocatorCPU.get(), widthII, heightII);
|
||||
ncvAssertReturn(h_imgII.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<Ncv64u> d_imgSII(*this->allocatorGPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(d_imgSII.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv64u> h_imgSII(*this->allocatorCPU.get(), widthSII, heightSII);
|
||||
ncvAssertReturn(h_imgSII.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<Ncv32f> d_norm(*this->allocatorGPU.get(), normWidth, normHeight);
|
||||
ncvAssertReturn(d_norm.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32f> h_norm(*this->allocatorCPU.get(), normWidth, normHeight);
|
||||
ncvAssertReturn(h_norm.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<Ncv32f> h_norm_d(*this->allocatorCPU.get(), normWidth, normHeight);
|
||||
ncvAssertReturn(h_norm_d.isMemAllocated(), false);
|
||||
|
||||
Ncv32u bufSizeII, bufSizeSII;
|
||||
ncvStat = nppiStIntegralGetSize_8u32u(NcvSize32u(this->width, this->height), &bufSizeII, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
ncvStat = nppiStSqrIntegralGetSize_8u64u(NcvSize32u(this->width, this->height), &bufSizeSII, this->devProp);
|
||||
ncvAssertReturn(NPPST_SUCCESS == ncvStat, false);
|
||||
Ncv32u bufSize = bufSizeII > bufSizeSII ? bufSizeII : bufSizeSII;
|
||||
NCVVectorAlloc<Ncv8u> d_tmpBuf(*this->allocatorGPU.get(), bufSize);
|
||||
ncvAssertReturn(d_tmpBuf.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStIntegral_8u32u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_imgII.ptr(), d_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStSqrIntegral_8u64u_C1R(d_img.ptr(), d_img.pitch(),
|
||||
d_imgSII.ptr(), d_imgSII.pitch(),
|
||||
NcvSize32u(this->width, this->height),
|
||||
d_tmpBuf.ptr(), bufSize, this->devProp);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStRectStdDev_32f_C1R(d_imgII.ptr(), d_imgII.pitch(),
|
||||
d_imgSII.ptr(), d_imgSII.pitch(),
|
||||
d_norm.ptr(), d_norm.pitch(),
|
||||
szNormRoi, this->rect,
|
||||
this->scaleFactor,
|
||||
this->bTextureCache);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = d_norm.copySolid(h_norm_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStIntegral_8u32u_C1R_host(h_img.ptr(), h_img.pitch(),
|
||||
h_imgII.ptr(), h_imgII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStSqrIntegral_8u64u_C1R_host(h_img.ptr(), h_img.pitch(),
|
||||
h_imgSII.ptr(), h_imgSII.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
ncvStat = nppiStRectStdDev_32f_C1R_host(h_imgII.ptr(), h_imgII.pitch(),
|
||||
h_imgSII.ptr(), h_imgSII.pitch(),
|
||||
h_norm.ptr(), h_norm.pitch(),
|
||||
szNormRoi, this->rect,
|
||||
this->scaleFactor);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
const Ncv64f relEPS = 0.005;
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_norm.height(); i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_norm.width(); j++)
|
||||
{
|
||||
Ncv64f absErr = fabs(h_norm.ptr()[h_norm.stride()*i+j] - h_norm_d.ptr()[h_norm_d.stride()*i+j]);
|
||||
Ncv64f relErr = absErr / h_norm.ptr()[h_norm.stride()*i+j];
|
||||
|
||||
if (relErr > relEPS)
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
bool TestRectStdDev::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testrectstddev_h_
|
||||
#define _testrectstddev_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
class TestRectStdDev : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestRectStdDev(std::string testName, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u width, Ncv32u height, NcvRect32u rect, Ncv32f scaleFactor,
|
||||
NcvBool bTextureCache);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestRectStdDev(const TestRectStdDev&);
|
||||
TestRectStdDev& operator=(const TestRectStdDev&);
|
||||
|
||||
NCVTestSourceProvider<Ncv8u> &src;
|
||||
NcvRect32u rect;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
Ncv32f scaleFactor;
|
||||
|
||||
NcvBool bTextureCache;
|
||||
};
|
||||
|
||||
#endif // _testrectstddev_h_
|
@ -1,161 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "TestResize.h"
|
||||
|
||||
|
||||
template <class T>
|
||||
TestResize<T>::TestResize(std::string testName, NCVTestSourceProvider<T> &src,
|
||||
Ncv32u width, Ncv32u height, Ncv32u scaleFactor, NcvBool bTextureCache)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
width(width),
|
||||
height(height),
|
||||
scaleFactor(scaleFactor),
|
||||
bTextureCache(bTextureCache)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestResize<T>::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "sizeof(T)=" << sizeof(T) << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
strOut << "scaleFactor=" << scaleFactor << std::endl;
|
||||
strOut << "bTextureCache=" << bTextureCache << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestResize<T>::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestResize<T>::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
Ncv32s smallWidth = this->width / this->scaleFactor;
|
||||
Ncv32s smallHeight = this->height / this->scaleFactor;
|
||||
if (smallWidth == 0 || smallHeight == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
NcvSize32u srcSize(this->width, this->height);
|
||||
|
||||
NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<T> d_small(*this->allocatorGPU.get(), smallWidth, smallHeight);
|
||||
ncvAssertReturn(d_small.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_small(*this->allocatorCPU.get(), smallWidth, smallHeight);
|
||||
ncvAssertReturn(h_small.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_small_d(*this->allocatorCPU.get(), smallWidth, smallHeight);
|
||||
ncvAssertReturn(h_small_d.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = nppiStDownsampleNearest_32u_C1R((Ncv32u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv32u *)d_small.ptr(), d_small.pitch(),
|
||||
srcSize, this->scaleFactor,
|
||||
this->bTextureCache);
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv64u))
|
||||
{
|
||||
ncvStat = nppiStDownsampleNearest_64u_C1R((Ncv64u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv64u *)d_small.ptr(), d_small.pitch(),
|
||||
srcSize, this->scaleFactor,
|
||||
this->bTextureCache);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
ncvStat = d_small.copySolid(h_small_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = nppiStDownsampleNearest_32u_C1R_host((Ncv32u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv32u *)h_small.ptr(), h_small.pitch(),
|
||||
srcSize, this->scaleFactor);
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv64u))
|
||||
{
|
||||
ncvStat = nppiStDownsampleNearest_64u_C1R_host((Ncv64u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv64u *)h_small.ptr(), h_small.pitch(),
|
||||
srcSize, this->scaleFactor);
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
//const Ncv64f relEPS = 0.005;
|
||||
for (Ncv32u i=0; bLoopVirgin && i < h_small.height(); i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < h_small.width(); j++)
|
||||
{
|
||||
if (h_small.ptr()[h_small.stride()*i+j] != h_small_d.ptr()[h_small_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestResize<T>::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template class TestResize<Ncv32u>;
|
||||
template class TestResize<Ncv64u>;
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testresize_h_
|
||||
#define _testresize_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
template <class T>
|
||||
class TestResize : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestResize(std::string testName, NCVTestSourceProvider<T> &src,
|
||||
Ncv32u width, Ncv32u height, Ncv32u scaleFactor, NcvBool bTextureCache);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
TestResize(const TestResize&);
|
||||
TestResize& operator=(const TestResize&);
|
||||
|
||||
NCVTestSourceProvider<T> &src;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
Ncv32u scaleFactor;
|
||||
|
||||
NcvBool bTextureCache;
|
||||
};
|
||||
|
||||
#endif // _testresize_h_
|
@ -1,148 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "TestTranspose.h"
|
||||
|
||||
|
||||
template <class T>
|
||||
TestTranspose<T>::TestTranspose(std::string testName, NCVTestSourceProvider<T> &src,
|
||||
Ncv32u width, Ncv32u height)
|
||||
:
|
||||
NCVTestProvider(testName),
|
||||
src(src),
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestTranspose<T>::toString(std::ofstream &strOut)
|
||||
{
|
||||
strOut << "sizeof(T)=" << sizeof(T) << std::endl;
|
||||
strOut << "width=" << width << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestTranspose<T>::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestTranspose<T>::process()
|
||||
{
|
||||
NCVStatus ncvStat;
|
||||
bool rcode = false;
|
||||
|
||||
NcvSize32u srcSize(this->width, this->height);
|
||||
|
||||
NCVMatrixAlloc<T> d_img(*this->allocatorGPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(d_img.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_img(*this->allocatorCPU.get(), this->width, this->height);
|
||||
ncvAssertReturn(h_img.isMemAllocated(), false);
|
||||
|
||||
NCVMatrixAlloc<T> d_dst(*this->allocatorGPU.get(), this->height, this->width);
|
||||
ncvAssertReturn(d_dst.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_dst(*this->allocatorCPU.get(), this->height, this->width);
|
||||
ncvAssertReturn(h_dst.isMemAllocated(), false);
|
||||
NCVMatrixAlloc<T> h_dst_d(*this->allocatorCPU.get(), this->height, this->width);
|
||||
ncvAssertReturn(h_dst_d.isMemAllocated(), false);
|
||||
|
||||
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
|
||||
NCV_SKIP_COND_BEGIN
|
||||
ncvAssertReturn(this->src.fill(h_img), false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
ncvStat = h_img.copySolid(d_img, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = nppiStTranspose_32u_C1R((Ncv32u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv32u *)d_dst.ptr(), d_dst.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv64u))
|
||||
{
|
||||
ncvStat = nppiStTranspose_64u_C1R((Ncv64u *)d_img.ptr(), d_img.pitch(),
|
||||
(Ncv64u *)d_dst.ptr(), d_dst.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect transpose test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
ncvStat = d_dst.copySolid(h_dst_d, 0);
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
ncvStat = nppiStTranspose_32u_C1R_host((Ncv32u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv32u *)h_dst.ptr(), h_dst.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv64u))
|
||||
{
|
||||
ncvStat = nppiStTranspose_64u_C1R_host((Ncv64u *)h_img.ptr(), h_img.pitch(),
|
||||
(Ncv64u *)h_dst.ptr(), h_dst.pitch(),
|
||||
NcvSize32u(this->width, this->height));
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintReturn(false, "Incorrect downsample test instance", false);
|
||||
}
|
||||
ncvAssertReturn(ncvStat == NPPST_SUCCESS, false);
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
//bit-to-bit check
|
||||
bool bLoopVirgin = true;
|
||||
|
||||
NCV_SKIP_COND_BEGIN
|
||||
//const Ncv64f relEPS = 0.005;
|
||||
for (Ncv32u i=0; bLoopVirgin && i < this->width; i++)
|
||||
{
|
||||
for (Ncv32u j=0; bLoopVirgin && j < this->height; j++)
|
||||
{
|
||||
if (h_dst.ptr()[h_dst.stride()*i+j] != h_dst_d.ptr()[h_dst_d.stride()*i+j])
|
||||
{
|
||||
bLoopVirgin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
NCV_SKIP_COND_END
|
||||
|
||||
if (bLoopVirgin)
|
||||
{
|
||||
rcode = true;
|
||||
}
|
||||
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool TestTranspose<T>::deinit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template class TestTranspose<Ncv32u>;
|
||||
template class TestTranspose<Ncv64u>;
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* NVIDIA Corporation and its licensors retain all intellectual
|
||||
* property and proprietary rights in and to this software and
|
||||
* related documentation and any modifications thereto.
|
||||
* Any use, reproduction, disclosure, or distribution of this
|
||||
* software and related documentation without an express license
|
||||
* agreement from NVIDIA Corporation is strictly prohibited.
|
||||
*/
|
||||
#ifndef _testtranspose_h_
|
||||
#define _testtranspose_h_
|
||||
|
||||
#include "NCVTest.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
template <class T>
|
||||
class TestTranspose : public NCVTestProvider
|
||||
{
|
||||
public:
|
||||
|
||||
TestTranspose(std::string testName, NCVTestSourceProvider<T> &src,
|
||||
Ncv32u width, Ncv32u height);
|
||||
|
||||
virtual bool init();
|
||||
virtual bool process();
|
||||
virtual bool deinit();
|
||||
virtual bool toString(std::ofstream &strOut);
|
||||
|
||||
private:
|
||||
|
||||
TestTranspose(const TestTranspose&);
|
||||
TestTranspose& operator=(const TestTranspose&);
|
||||
|
||||
NCVTestSourceProvider<T> &src;
|
||||
Ncv32u width;
|
||||
Ncv32u height;
|
||||
};
|
||||
|
||||
#endif // _testtranspose_h_
|
@ -1,353 +0,0 @@
|
||||
#pragma warning (disable : 4408 4201 4100)
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "NCV.hpp"
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
|
||||
#include "TestIntegralImage.h"
|
||||
#include "TestIntegralImageSquared.h"
|
||||
#include "TestRectStdDev.h"
|
||||
#include "TestResize.h"
|
||||
#include "TestCompact.h"
|
||||
#include "TestTranspose.h"
|
||||
|
||||
#include "TestDrawRects.h"
|
||||
#include "TestHypothesesGrow.h"
|
||||
#include "TestHypothesesFilter.h"
|
||||
#include "TestHaarCascadeLoader.h"
|
||||
#include "TestHaarCascadeApplication.h"
|
||||
|
||||
#include "NCVAutoTestLister.hpp"
|
||||
#include "NCVTestSourceProvider.hpp"
|
||||
|
||||
|
||||
template <class T_in, class T_out>
|
||||
void generateIntegralTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T_in> &src,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
for (Ncv32f _i=1.0; _i<maxWidth; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "LinIntImgW%dH%d", i, 2);
|
||||
testLister.add(new TestIntegralImage<T_in, T_out>(testName, src, i, 2));
|
||||
}
|
||||
for (Ncv32f _i=1.0; _i<maxHeight; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "LinIntImgW%dH%d", 2, i);
|
||||
testLister.add(new TestIntegralImage<T_in, T_out>(testName, src, 2, i));
|
||||
}
|
||||
|
||||
//test VGA
|
||||
testLister.add(new TestIntegralImage<T_in, T_out>("LinIntImg_VGA", src, 640, 480));
|
||||
|
||||
//TODO: add tests of various resolutions up to 4096x4096
|
||||
}
|
||||
|
||||
|
||||
void generateSquaredIntegralTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
for (Ncv32f _i=1.0; _i<maxWidth; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "SqIntImgW%dH%d", i, 32);
|
||||
testLister.add(new TestIntegralImageSquared(testName, src, i, 32));
|
||||
}
|
||||
for (Ncv32f _i=1.0; _i<maxHeight; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "SqIntImgW%dH%d", 32, i);
|
||||
testLister.add(new TestIntegralImageSquared(testName, src, 32, i));
|
||||
}
|
||||
|
||||
//test VGA
|
||||
testLister.add(new TestIntegralImageSquared("SqLinIntImg_VGA", src, 640, 480));
|
||||
|
||||
//TODO: add tests of various resolutions up to 4096x4096
|
||||
}
|
||||
|
||||
|
||||
void generateRectStdDevTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
NcvRect32u rect(1,1,18,18);
|
||||
|
||||
for (Ncv32f _i=32; _i<maxHeight/2 && _i < maxWidth/2; _i*=1.2f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "RectStdDevW%dH%d", i*2, i);
|
||||
testLister.add(new TestRectStdDev(testName, src, i*2, i, rect, 1, true));
|
||||
testLister.add(new TestRectStdDev(testName, src, i*2, i, rect, 1.5, false));
|
||||
testLister.add(new TestRectStdDev(testName, src, i-1, i*2-1, rect, 1, false));
|
||||
testLister.add(new TestRectStdDev(testName, src, i-1, i*2-1, rect, 2.5, true));
|
||||
}
|
||||
|
||||
//test VGA
|
||||
testLister.add(new TestRectStdDev("RectStdDev_VGA", src, 640, 480, rect, 1, true));
|
||||
|
||||
//TODO: add tests of various resolutions up to 4096x4096
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void generateResizeTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T> &src)
|
||||
{
|
||||
//test VGA
|
||||
for (Ncv32u i=1; i<480; i+=3)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "TestResize_VGA_s%d", i);
|
||||
testLister.add(new TestResize<T>(testName, src, 640, 480, i, true));
|
||||
testLister.add(new TestResize<T>(testName, src, 640, 480, i, false));
|
||||
}
|
||||
|
||||
//test HD
|
||||
for (Ncv32u i=1; i<1080; i+=5)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "TestResize_1080_s%d", i);
|
||||
testLister.add(new TestResize<T>(testName, src, 1920, 1080, i, true));
|
||||
testLister.add(new TestResize<T>(testName, src, 1920, 1080, i, false));
|
||||
}
|
||||
|
||||
//TODO: add tests of various resolutions up to 4096x4096
|
||||
}
|
||||
|
||||
|
||||
void generateNPPSTVectorTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
|
||||
{
|
||||
//compaction
|
||||
for (Ncv32f _i=256.0; _i<maxLength; _i*=1.1f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "Compaction%d", i);
|
||||
testLister.add(new TestCompact(testName, src, i, 0xFFFFFFFF, 30));
|
||||
}
|
||||
for (Ncv32u i=1; i<260; i++)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "Compaction%d", i);
|
||||
testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 70));
|
||||
testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 0));
|
||||
testLister.add(new TestCompact(testName, src, i, 0xC001C0DE, 100));
|
||||
}
|
||||
for (Ncv32u i=256*256-256; i<256*256+257; i++)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "Compaction%d", i);
|
||||
testLister.add(new TestCompact(testName, src, i, 0xFFFFFFFF, 40));
|
||||
}
|
||||
for (Ncv32u i=256*256*256-10; i<256*256*256+10; i++)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "Compaction%d", i);
|
||||
testLister.add(new TestCompact(testName, src, i, 0x00000000, 2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void generateTransposeTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T> &src)
|
||||
{
|
||||
for (int i=2; i<64; i+=4)
|
||||
{
|
||||
for (int j=2; j<64; j+=4)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "TestTranspose_%dx%d", i, j);
|
||||
testLister.add(new TestTranspose<T>(testName, src, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=1; i<128; i+=1)
|
||||
{
|
||||
for (int j=1; j<2; j+=1)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "TestTranspose_%dx%d", i, j);
|
||||
testLister.add(new TestTranspose<T>(testName, src, i, j));
|
||||
}
|
||||
}
|
||||
|
||||
testLister.add(new TestTranspose<T>("TestTranspose_VGA", src, 640, 480));
|
||||
testLister.add(new TestTranspose<T>("TestTranspose_HD1080", src, 1920, 1080));
|
||||
|
||||
//regression tests
|
||||
testLister.add(new TestTranspose<T>("TestTranspose_reg_0", src, 1072, 375));
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void generateDrawRectsTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<T> &src, NCVTestSourceProvider<Ncv32u> &src32u,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
for (Ncv32f _i=16.0; _i<maxWidth; _i*=1.1f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
Ncv32u j = maxHeight * i / maxWidth;
|
||||
if (!j) continue;
|
||||
char testName[80];
|
||||
sprintf(testName, "DrawRectsW%dH%d", i, j);
|
||||
|
||||
if (sizeof(T) == sizeof(Ncv32u))
|
||||
{
|
||||
testLister.add(new TestDrawRects<T>(testName, src, src32u, i, j, i*j/1000+1, (T)0xFFFFFFFF));
|
||||
}
|
||||
else if (sizeof(T) == sizeof(Ncv8u))
|
||||
{
|
||||
testLister.add(new TestDrawRects<T>(testName, src, src32u, i, j, i*j/1000+1, (T)0xFF));
|
||||
}
|
||||
else
|
||||
{
|
||||
ncvAssertPrintCheck(false, "Attempted to instantiate non-existing DrawRects test suite");
|
||||
}
|
||||
}
|
||||
|
||||
//test VGA
|
||||
testLister.add(new TestDrawRects<T>("DrawRects_VGA", src, src32u, 640, 480, 640*480/1000, (T)0xFF));
|
||||
|
||||
//TODO: add tests of various resolutions up to 4096x4096
|
||||
}
|
||||
|
||||
|
||||
void generateVectorTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
|
||||
{
|
||||
//growth
|
||||
for (Ncv32f _i=10.0; _i<maxLength; _i*=1.1f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "VectorGrow%d", i);
|
||||
testLister.add(new TestHypothesesGrow(testName, src, 20, 20, 2.2f, i, i/2, i, i/4));
|
||||
testLister.add(new TestHypothesesGrow(testName, src, 10, 42, 1.2f, i, i, i, 0));
|
||||
}
|
||||
testLister.add(new TestHypothesesGrow("VectorGrow01b", src, 10, 42, 1.2f, 10, 0, 10, 1));
|
||||
testLister.add(new TestHypothesesGrow("VectorGrow11b", src, 10, 42, 1.2f, 10, 1, 10, 1));
|
||||
testLister.add(new TestHypothesesGrow("VectorGrow10b", src, 10, 42, 1.2f, 10, 1, 10, 0));
|
||||
testLister.add(new TestHypothesesGrow("VectorGrow00b", src, 10, 42, 1.2f, 10, 0, 10, 0));
|
||||
}
|
||||
|
||||
|
||||
void generateHypothesesFiltrationTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv32u> &src, Ncv32u maxLength)
|
||||
{
|
||||
for (Ncv32f _i=1.0; _i<maxLength; _i*=1.1f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "HypFilter%d", i);
|
||||
testLister.add(new TestHypothesesFilter(testName, src, i, 3, 0.2f));
|
||||
testLister.add(new TestHypothesesFilter(testName, src, i, 0, 0.2f));
|
||||
testLister.add(new TestHypothesesFilter(testName, src, i, 1, 0.1f));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void generateHaarLoaderTests(NCVAutoTestLister &testLister)
|
||||
{
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_eye.xml", "haarcascade_eye.xml"));
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt.xml", "haarcascade_frontalface_alt.xml"));
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt2.xml", "haarcascade_frontalface_alt2.xml"));
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_frontalface_alt_tree.xml", "haarcascade_frontalface_alt_tree.xml"));
|
||||
testLister.add(new TestHaarCascadeLoader("haarcascade_eye_tree_eyeglasses.xml", "haarcascade_eye_tree_eyeglasses.xml"));
|
||||
}
|
||||
|
||||
|
||||
void generateHaarApplicationTests(NCVAutoTestLister &testLister, NCVTestSourceProvider<Ncv8u> &src,
|
||||
Ncv32u maxWidth, Ncv32u maxHeight)
|
||||
{
|
||||
for (Ncv32u i=20; i<512; i+=11)
|
||||
{
|
||||
for (Ncv32u j=20; j<128; j+=5)
|
||||
{
|
||||
char testName[80];
|
||||
sprintf(testName, "HaarAppl%d_%d", i, j);
|
||||
testLister.add(new TestHaarCascadeApplication(testName, src, "haarcascade_frontalface_alt.xml", j, i));
|
||||
}
|
||||
}
|
||||
for (Ncv32f _i=20.0; _i<maxWidth; _i*=1.1f)
|
||||
{
|
||||
Ncv32u i = (Ncv32u)_i;
|
||||
char testName[80];
|
||||
sprintf(testName, "HaarAppl%d", i);
|
||||
testLister.add(new TestHaarCascadeApplication(testName, src, "haarcascade_frontalface_alt.xml", i, i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void devNullOutput(const char *msg)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool main_nvidia()
|
||||
{
|
||||
printf("Testing NVIDIA Computer Vision SDK\n");
|
||||
printf("==================================\n");
|
||||
|
||||
ncvSetDebugOutputHandler(devNullOutput);
|
||||
|
||||
NCVAutoTestLister testListerII("NPPST Integral Image" );//,,true, false);
|
||||
NCVAutoTestLister testListerSII("NPPST Squared Integral Image" );//,,true, false);
|
||||
NCVAutoTestLister testListerRStdDev("NPPST RectStdDev" );//,,true, false);
|
||||
NCVAutoTestLister testListerResize("NPPST Resize" );//,,true, false);
|
||||
NCVAutoTestLister testListerNPPSTVectorOperations("NPPST Vector Operations" );//,,true, false);
|
||||
NCVAutoTestLister testListerTranspose("NPPST Transpose" );//,,true, false);
|
||||
|
||||
NCVAutoTestLister testListerVectorOperations("Vector Operations" );//,,true, false);
|
||||
NCVAutoTestLister testListerHaarLoader("Haar Cascade Loader" );//,,true, false);
|
||||
NCVAutoTestLister testListerHaarAppl("Haar Cascade Application" );//,,true, false);
|
||||
NCVAutoTestLister testListerHypFiltration("Hypotheses Filtration" );//,,true, false);
|
||||
NCVAutoTestLister testListerVisualize("Visualization" );//,,true, false);
|
||||
|
||||
printf("Initializing data source providers\n");
|
||||
NCVTestSourceProvider<Ncv32u> testSrcRandom_32u(2010, 0, 0xFFFFFFFF, 4096, 4096);
|
||||
NCVTestSourceProvider<Ncv8u> testSrcRandom_8u(2010, 0, 255, 4096, 4096);
|
||||
NCVTestSourceProvider<Ncv64u> testSrcRandom_64u(2010, 0, 0xFFFFFFFFFFFFFFFF, 4096, 4096);
|
||||
NCVTestSourceProvider<Ncv8u> testSrcFacesVGA_8u("../../data/group_1_640x480_VGA.pgm");
|
||||
NCVTestSourceProvider<Ncv32f> testSrcRandom_32f(2010, -1.0f, 1.0f, 4096, 4096);
|
||||
|
||||
printf("Generating NPPST test suites\n");
|
||||
generateIntegralTests<Ncv8u, Ncv32u>(testListerII, testSrcRandom_8u, 4096, 4096);
|
||||
generateIntegralTests<Ncv32f, Ncv32f>(testListerII, testSrcRandom_32f, 4096, 4096);
|
||||
generateSquaredIntegralTests(testListerSII, testSrcRandom_8u, 4096, 4096);
|
||||
generateRectStdDevTests(testListerRStdDev, testSrcRandom_8u, 4096, 4096);
|
||||
generateResizeTests(testListerResize, testSrcRandom_32u);
|
||||
generateResizeTests(testListerResize, testSrcRandom_64u);
|
||||
generateNPPSTVectorTests(testListerNPPSTVectorOperations, testSrcRandom_32u, 4096*4096);
|
||||
generateTransposeTests(testListerTranspose, testSrcRandom_32u);
|
||||
generateTransposeTests(testListerTranspose, testSrcRandom_64u);
|
||||
|
||||
printf("Generating NCV test suites\n");
|
||||
generateDrawRectsTests(testListerVisualize, testSrcRandom_8u, testSrcRandom_32u, 4096, 4096);
|
||||
generateDrawRectsTests(testListerVisualize, testSrcRandom_32u, testSrcRandom_32u, 4096, 4096);
|
||||
generateVectorTests(testListerVectorOperations, testSrcRandom_32u, 4096*4096);
|
||||
generateHypothesesFiltrationTests(testListerHypFiltration, testSrcRandom_32u, 1024);
|
||||
generateHaarLoaderTests(testListerHaarLoader);
|
||||
generateHaarApplicationTests(testListerHaarAppl, testSrcFacesVGA_8u, 1280, 720);
|
||||
|
||||
// Indicate if at least one test failed
|
||||
bool passed = true;
|
||||
|
||||
// Invoke all tests
|
||||
passed &= testListerII.invoke();
|
||||
passed &= testListerSII.invoke();
|
||||
passed &= testListerRStdDev.invoke();
|
||||
passed &= testListerResize.invoke();
|
||||
passed &= testListerNPPSTVectorOperations.invoke();
|
||||
passed &= testListerTranspose.invoke();
|
||||
passed &= testListerVisualize.invoke();
|
||||
passed &= testListerVectorOperations.invoke();
|
||||
passed &= testListerHypFiltration.invoke();
|
||||
passed &= testListerHaarLoader.invoke();
|
||||
passed &= testListerHaarAppl.invoke();
|
||||
|
||||
return passed;
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include "cvconfig.h"
|
||||
|
||||
class CV_NVidiaTestsCaller : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_NVidiaTestsCaller() : CvTest("GPU-NVidia", "NVidia") {}
|
||||
virtual ~CV_NVidiaTestsCaller() {}
|
||||
|
||||
protected:
|
||||
|
||||
void run( int )
|
||||
{
|
||||
#if defined(HAVE_CUDA)
|
||||
bool main_nvidia();
|
||||
|
||||
// Invoke all NVIDIA Staging tests and obtain the result
|
||||
bool passed = main_nvidia();
|
||||
|
||||
if (passed)
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
else
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
|
||||
#else
|
||||
ts->set_failed_test_info(CvTS::SKIPPED);
|
||||
#endif
|
||||
}
|
||||
} CV_NVidiaTestsCaller_test;
|
@ -1,93 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
struct CV_AsyncGpuMatTest : public CvTest
|
||||
{
|
||||
CV_AsyncGpuMatTest() : CvTest( "GPU-AsyncGpuMatOperator", "async" )
|
||||
{
|
||||
}
|
||||
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
CudaMem src(Mat::zeros(100, 100, CV_8UC1));
|
||||
|
||||
GpuMat gpusrc;
|
||||
GpuMat gpudst0, gpudst1(100, 100, CV_8UC1);
|
||||
|
||||
CudaMem cpudst0;
|
||||
CudaMem cpudst1;
|
||||
|
||||
Stream stream0, stream1;
|
||||
|
||||
stream0.enqueueUpload(src, gpusrc);
|
||||
bitwise_not(gpusrc, gpudst0, GpuMat(), stream0);
|
||||
stream0.enqueueDownload(gpudst0, cpudst0);
|
||||
|
||||
stream1.enqueueMemSet(gpudst1, Scalar::all(128));
|
||||
stream1.enqueueDownload(gpudst1, cpudst1);
|
||||
|
||||
stream0.waitForCompletion();
|
||||
stream1.waitForCompletion();
|
||||
|
||||
Mat cpu_gold0(100, 100, CV_8UC1, Scalar::all(255));
|
||||
Mat cpu_gold1(100, 100, CV_8UC1, Scalar::all(128));
|
||||
|
||||
if (norm(cpudst0, cpu_gold0, NORM_INF) > 0 || norm(cpudst1, cpu_gold1, NORM_INF) > 0)
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
else
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
catch(cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} CV_AsyncGpuMatTest_test;
|
@ -1,126 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
using namespace gpu;
|
||||
|
||||
class CV_GpuMatOpConvertToTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GpuMatOpConvertToTest() : CvTest( "GPU-MatOperatorConvertTo", "convertTo" ) {}
|
||||
~CV_GpuMatOpConvertToTest() {}
|
||||
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
void CV_GpuMatOpConvertToTest::run(int /* start_from */)
|
||||
{
|
||||
const Size img_size(67, 35);
|
||||
|
||||
const char* types_str[] = {"CV_8U", "CV_8S", "CV_16U", "CV_16S", "CV_32S", "CV_32F", "CV_64F"};
|
||||
|
||||
bool passed = true;
|
||||
try
|
||||
{
|
||||
int lastType = CV_32F;
|
||||
|
||||
if (TargetArchs::builtWith(NATIVE_DOUBLE) && DeviceInfo().supports(NATIVE_DOUBLE))
|
||||
lastType = CV_64F;
|
||||
|
||||
for (int i = 0; i <= lastType && passed; ++i)
|
||||
{
|
||||
for (int j = 0; j <= lastType && passed; ++j)
|
||||
{
|
||||
for (int c = 1; c < 5 && passed; ++c)
|
||||
{
|
||||
const int src_type = CV_MAKETYPE(i, c);
|
||||
const int dst_type = j;
|
||||
|
||||
cv::RNG rng(*ts->get_rng());
|
||||
|
||||
Mat cpumatsrc(img_size, src_type);
|
||||
rng.fill(cpumatsrc, RNG::UNIFORM, Scalar::all(0), Scalar::all(300));
|
||||
|
||||
GpuMat gpumatsrc(cpumatsrc);
|
||||
Mat cpumatdst;
|
||||
GpuMat gpumatdst;
|
||||
|
||||
cpumatsrc.convertTo(cpumatdst, dst_type, 0.5, 3.0);
|
||||
gpumatsrc.convertTo(gpumatdst, dst_type, 0.5, 3.0);
|
||||
|
||||
double r = norm(cpumatdst, gpumatdst, NORM_INF);
|
||||
if (r > 1)
|
||||
{
|
||||
ts->printf(CvTS::LOG,
|
||||
"\nFAILED: SRC_TYPE=%sC%d DST_TYPE=%s NORM = %f\n",
|
||||
types_str[i], c, types_str[j], r);
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(passed ? CvTS::OK : CvTS::FAIL_GENERIC);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_GpuMatOpConvertToTest CV_GpuMatOpConvertToTest_test;
|
@ -1,162 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
#include <iomanip> // for cout << setw()
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
using namespace gpu;
|
||||
|
||||
class CV_GpuMatOpCopyToTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GpuMatOpCopyToTest() : CvTest( "GPU-MatOperatorCopyTo", "copyTo" )
|
||||
{
|
||||
rows = 234;
|
||||
cols = 123;
|
||||
}
|
||||
~CV_GpuMatOpCopyToTest() {}
|
||||
|
||||
protected:
|
||||
void run(int);
|
||||
template <typename T>
|
||||
void print_mat(const T & mat, const std::string & name) const;
|
||||
bool compare_matrix(cv::Mat & cpumat, gpu::GpuMat & gpumat);
|
||||
|
||||
private:
|
||||
int rows;
|
||||
int cols;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void CV_GpuMatOpCopyToTest::print_mat(const T & mat, const std::string & name) const { cv::imshow(name, mat); }
|
||||
|
||||
bool CV_GpuMatOpCopyToTest::compare_matrix(cv::Mat & cpumat, gpu::GpuMat & gpumat)
|
||||
{
|
||||
Mat cmat(cpumat.size(), cpumat.type(), Scalar::all(0));
|
||||
GpuMat gmat(cmat);
|
||||
|
||||
Mat cpumask(cpumat.size(), CV_8U);
|
||||
|
||||
cv::RNG rng(*ts->get_rng());
|
||||
|
||||
rng.fill(cpumask, RNG::NORMAL, Scalar::all(0), Scalar::all(127));
|
||||
|
||||
threshold(cpumask, cpumask, 0, 127, THRESH_BINARY);
|
||||
|
||||
GpuMat gpumask(cpumask);
|
||||
|
||||
//int64 time = getTickCount();
|
||||
cpumat.copyTo(cmat, cpumask);
|
||||
//int64 time1 = getTickCount();
|
||||
gpumat.copyTo(gmat, gpumask);
|
||||
//int64 time2 = getTickCount();
|
||||
|
||||
//std::cout << "\ntime cpu: " << std::fixed << std::setprecision(12) << 1.0 / double((time1 - time) / (double)getTickFrequency());
|
||||
//std::cout << "\ntime gpu: " << std::fixed << std::setprecision(12) << 1.0 / double((time2 - time1) / (double)getTickFrequency());
|
||||
//std::cout << "\n";
|
||||
|
||||
#ifdef PRINT_MATRIX
|
||||
print_mat(cmat, "cpu mat");
|
||||
print_mat(gmat, "gpu mat");
|
||||
print_mat(cpumask, "cpu mask");
|
||||
print_mat(gpumask, "gpu mask");
|
||||
cv::waitKey(0);
|
||||
#endif
|
||||
|
||||
double ret = norm(cmat, gmat);
|
||||
|
||||
if (ret < 1.0)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nNorm: %f\n", ret);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void CV_GpuMatOpCopyToTest::run( int /* start_from */)
|
||||
{
|
||||
bool is_test_good = true;
|
||||
|
||||
try
|
||||
{
|
||||
int lastType = CV_32F;
|
||||
|
||||
if (TargetArchs::builtWith(NATIVE_DOUBLE) && DeviceInfo().supports(NATIVE_DOUBLE))
|
||||
lastType = CV_64F;
|
||||
|
||||
for (int i = 0 ; i <= lastType; i++)
|
||||
{
|
||||
Mat cpumat(rows, cols, i);
|
||||
cpumat.setTo(Scalar::all(127));
|
||||
|
||||
GpuMat gpumat(cpumat);
|
||||
|
||||
is_test_good &= compare_matrix(cpumat, gpumat);
|
||||
}
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_test_good == true)
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
else
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_GpuMatOpCopyToTest CV_GpuMatOpCopyTo_test;
|
@ -1,138 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <limits>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
using namespace gpu;
|
||||
|
||||
class CV_GpuMatOpSetToTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_GpuMatOpSetToTest();
|
||||
~CV_GpuMatOpSetToTest() {}
|
||||
|
||||
protected:
|
||||
void run(int);
|
||||
|
||||
bool testSetTo(cv::Mat& cpumat, gpu::GpuMat& gpumat, const cv::Mat& cpumask = cv::Mat(), const cv::gpu::GpuMat& gpumask = cv::gpu::GpuMat());
|
||||
|
||||
private:
|
||||
int rows;
|
||||
int cols;
|
||||
Scalar s;
|
||||
};
|
||||
|
||||
CV_GpuMatOpSetToTest::CV_GpuMatOpSetToTest(): CvTest( "GPU-MatOperatorSetTo", "setTo" )
|
||||
{
|
||||
rows = 35;
|
||||
cols = 67;
|
||||
|
||||
s.val[0] = 127.0;
|
||||
s.val[1] = 127.0;
|
||||
s.val[2] = 127.0;
|
||||
s.val[3] = 127.0;
|
||||
}
|
||||
|
||||
bool CV_GpuMatOpSetToTest::testSetTo(cv::Mat& cpumat, gpu::GpuMat& gpumat, const cv::Mat& cpumask, const cv::gpu::GpuMat& gpumask)
|
||||
{
|
||||
cpumat.setTo(s, cpumask);
|
||||
gpumat.setTo(s, gpumask);
|
||||
|
||||
double ret = norm(cpumat, gpumat, NORM_INF);
|
||||
|
||||
if (ret < std::numeric_limits<double>::epsilon())
|
||||
return true;
|
||||
else
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nNorm: %f\n", ret);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void CV_GpuMatOpSetToTest::run( int /* start_from */)
|
||||
{
|
||||
bool is_test_good = true;
|
||||
|
||||
try
|
||||
{
|
||||
cv::Mat cpumask(rows, cols, CV_8UC1);
|
||||
cv::RNG rng(*ts->get_rng());
|
||||
rng.fill(cpumask, RNG::UNIFORM, cv::Scalar::all(0.0), cv::Scalar(1.5));
|
||||
cv::gpu::GpuMat gpumask(cpumask);
|
||||
|
||||
int lastType = CV_32F;
|
||||
|
||||
if (TargetArchs::builtWith(NATIVE_DOUBLE) && DeviceInfo().supports(NATIVE_DOUBLE))
|
||||
lastType = CV_64F;
|
||||
|
||||
for (int i = 0; i <= lastType; i++)
|
||||
{
|
||||
for (int cn = 1; cn <= 4; ++cn)
|
||||
{
|
||||
int mat_type = CV_MAKETYPE(i, cn);
|
||||
Mat cpumat(rows, cols, mat_type, Scalar::all(0));
|
||||
GpuMat gpumat(cpumat);
|
||||
is_test_good &= testSetTo(cpumat, gpumat, cpumask, gpumask);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_test_good == true)
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
else
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_GpuMatOpSetToTest CV_GpuMatOpSetTo_test;
|
@ -1,352 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other GpuMaterials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or bpied warranties, including, but not limited to, the bpied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Merge
|
||||
|
||||
struct CV_MergeTest : public CvTest
|
||||
{
|
||||
CV_MergeTest() : CvTest("GPU-Merge", "merge") {}
|
||||
void can_merge(size_t rows, size_t cols);
|
||||
void can_merge_submatrixes(size_t rows, size_t cols);
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
void CV_MergeTest::can_merge(size_t rows, size_t cols)
|
||||
{
|
||||
bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) &&
|
||||
gpu::DeviceInfo().supports(gpu::NATIVE_DOUBLE);
|
||||
size_t depth_end = double_ok ? CV_64F : CV_32F;
|
||||
|
||||
for (size_t num_channels = 1; num_channels <= 4; ++num_channels)
|
||||
for (size_t depth = CV_8U; depth <= depth_end; ++depth)
|
||||
{
|
||||
vector<Mat> src;
|
||||
for (size_t i = 0; i < num_channels; ++i)
|
||||
src.push_back(Mat(rows, cols, depth, Scalar::all(static_cast<double>(i))));
|
||||
|
||||
Mat dst(rows, cols, CV_MAKETYPE(depth, num_channels));
|
||||
|
||||
cv::merge(src, dst);
|
||||
|
||||
vector<gpu::GpuMat> dev_src;
|
||||
for (size_t i = 0; i < num_channels; ++i)
|
||||
dev_src.push_back(gpu::GpuMat(src[i]));
|
||||
|
||||
gpu::GpuMat dev_dst(rows, cols, CV_MAKETYPE(depth, num_channels));
|
||||
cv::gpu::merge(dev_src, dev_dst);
|
||||
|
||||
Mat host_dst = dev_dst;
|
||||
|
||||
double err = norm(dst, host_dst, NORM_INF);
|
||||
|
||||
if (err > 1e-3)
|
||||
{
|
||||
//ts->printf(CvTS::CONSOLE, "\nNorm: %f\n", err);
|
||||
//ts->printf(CvTS::CONSOLE, "Depth: %d\n", depth);
|
||||
//ts->printf(CvTS::CONSOLE, "Rows: %d\n", rows);
|
||||
//ts->printf(CvTS::CONSOLE, "Cols: %d\n", cols);
|
||||
//ts->printf(CvTS::CONSOLE, "NumChannels: %d\n", num_channels);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_MergeTest::can_merge_submatrixes(size_t rows, size_t cols)
|
||||
{
|
||||
bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) &&
|
||||
gpu::DeviceInfo().supports(gpu::NATIVE_DOUBLE);
|
||||
size_t depth_end = double_ok ? CV_64F : CV_32F;
|
||||
|
||||
for (size_t num_channels = 1; num_channels <= 4; ++num_channels)
|
||||
for (size_t depth = CV_8U; depth <= depth_end; ++depth)
|
||||
{
|
||||
vector<Mat> src;
|
||||
for (size_t i = 0; i < num_channels; ++i)
|
||||
{
|
||||
Mat m(rows * 2, cols * 2, depth, Scalar::all(static_cast<double>(i)));
|
||||
src.push_back(m(Range(rows / 2, rows / 2 + rows), Range(cols / 2, cols / 2 + cols)));
|
||||
}
|
||||
|
||||
Mat dst(rows, cols, CV_MAKETYPE(depth, num_channels));
|
||||
|
||||
cv::merge(src, dst);
|
||||
|
||||
vector<gpu::GpuMat> dev_src;
|
||||
for (size_t i = 0; i < num_channels; ++i)
|
||||
dev_src.push_back(gpu::GpuMat(src[i]));
|
||||
|
||||
gpu::GpuMat dev_dst(rows, cols, CV_MAKETYPE(depth, num_channels));
|
||||
cv::gpu::merge(dev_src, dev_dst);
|
||||
|
||||
Mat host_dst = dev_dst;
|
||||
|
||||
double err = norm(dst, host_dst, NORM_INF);
|
||||
|
||||
if (err > 1e-3)
|
||||
{
|
||||
//ts->printf(CvTS::CONSOLE, "\nNorm: %f\n", err);
|
||||
//ts->printf(CvTS::CONSOLE, "Depth: %d\n", depth);
|
||||
//ts->printf(CvTS::CONSOLE, "Rows: %d\n", rows);
|
||||
//ts->printf(CvTS::CONSOLE, "Cols: %d\n", cols);
|
||||
//ts->printf(CvTS::CONSOLE, "NumChannels: %d\n", num_channels);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CV_MergeTest::run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
can_merge(1, 1);
|
||||
can_merge(1, 7);
|
||||
can_merge(53, 7);
|
||||
can_merge_submatrixes(1, 1);
|
||||
can_merge_submatrixes(1, 7);
|
||||
can_merge_submatrixes(53, 7);
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Split
|
||||
|
||||
struct CV_SplitTest : public CvTest
|
||||
{
|
||||
CV_SplitTest() : CvTest("GPU-Split", "split") {}
|
||||
void can_split(size_t rows, size_t cols);
|
||||
void can_split_submatrix(size_t rows, size_t cols);
|
||||
void run(int);
|
||||
};
|
||||
|
||||
void CV_SplitTest::can_split(size_t rows, size_t cols)
|
||||
{
|
||||
bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) &&
|
||||
gpu::DeviceInfo().supports(gpu::NATIVE_DOUBLE);
|
||||
size_t depth_end = double_ok ? CV_64F : CV_32F;
|
||||
|
||||
for (size_t num_channels = 1; num_channels <= 4; ++num_channels)
|
||||
for (size_t depth = CV_8U; depth <= depth_end; ++depth)
|
||||
{
|
||||
Mat src(rows, cols, CV_MAKETYPE(depth, num_channels), Scalar(1.0, 2.0, 3.0, 4.0));
|
||||
vector<Mat> dst;
|
||||
cv::split(src, dst);
|
||||
|
||||
gpu::GpuMat dev_src(src);
|
||||
vector<gpu::GpuMat> dev_dst;
|
||||
cv::gpu::split(dev_src, dev_dst);
|
||||
|
||||
if (dev_dst.size() != dst.size())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "Bad output sizes");
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_channels; ++i)
|
||||
{
|
||||
Mat host_dst = dev_dst[i];
|
||||
double err = norm(dst[i], host_dst, NORM_INF);
|
||||
|
||||
if (err > 1e-3)
|
||||
{
|
||||
//ts->printf(CvTS::CONSOLE, "\nNorm: %f\n", err);
|
||||
//ts->printf(CvTS::CONSOLE, "Depth: %d\n", depth);
|
||||
//ts->printf(CvTS::CONSOLE, "Rows: %d\n", rows);
|
||||
//ts->printf(CvTS::CONSOLE, "Cols: %d\n", cols);
|
||||
//ts->printf(CvTS::CONSOLE, "NumChannels: %d\n", num_channels);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CV_SplitTest::can_split_submatrix(size_t rows, size_t cols)
|
||||
{
|
||||
bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) &&
|
||||
gpu::DeviceInfo().supports(gpu::NATIVE_DOUBLE);
|
||||
size_t depth_end = double_ok ? CV_64F : CV_32F;
|
||||
|
||||
for (size_t num_channels = 1; num_channels <= 4; ++num_channels)
|
||||
for (size_t depth = CV_8U; depth <= depth_end; ++depth)
|
||||
{
|
||||
Mat src_data(rows * 2, cols * 2, CV_MAKETYPE(depth, num_channels), Scalar(1.0, 2.0, 3.0, 4.0));
|
||||
Mat src(src_data(Range(rows / 2, rows / 2 + rows), Range(cols / 2, cols / 2 + cols)));
|
||||
vector<Mat> dst;
|
||||
cv::split(src, dst);
|
||||
|
||||
gpu::GpuMat dev_src(src);
|
||||
vector<gpu::GpuMat> dev_dst;
|
||||
cv::gpu::split(dev_src, dev_dst);
|
||||
|
||||
if (dev_dst.size() != dst.size())
|
||||
{
|
||||
ts->printf(CvTS::CONSOLE, "Bad output sizes");
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_channels; ++i)
|
||||
{
|
||||
Mat host_dst = dev_dst[i];
|
||||
double err = norm(dst[i], host_dst, NORM_INF);
|
||||
|
||||
if (err > 1e-3)
|
||||
{
|
||||
//ts->printf(CvTS::CONSOLE, "\nNorm: %f\n", err);
|
||||
//ts->printf(CvTS::CONSOLE, "Depth: %d\n", depth);
|
||||
//ts->printf(CvTS::CONSOLE, "Rows: %d\n", rows);
|
||||
//ts->printf(CvTS::CONSOLE, "Cols: %d\n", cols);
|
||||
//ts->printf(CvTS::CONSOLE, "NumChannels: %d\n", num_channels);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CV_SplitTest::run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
can_split(1, 1);
|
||||
can_split(1, 7);
|
||||
can_split(7, 53);
|
||||
can_split_submatrix(1, 1);
|
||||
can_split_submatrix(1, 7);
|
||||
can_split_submatrix(7, 53);
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Split and merge
|
||||
|
||||
struct CV_SplitMergeTest : public CvTest
|
||||
{
|
||||
CV_SplitMergeTest() : CvTest("GPU-SplitMerge", "split merge") {}
|
||||
void can_split_merge(size_t rows, size_t cols);
|
||||
void run(int);
|
||||
};
|
||||
|
||||
void CV_SplitMergeTest::can_split_merge(size_t rows, size_t cols) {
|
||||
bool double_ok = gpu::TargetArchs::builtWith(gpu::NATIVE_DOUBLE) &&
|
||||
gpu::DeviceInfo().supports(gpu::NATIVE_DOUBLE);
|
||||
size_t depth_end = double_ok ? CV_64F : CV_32F;
|
||||
|
||||
for (size_t num_channels = 1; num_channels <= 4; ++num_channels)
|
||||
for (size_t depth = CV_8U; depth <= depth_end; ++depth)
|
||||
{
|
||||
Mat orig(rows, cols, CV_MAKETYPE(depth, num_channels), Scalar(1.0, 2.0, 3.0, 4.0));
|
||||
gpu::GpuMat dev_orig(orig);
|
||||
vector<gpu::GpuMat> dev_vec;
|
||||
cv::gpu::split(dev_orig, dev_vec);
|
||||
|
||||
gpu::GpuMat dev_final(rows, cols, CV_MAKETYPE(depth, num_channels));
|
||||
cv::gpu::merge(dev_vec, dev_final);
|
||||
|
||||
double err = cv::norm((Mat)dev_orig, (Mat)dev_final, NORM_INF);
|
||||
if (err > 1e-3)
|
||||
{
|
||||
//ts->printf(CvTS::CONSOLE, "\nNorm: %f\n", err);
|
||||
//ts->printf(CvTS::CONSOLE, "Depth: %d\n", depth);
|
||||
//ts->printf(CvTS::CONSOLE, "Rows: %d\n", rows);
|
||||
//ts->printf(CvTS::CONSOLE, "Cols: %d\n", cols);
|
||||
//ts->printf(CvTS::CONSOLE, "NumChannels: %d\n", num_channels);
|
||||
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_SplitMergeTest::run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
can_split_merge(1, 1);
|
||||
can_split_merge(1, 7);
|
||||
can_split_merge(7, 53);
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// If we comment some tests, we may foget/miss to uncomment it after.
|
||||
// Placing all test definitions in one place
|
||||
// makes us know about what tests are commented.
|
||||
|
||||
|
||||
CV_SplitTest split_test;
|
||||
CV_MergeTest merge_test;
|
||||
CV_SplitMergeTest split_merge_test;
|
@ -1,152 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
struct CV_GpuStereoBMTest : public CvTest
|
||||
{
|
||||
CV_GpuStereoBMTest() : CvTest( "GPU-StereoBM", "StereoBM" ){}
|
||||
~CV_GpuStereoBMTest() {}
|
||||
|
||||
|
||||
void run_stress()
|
||||
{
|
||||
RNG rng;
|
||||
|
||||
for(int i = 0; i < 10; ++i)
|
||||
{
|
||||
int winSize = cvRound(rng.uniform(2, 11)) * 2 + 1;
|
||||
|
||||
for(int j = 0; j < 10; ++j)
|
||||
{
|
||||
int ndisp = cvRound(rng.uniform(5, 32)) * 8;
|
||||
|
||||
for(int s = 0; s < 10; ++s)
|
||||
{
|
||||
int w = cvRound(rng.uniform(1024, 2048));
|
||||
int h = cvRound(rng.uniform(768, 1152));
|
||||
|
||||
for(int p = 0; p < 2; ++p)
|
||||
{
|
||||
//int winSize = winsz[i];
|
||||
//int disp = disps[j];
|
||||
Size imgSize(w, h);//res[s];
|
||||
int preset = p;
|
||||
|
||||
printf("Preset = %d, nidsp = %d, winsz = %d, width = %d, height = %d\n", p, ndisp, winSize, imgSize.width, imgSize.height);
|
||||
|
||||
GpuMat l(imgSize, CV_8U);
|
||||
GpuMat r(imgSize, CV_8U);
|
||||
|
||||
GpuMat disparity;
|
||||
StereoBM_GPU bm(preset, ndisp, winSize);
|
||||
bm(l, r, disparity);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void run(int )
|
||||
{
|
||||
/*run_stress();
|
||||
return;*/
|
||||
|
||||
cv::Mat img_l = cv::imread(std::string(ts->get_data_path()) + "stereobm/aloe-L.png", 0);
|
||||
cv::Mat img_r = cv::imread(std::string(ts->get_data_path()) + "stereobm/aloe-R.png", 0);
|
||||
cv::Mat img_reference = cv::imread(std::string(ts->get_data_path()) + "stereobm/aloe-disp.png", 0);
|
||||
|
||||
if (img_l.empty() || img_r.empty() || img_reference.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
cv::gpu::GpuMat disp;
|
||||
cv::gpu::StereoBM_GPU bm(0, 128, 19);
|
||||
bm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), disp);
|
||||
|
||||
disp.convertTo(disp, img_reference.type());
|
||||
double norm = cv::norm(disp, img_reference, cv::NORM_INF);
|
||||
|
||||
//cv::imwrite(std::string(ts->get_data_path()) + "stereobm/aloe-disp.png", disp);
|
||||
|
||||
/*cv::imshow("disp", disp);
|
||||
cv::imshow("img_reference", img_reference);
|
||||
|
||||
cv::Mat diff = (cv::Mat)disp - (cv::Mat)img_reference;
|
||||
cv::imshow("diff", diff);
|
||||
cv::waitKey();*/
|
||||
|
||||
if (norm >= 100)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nStereoBM norm = %f\n", norm);
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_GpuStereoBMTest CV_GpuStereoBM_test;
|
@ -1,103 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
struct CV_AsyncStereoBMTest : public CvTest
|
||||
{
|
||||
public:
|
||||
CV_AsyncStereoBMTest() : CvTest( "GPU-AsyncStereoBM", "asyncStereoBM" ) {}
|
||||
~CV_AsyncStereoBMTest() {}
|
||||
|
||||
void run( int /* start_from */)
|
||||
{
|
||||
cv::Mat img_l = cv::imread(std::string(ts->get_data_path()) + "stereobm/aloe-L.png", 0);
|
||||
cv::Mat img_r = cv::imread(std::string(ts->get_data_path()) + "stereobm/aloe-R.png", 0);
|
||||
cv::Mat img_reference = cv::imread(std::string(ts->get_data_path()) + "stereobm/aloe-disp.png", 0);
|
||||
|
||||
if (img_l.empty() || img_r.empty() || img_reference.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
cv::gpu::GpuMat disp;
|
||||
cv::gpu::StereoBM_GPU bm(0, 128, 19);
|
||||
|
||||
cv::gpu::Stream stream;
|
||||
|
||||
for (size_t i = 0; i < 50; i++)
|
||||
{
|
||||
bm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), disp, stream);
|
||||
}
|
||||
|
||||
stream.waitForCompletion();
|
||||
disp.convertTo(disp, img_reference.type());
|
||||
double norm = cv::norm(disp, img_reference, cv::NORM_INF);
|
||||
|
||||
if (norm >= 100)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nStereoBM norm = %f\n", norm);
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_AsyncStereoBMTest CV_AsyncStereoBMTest_test;
|
@ -1,100 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
struct CV_GpuStereoBPTest : public CvTest
|
||||
{
|
||||
CV_GpuStereoBPTest() : CvTest( "GPU-StereoBP", "StereoBP" ){}
|
||||
~CV_GpuStereoBPTest() {}
|
||||
|
||||
void run(int )
|
||||
{
|
||||
cv::Mat img_l = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-L.png");
|
||||
cv::Mat img_r = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-R.png");
|
||||
cv::Mat img_template = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-disp.png", 0);
|
||||
|
||||
if (img_l.empty() || img_r.empty() || img_template.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
{cv::Mat temp; cv::cvtColor(img_l, temp, CV_BGR2BGRA); cv::swap(temp, img_l);}
|
||||
{cv::Mat temp; cv::cvtColor(img_r, temp, CV_BGR2BGRA); cv::swap(temp, img_r);}
|
||||
|
||||
cv::gpu::GpuMat disp;
|
||||
cv::gpu::StereoBeliefPropagation bpm(64, 8, 2, 25, 0.1f, 15, 1, CV_16S);
|
||||
|
||||
bpm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), disp);
|
||||
|
||||
//cv::imwrite(std::string(ts->get_data_path()) + "stereobp/aloe-disp.png", disp);
|
||||
|
||||
disp.convertTo(disp, img_template.type());
|
||||
|
||||
double norm = cv::norm(disp, img_template, cv::NORM_INF);
|
||||
if (norm >= 0.5)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nStereoBP norm = %f\n", norm);
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_GpuStereoBPTest CV_GpuStereoBP_test;
|
@ -1,100 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "gputest.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
struct CV_GpuStereoCSBPTest : public CvTest
|
||||
{
|
||||
CV_GpuStereoCSBPTest() : CvTest( "GPU-StereoCSBP", "ConstantSpaceStereoBP" ){}
|
||||
~CV_GpuStereoCSBPTest() {}
|
||||
|
||||
void run(int )
|
||||
{
|
||||
cv::Mat img_l = cv::imread(std::string(ts->get_data_path()) + "csstereobp/aloe-L.png");
|
||||
cv::Mat img_r = cv::imread(std::string(ts->get_data_path()) + "csstereobp/aloe-R.png");
|
||||
cv::Mat img_template = cv::imread(std::string(ts->get_data_path()) + "csstereobp/aloe-disp.png", 0);
|
||||
|
||||
if (img_l.empty() || img_r.empty() || img_template.empty())
|
||||
{
|
||||
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
{cv::Mat temp; cv::cvtColor(img_l, temp, CV_BGR2BGRA); cv::swap(temp, img_l);}
|
||||
{cv::Mat temp; cv::cvtColor(img_r, temp, CV_BGR2BGRA); cv::swap(temp, img_r);}
|
||||
|
||||
cv::gpu::GpuMat disp;
|
||||
cv::gpu::StereoConstantSpaceBP bpm(128, 16, 4, 4);
|
||||
|
||||
bpm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), disp);
|
||||
|
||||
//cv::imwrite(std::string(ts->get_data_path()) + "csstereobp/aloe-disp.png", disp);
|
||||
|
||||
disp.convertTo(disp, img_template.type());
|
||||
|
||||
double norm = cv::norm(disp, img_template, cv::NORM_INF);
|
||||
if (norm >= 0.5)
|
||||
{
|
||||
ts->printf(CvTS::LOG, "\nConstantSpaceStereoBP norm = %f\n", norm);
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(const cv::Exception& e)
|
||||
{
|
||||
if (!check_and_treat_gpu_exception(e, ts))
|
||||
throw;
|
||||
return;
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(CvTS::OK);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// tests registration /////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CV_GpuStereoCSBPTest CV_GpuCSStereoBP_test;
|
Loading…
x
Reference in New Issue
Block a user