mirror of
https://github.com/opencv/opencv.git
synced 2024-11-28 13:10:12 +08:00
Merge branch 'master' of git://code.opencv.org/opencv
This commit is contained in:
commit
0f4bdcd708
@ -64,8 +64,8 @@ ocv_add_accuracy_tests(FILES "Include" ${test_hdrs}
|
||||
################################################################################################################
|
||||
################################ OpenCL Module Performance ##################################################
|
||||
################################################################################################################
|
||||
#file(GLOB perf_srcs "perf/*.cpp")
|
||||
#file(GLOB perf_hdrs "perf/*.hpp" "perf/*.h")
|
||||
file(GLOB perf_srcs "perf/*.cpp")
|
||||
file(GLOB perf_hdrs "perf/*.hpp" "perf/*.h")
|
||||
|
||||
#ocv_add_perf_tests(FILES "Include" ${perf_hdrs}
|
||||
# FILES "Src" ${perf_srcs})
|
||||
ocv_add_perf_tests(FILES "Include" ${perf_hdrs}
|
||||
FILES "Src" ${perf_srcs})
|
||||
|
120
modules/ocl/perf/interpolation.hpp
Normal file
120
modules/ocl/perf/interpolation.hpp
Normal file
@ -0,0 +1,120 @@
|
||||
/*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 __OPENCV_TEST_INTERPOLATION_HPP__
|
||||
#define __OPENCV_TEST_INTERPOLATION_HPP__
|
||||
|
||||
template <typename T> T readVal(const cv::Mat& src, int y, int x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
|
||||
{
|
||||
if (border_type == cv::BORDER_CONSTANT)
|
||||
return (y >= 0 && y < src.rows && x >= 0 && x < src.cols) ? src.at<T>(y, x * src.channels() + c) : cv::saturate_cast<T>(borderVal.val[c]);
|
||||
|
||||
return src.at<T>(cv::borderInterpolate(y, src.rows, border_type), cv::borderInterpolate(x, src.cols, border_type) * src.channels() + c);
|
||||
}
|
||||
|
||||
template <typename T> struct NearestInterpolator
|
||||
{
|
||||
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
|
||||
{
|
||||
return readVal<T>(src, cvFloor(y), cvFloor(x), c, border_type, borderVal);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct LinearInterpolator
|
||||
{
|
||||
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
|
||||
{
|
||||
x -= 0.5f;
|
||||
y -= 0.5f;
|
||||
|
||||
int x1 = cvFloor(x);
|
||||
int y1 = cvFloor(y);
|
||||
int x2 = x1 + 1;
|
||||
int y2 = y1 + 1;
|
||||
|
||||
float res = 0;
|
||||
|
||||
res += readVal<T>(src, y1, x1, c, border_type, borderVal) * ((x2 - x) * (y2 - y));
|
||||
res += readVal<T>(src, y1, x2, c, border_type, borderVal) * ((x - x1) * (y2 - y));
|
||||
res += readVal<T>(src, y2, x1, c, border_type, borderVal) * ((x2 - x) * (y - y1));
|
||||
res += readVal<T>(src, y2, x2, c, border_type, borderVal) * ((x - x1) * (y - y1));
|
||||
|
||||
return cv::saturate_cast<T>(res);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct CubicInterpolator
|
||||
{
|
||||
static float getValue(float p[4], float x)
|
||||
{
|
||||
return p[1] + 0.5 * x * (p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0])));
|
||||
}
|
||||
|
||||
static float getValue(float p[4][4], float x, float y)
|
||||
{
|
||||
float arr[4];
|
||||
|
||||
arr[0] = getValue(p[0], x);
|
||||
arr[1] = getValue(p[1], x);
|
||||
arr[2] = getValue(p[2], x);
|
||||
arr[3] = getValue(p[3], x);
|
||||
|
||||
return getValue(arr, y);
|
||||
}
|
||||
|
||||
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
|
||||
{
|
||||
int ix = cvRound(x);
|
||||
int iy = cvRound(y);
|
||||
|
||||
float vals[4][4] =
|
||||
{
|
||||
{readVal<T>(src, iy - 2, ix - 2, c, border_type, borderVal), readVal<T>(src, iy - 2, ix - 1, c, border_type, borderVal), readVal<T>(src, iy - 2, ix, c, border_type, borderVal), readVal<T>(src, iy - 2, ix + 1, c, border_type, borderVal)},
|
||||
{readVal<T>(src, iy - 1, ix - 2, c, border_type, borderVal), readVal<T>(src, iy - 1, ix - 1, c, border_type, borderVal), readVal<T>(src, iy - 1, ix, c, border_type, borderVal), readVal<T>(src, iy - 1, ix + 1, c, border_type, borderVal)},
|
||||
{readVal<T>(src, iy , ix - 2, c, border_type, borderVal), readVal<T>(src, iy , ix - 1, c, border_type, borderVal), readVal<T>(src, iy , ix, c, border_type, borderVal), readVal<T>(src, iy , ix + 1, c, border_type, borderVal)},
|
||||
{readVal<T>(src, iy + 1, ix - 2, c, border_type, borderVal), readVal<T>(src, iy + 1, ix - 1, c, border_type, borderVal), readVal<T>(src, iy + 1, ix, c, border_type, borderVal), readVal<T>(src, iy + 1, ix + 1, c, border_type, borderVal)},
|
||||
};
|
||||
|
||||
return cv::saturate_cast<T>(getValue(vals, (x - ix + 2.0) / 4.0, (y - iy + 2.0) / 4.0));
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __OPENCV_TEST_INTERPOLATION_HPP__
|
108
modules/ocl/perf/main.cpp
Normal file
108
modules/ocl/perf/main.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*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 "precomp.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::ocl;
|
||||
using namespace cvtest;
|
||||
using namespace testing;
|
||||
|
||||
void print_info()
|
||||
{
|
||||
printf("\n");
|
||||
#if defined _WIN32
|
||||
# if defined _WIN64
|
||||
puts("OS: Windows 64");
|
||||
# else
|
||||
puts("OS: Windows 32");
|
||||
# endif
|
||||
#elif defined linux
|
||||
# if defined _LP64
|
||||
puts("OS: Linux 64");
|
||||
# else
|
||||
puts("OS: Linux 32");
|
||||
# endif
|
||||
#elif defined __APPLE__
|
||||
# if defined _LP64
|
||||
puts("OS: Apple 64");
|
||||
# else
|
||||
puts("OS: Apple 32");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if PERF_TEST_OCL
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
static std::vector<Info> ocl_info;
|
||||
ocl::getDevice(ocl_info);
|
||||
|
||||
run_perf_test();
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TS::ptr()->init("ocl");
|
||||
InitGoogleTest(&argc, argv);
|
||||
|
||||
print_info();
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
#endif // PERF_TEST_OCL
|
||||
|
||||
#else // HAVE_OPENC
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("OpenCV was built without OpenCL support\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // HAVE_OPENCL
|
1191
modules/ocl/perf/perf_test_ocl.cpp
Normal file
1191
modules/ocl/perf/perf_test_ocl.cpp
Normal file
File diff suppressed because it is too large
Load Diff
45
modules/ocl/perf/precomp.cpp
Normal file
45
modules/ocl/perf/precomp.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*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 "precomp.hpp"
|
||||
|
||||
|
||||
|
72
modules/ocl/perf/precomp.hpp
Normal file
72
modules/ocl/perf/precomp.hpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*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 __OPENCV_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <cstdarg>
|
||||
#include "cvconfig.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/video/video.hpp"
|
||||
#include "opencv2/ts/ts.hpp"
|
||||
#include "opencv2/ts/ts_perf.hpp"
|
||||
#include "opencv2/ocl/ocl.hpp"
|
||||
#include "opencv2/nonfree/nonfree.hpp"
|
||||
|
||||
#include "utility.hpp"
|
||||
#include "interpolation.hpp"
|
||||
//#include "add_test_info.h"
|
||||
//#define PERF_TEST_OCL 1
|
||||
|
||||
#endif
|
||||
|
3658
modules/ocl/perf/test_arithm.cpp
Normal file
3658
modules/ocl/perf/test_arithm.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1096
modules/ocl/perf/test_filters.cpp
Normal file
1096
modules/ocl/perf/test_filters.cpp
Normal file
File diff suppressed because it is too large
Load Diff
198
modules/ocl/perf/test_haar.cpp
Normal file
198
modules/ocl/perf/test_haar.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
/*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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
//
|
||||
// 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 oclMaterials 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 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 "opencv2/objdetect/objdetect.hpp"
|
||||
#include "precomp.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
using namespace cvtest;
|
||||
using namespace testing;
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
struct getRect { Rect operator ()(const CvAvgComp& e) const { return e.rect; } };
|
||||
|
||||
PARAM_TEST_CASE(HaarTestBase, int, int)
|
||||
{
|
||||
std::vector<cv::ocl::Info> oclinfo;
|
||||
cv::ocl::OclCascadeClassifier cascade, nestedCascade;
|
||||
cv::CascadeClassifier cpucascade, cpunestedCascade;
|
||||
// Mat img;
|
||||
|
||||
double scale;
|
||||
int index;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
scale = 1.1;
|
||||
|
||||
#if WIN32
|
||||
string cascadeName="E:\\opencvbuffer\\trunk\\data\\haarcascades\\haarcascade_frontalface_alt.xml";
|
||||
#else
|
||||
string cascadeName="../data/haarcascades/haarcascade_frontalface_alt.xml";
|
||||
#endif
|
||||
|
||||
if( (!cascade.load( cascadeName )) || (!cpucascade.load(cascadeName)))
|
||||
{
|
||||
cout << "ERROR: Could not load classifier cascade" << endl;
|
||||
cout << "Usage: facedetect [--cascade=<cascade_path>]\n"
|
||||
" [--nested-cascade[=nested_cascade_path]]\n"
|
||||
" [--scale[=<image scale>\n"
|
||||
" [filename|camera_index]\n" << endl ;
|
||||
|
||||
return;
|
||||
}
|
||||
int devnums = getDevice(oclinfo);
|
||||
CV_Assert(devnums>0);
|
||||
//if you want to use undefault device, set it here
|
||||
//setDevice(oclinfo[0]);
|
||||
cv::ocl::setBinpath("E:\\");
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////faceDetect/////////////////////////////////////////////////
|
||||
|
||||
struct Haar : HaarTestBase {};
|
||||
|
||||
TEST_P(Haar, FaceDetect)
|
||||
{
|
||||
for(int index = 1;index < 2; index++)
|
||||
{
|
||||
Mat img;
|
||||
char buff[256];
|
||||
#if WIN32
|
||||
sprintf(buff,"E:\\myDataBase\\%d.jpg",index);
|
||||
img = imread( buff, 1 );
|
||||
#else
|
||||
sprintf(buff,"%d.jpg",index);
|
||||
img = imread( buff, 1 );
|
||||
std::cout << "Now test " << index << ".jpg" <<std::endl;
|
||||
#endif
|
||||
if(img.empty())
|
||||
{
|
||||
std::cout << "Couldn't read test" << index <<".jpg" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
double t = 0;
|
||||
vector<Rect> faces;
|
||||
|
||||
const static Scalar colors[] = { CV_RGB(0,0,255),
|
||||
CV_RGB(0,128,255),
|
||||
CV_RGB(0,255,255),
|
||||
CV_RGB(0,255,0),
|
||||
CV_RGB(255,128,0),
|
||||
CV_RGB(255,255,0),
|
||||
CV_RGB(255,0,0),
|
||||
CV_RGB(255,0,255)} ;
|
||||
|
||||
Mat gray, smallImg(cvRound (img.rows/scale), cvRound(img.cols/scale), CV_8UC1 );
|
||||
MemStorage storage(cvCreateMemStorage(0));
|
||||
cvtColor( img, gray, CV_BGR2GRAY );
|
||||
resize( gray, smallImg, smallImg.size(), 0, 0, INTER_LINEAR );
|
||||
equalizeHist( smallImg, smallImg );
|
||||
CvMat _image = smallImg;
|
||||
|
||||
Mat tempimg(&_image, false);
|
||||
|
||||
cv::ocl::oclMat image(tempimg);
|
||||
CvSeq* _objects;
|
||||
|
||||
#if 1
|
||||
for(int k= 0; k<10; k++)
|
||||
{
|
||||
t = (double)cvGetTickCount();
|
||||
_objects = cascade.oclHaarDetectObjects( image, storage, 1.1,
|
||||
2, 0
|
||||
|CV_HAAR_SCALE_IMAGE
|
||||
, Size(30,30), Size(0, 0) );
|
||||
|
||||
t = (double)cvGetTickCount() - t ;
|
||||
printf( "detection time = %g ms\n", t/((double)cvGetTickFrequency()*1000.) );
|
||||
}
|
||||
|
||||
#else
|
||||
cpucascade.detectMultiScale( image, faces, 1.1,
|
||||
2, 0
|
||||
|CV_HAAR_SCALE_IMAGE
|
||||
, Size(30,30), Size(0, 0) );
|
||||
|
||||
#endif
|
||||
vector<CvAvgComp> vecAvgComp;
|
||||
Seq<CvAvgComp>(_objects).copyTo(vecAvgComp);
|
||||
faces.resize(vecAvgComp.size());
|
||||
std::transform(vecAvgComp.begin(), vecAvgComp.end(), faces.begin(), getRect());
|
||||
|
||||
for( vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++, i++ )
|
||||
{
|
||||
Mat smallImgROI;
|
||||
vector<Rect> nestedObjects;
|
||||
Point center;
|
||||
Scalar color = colors[i%8];
|
||||
int radius;
|
||||
center.x = cvRound((r->x + r->width*0.5)*scale);
|
||||
center.y = cvRound((r->y + r->height*0.5)*scale);
|
||||
radius = cvRound((r->width + r->height)*0.25*scale);
|
||||
circle( img, center, radius, color, 3, 8, 0 );
|
||||
}
|
||||
|
||||
#if WIN32
|
||||
sprintf(buff,"E:\\result1\\%d.jpg",index);
|
||||
imwrite(buff,img);
|
||||
#else
|
||||
sprintf(buff,"testdet_%d.jpg",index);
|
||||
imwrite(buff,img);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//INSTANTIATE_TEST_CASE_P(HaarTestBase, Haar, Combine(Values(1),
|
||||
// Values(1)));
|
||||
|
||||
|
||||
#endif // HAVE_OPENCL
|
1551
modules/ocl/perf/test_imgproc.cpp
Normal file
1551
modules/ocl/perf/test_imgproc.cpp
Normal file
File diff suppressed because it is too large
Load Diff
616
modules/ocl/perf/test_matrix_operation.cpp
Normal file
616
modules/ocl/perf/test_matrix_operation.cpp
Normal file
@ -0,0 +1,616 @@
|
||||
/*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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
//
|
||||
// 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 oclMaterials 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 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 "precomp.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
using namespace cvtest;
|
||||
using namespace testing;
|
||||
using namespace std;
|
||||
using namespace cv::ocl;
|
||||
////////////////////////////////converto/////////////////////////////////////////////////
|
||||
PARAM_TEST_CASE(ConvertToTestBase, MatType, MatType)
|
||||
{
|
||||
int type;
|
||||
int dst_type;
|
||||
|
||||
//src mat
|
||||
cv::Mat mat;
|
||||
cv::Mat dst;
|
||||
|
||||
// set up roi
|
||||
int roicols;
|
||||
int roirows;
|
||||
int srcx;
|
||||
int srcy;
|
||||
int dstx;
|
||||
int dsty;
|
||||
|
||||
//src mat with roi
|
||||
cv::Mat mat_roi;
|
||||
cv::Mat dst_roi;
|
||||
std::vector<cv::ocl::Info> oclinfo;
|
||||
//ocl dst mat for testing
|
||||
cv::ocl::oclMat gdst_whole;
|
||||
|
||||
//ocl mat with roi
|
||||
cv::ocl::oclMat gmat;
|
||||
cv::ocl::oclMat gdst;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
dst_type = GET_PARAM(1);
|
||||
|
||||
cv::RNG& rng = TS::ptr()->get_rng();
|
||||
cv::Size size(MWIDTH, MHEIGHT);
|
||||
|
||||
mat = randomMat(rng, size, type, 5, 16, false);
|
||||
dst = randomMat(rng, size, type, 5, 16, false);
|
||||
int devnums = getDevice(oclinfo);
|
||||
CV_Assert(devnums > 0);
|
||||
//if you want to use undefault device, set it here
|
||||
//setDevice(oclinfo[0]);
|
||||
setBinpath(CLBINPATH);
|
||||
}
|
||||
|
||||
void Has_roi(int b)
|
||||
{
|
||||
//cv::RNG& rng = TS::ptr()->get_rng();
|
||||
if(b)
|
||||
{
|
||||
//randomize ROI
|
||||
roicols = mat.cols-1; //start
|
||||
roirows = mat.rows-1;
|
||||
srcx = 1;
|
||||
srcy = 1;
|
||||
dstx = 1;
|
||||
dsty =1;
|
||||
}else
|
||||
{
|
||||
roicols = mat.cols;
|
||||
roirows = mat.rows;
|
||||
srcx = 0;
|
||||
srcy = 0;
|
||||
dstx = 0;
|
||||
dsty = 0;
|
||||
};
|
||||
|
||||
mat_roi = mat(Rect(srcx,srcy,roicols,roirows));
|
||||
dst_roi = dst(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
//gdst_whole = dst;
|
||||
//gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
//gmat = mat_roi;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct ConvertTo :ConvertToTestBase {};
|
||||
|
||||
TEST_P(ConvertTo, Accuracy)
|
||||
{
|
||||
#ifndef PRINT_KERNEL_RUN_TIME
|
||||
double totalcputick=0;
|
||||
double totalgputick=0;
|
||||
double totalgputick_kernel=0;
|
||||
double t0=0;
|
||||
double t1=0;
|
||||
double t2=0;
|
||||
for(int k=0;k<2;k++){
|
||||
totalcputick=0;
|
||||
totalgputick=0;
|
||||
totalgputick_kernel=0;
|
||||
for(int j = 0; j < LOOP_TIMES+1; j ++)
|
||||
{
|
||||
Has_roi(k);
|
||||
|
||||
t0 = (double)cvGetTickCount();//cpu start
|
||||
mat_roi.convertTo(dst_roi, dst_type);
|
||||
t0 = (double)cvGetTickCount() - t0;//cpu end
|
||||
|
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
gdst_whole = dst;
|
||||
gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
gmat = mat_roi;
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
gmat.convertTo(gdst, dst_type);
|
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
cv::Mat cpu_dst;
|
||||
gdst_whole.download (cpu_dst);//download
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
if(j == 0)
|
||||
continue;
|
||||
totalgputick=t1+totalgputick;
|
||||
totalcputick=t0+totalcputick;
|
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
}
|
||||
if(k==0){cout<<"no roi\n";}else{cout<<"with roi\n";};
|
||||
cout << "average cpu runtime is " << totalcputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
}
|
||||
#else
|
||||
for(int j = 0; j < 2; j ++)
|
||||
{
|
||||
Has_roi(j);
|
||||
gdst_whole = dst;
|
||||
gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
gmat = mat_roi;
|
||||
if(j==0){cout<<"no roi:";}else{cout<<"\nwith roi:";};
|
||||
gmat.convertTo(gdst, dst_type);
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////copyto/////////////////////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(CopyToTestBase, MatType, bool)
|
||||
{
|
||||
int type;
|
||||
|
||||
cv::Mat mat;
|
||||
cv::Mat mask;
|
||||
cv::Mat dst;
|
||||
|
||||
// set up roi
|
||||
int roicols;
|
||||
int roirows;
|
||||
int srcx;
|
||||
int srcy;
|
||||
int dstx;
|
||||
int dsty;
|
||||
int maskx;
|
||||
int masky;
|
||||
|
||||
//src mat with roi
|
||||
cv::Mat mat_roi;
|
||||
cv::Mat mask_roi;
|
||||
cv::Mat dst_roi;
|
||||
std::vector<cv::ocl::Info> oclinfo;
|
||||
//ocl dst mat for testing
|
||||
cv::ocl::oclMat gdst_whole;
|
||||
|
||||
//ocl mat with roi
|
||||
cv::ocl::oclMat gmat;
|
||||
cv::ocl::oclMat gdst;
|
||||
cv::ocl::oclMat gmask;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
|
||||
cv::RNG& rng = TS::ptr()->get_rng();
|
||||
cv::Size size(MWIDTH, MHEIGHT);
|
||||
|
||||
mat = randomMat(rng, size, type, 5, 16, false);
|
||||
dst = randomMat(rng, size, type, 5, 16, false);
|
||||
mask = randomMat(rng, size, CV_8UC1, 0, 2, false);
|
||||
|
||||
cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
|
||||
int devnums = getDevice(oclinfo);
|
||||
CV_Assert(devnums > 0);
|
||||
//if you want to use undefault device, set it here
|
||||
//setDevice(oclinfo[0]);
|
||||
setBinpath(CLBINPATH);
|
||||
}
|
||||
|
||||
void Has_roi(int b)
|
||||
{
|
||||
//cv::RNG& rng = TS::ptr()->get_rng();
|
||||
if(b)
|
||||
{
|
||||
//randomize ROI
|
||||
roicols = mat.cols-1; //start
|
||||
roirows = mat.rows-1;
|
||||
srcx = 1;
|
||||
srcy = 1;
|
||||
dstx = 1;
|
||||
dsty =1;
|
||||
maskx = 1;
|
||||
masky = 1;
|
||||
}else
|
||||
{
|
||||
roicols = mat.cols;
|
||||
roirows = mat.rows;
|
||||
srcx = 0;
|
||||
srcy = 0;
|
||||
dstx = 0;
|
||||
dsty = 0;
|
||||
maskx = 0;
|
||||
masky = 0;
|
||||
};
|
||||
|
||||
mat_roi = mat(Rect(srcx,srcy,roicols,roirows));
|
||||
mask_roi = mask(Rect(maskx,masky,roicols,roirows));
|
||||
dst_roi = dst(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
//gdst_whole = dst;
|
||||
//gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
//gmat = mat_roi;
|
||||
//gmask = mask_roi;
|
||||
}
|
||||
};
|
||||
|
||||
struct CopyTo :CopyToTestBase {};
|
||||
|
||||
TEST_P(CopyTo, Without_mask)
|
||||
{
|
||||
#ifndef PRINT_KERNEL_RUN_TIME
|
||||
double totalcputick=0;
|
||||
double totalgputick=0;
|
||||
double totalgputick_kernel=0;
|
||||
double t0=0;
|
||||
double t1=0;
|
||||
double t2=0;
|
||||
for(int k=0;k<2;k++){
|
||||
totalcputick=0;
|
||||
totalgputick=0;
|
||||
totalgputick_kernel=0;
|
||||
for(int j = 0; j < LOOP_TIMES+1; j ++)
|
||||
{
|
||||
Has_roi(k);
|
||||
|
||||
t0 = (double)cvGetTickCount();//cpu start
|
||||
mat_roi.copyTo(dst_roi);
|
||||
t0 = (double)cvGetTickCount() - t0;//cpu end
|
||||
|
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
gdst_whole = dst;
|
||||
gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
gmat = mat_roi;
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
gmat.copyTo(gdst);
|
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
cv::Mat cpu_dst;
|
||||
gdst_whole.download (cpu_dst);//download
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
if(j == 0)
|
||||
continue;
|
||||
totalgputick=t1+totalgputick;
|
||||
totalcputick=t0+totalcputick;
|
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
}
|
||||
if(k==0){cout<<"no roi\n";}else{cout<<"with roi\n";};
|
||||
cout << "average cpu runtime is " << totalcputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
}
|
||||
#else
|
||||
for(int j = 0; j < 2; j ++)
|
||||
{
|
||||
Has_roi(j);
|
||||
gdst_whole = dst;
|
||||
gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
gmat = mat_roi;
|
||||
|
||||
if(j==0){cout<<"no roi:";}else{cout<<"\nwith roi:";};
|
||||
gmat.copyTo(gdst);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_P(CopyTo, With_mask)
|
||||
{
|
||||
#ifndef PRINT_KERNEL_RUN_TIME
|
||||
double totalcputick=0;
|
||||
double totalgputick=0;
|
||||
double totalgputick_kernel=0;
|
||||
double t0=0;
|
||||
double t1=0;
|
||||
double t2=0;
|
||||
for(int k=0;k<2;k++){
|
||||
totalcputick=0;
|
||||
totalgputick=0;
|
||||
totalgputick_kernel=0;
|
||||
for(int j = 0; j < LOOP_TIMES+1; j ++)
|
||||
{
|
||||
Has_roi(k);
|
||||
|
||||
t0 = (double)cvGetTickCount();//cpu start
|
||||
mat_roi.copyTo(dst_roi,mask_roi);
|
||||
t0 = (double)cvGetTickCount() - t0;//cpu end
|
||||
|
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
gdst_whole = dst;
|
||||
gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
gmat = mat_roi;
|
||||
gmask = mask_roi;
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
gmat.copyTo(gdst, gmask);
|
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
cv::Mat cpu_dst;
|
||||
gdst_whole.download (cpu_dst);//download
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
if(j == 0)
|
||||
continue;
|
||||
totalgputick=t1+totalgputick;
|
||||
totalcputick=t0+totalcputick;
|
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
}
|
||||
if(k==0){cout<<"no roi\n";}else{cout<<"with roi\n";};
|
||||
cout << "average cpu runtime is " << totalcputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
}
|
||||
#else
|
||||
for(int j = 0; j < 2; j ++)
|
||||
{
|
||||
Has_roi(j);
|
||||
gdst_whole = dst;
|
||||
gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
|
||||
gmat = mat_roi;
|
||||
gmask = mask_roi;
|
||||
|
||||
if(j==0){cout<<"no roi:";}else{cout<<"\nwith roi:";};
|
||||
gmat.copyTo(gdst, gmask);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
///////////////////////////////////////////copyto/////////////////////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(SetToTestBase, MatType, bool)
|
||||
{
|
||||
int type;
|
||||
cv::Scalar val;
|
||||
|
||||
cv::Mat mat;
|
||||
cv::Mat mask;
|
||||
|
||||
// set up roi
|
||||
int roicols;
|
||||
int roirows;
|
||||
int srcx;
|
||||
int srcy;
|
||||
int maskx;
|
||||
int masky;
|
||||
|
||||
//src mat with roi
|
||||
cv::Mat mat_roi;
|
||||
cv::Mat mask_roi;
|
||||
std::vector<cv::ocl::Info> oclinfo;
|
||||
//ocl dst mat for testing
|
||||
cv::ocl::oclMat gmat_whole;
|
||||
|
||||
//ocl mat with roi
|
||||
cv::ocl::oclMat gmat;
|
||||
cv::ocl::oclMat gmask;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
|
||||
cv::RNG& rng = TS::ptr()->get_rng();
|
||||
cv::Size size(MWIDTH, MHEIGHT);
|
||||
|
||||
mat = randomMat(rng, size, type, 5, 16, false);
|
||||
mask = randomMat(rng, size, CV_8UC1, 0, 2, false);
|
||||
|
||||
cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
|
||||
val = cv::Scalar(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0));
|
||||
int devnums = getDevice(oclinfo);
|
||||
CV_Assert(devnums > 0);
|
||||
//if you want to use undefault device, set it here
|
||||
//setDevice(oclinfo[0]);
|
||||
setBinpath(CLBINPATH);
|
||||
}
|
||||
|
||||
void Has_roi(int b)
|
||||
{
|
||||
//cv::RNG& rng = TS::ptr()->get_rng();
|
||||
if(b)
|
||||
{
|
||||
//randomize ROI
|
||||
roicols = mat.cols-1; //start
|
||||
roirows = mat.rows-1;
|
||||
srcx = 1;
|
||||
srcy = 1;
|
||||
maskx = 1;
|
||||
masky = 1;
|
||||
}else
|
||||
{
|
||||
roicols = mat.cols;
|
||||
roirows = mat.rows;
|
||||
srcx = 0;
|
||||
srcy = 0;
|
||||
maskx = 0;
|
||||
masky = 0;
|
||||
};
|
||||
|
||||
mat_roi = mat(Rect(srcx,srcy,roicols,roirows));
|
||||
mask_roi = mask(Rect(maskx,masky,roicols,roirows));
|
||||
|
||||
//gmat_whole = mat;
|
||||
//gmat = gmat_whole(Rect(srcx,srcy,roicols,roirows));
|
||||
|
||||
//gmask = mask_roi;
|
||||
}
|
||||
};
|
||||
|
||||
struct SetTo :SetToTestBase {};
|
||||
|
||||
TEST_P(SetTo, Without_mask)
|
||||
{
|
||||
#ifndef PRINT_KERNEL_RUN_TIME
|
||||
double totalcputick=0;
|
||||
double totalgputick=0;
|
||||
double totalgputick_kernel=0;
|
||||
double t0=0;
|
||||
double t1=0;
|
||||
double t2=0;
|
||||
for(int k=0;k<2;k++){
|
||||
totalcputick=0;
|
||||
totalgputick=0;
|
||||
totalgputick_kernel=0;
|
||||
for(int j = 0; j < LOOP_TIMES+1; j ++)
|
||||
{
|
||||
Has_roi(k);
|
||||
|
||||
t0 = (double)cvGetTickCount();//cpu start
|
||||
mat_roi.setTo(val);
|
||||
t0 = (double)cvGetTickCount() - t0;//cpu end
|
||||
|
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
gmat_whole = mat;
|
||||
gmat = gmat_whole(Rect(srcx,srcy,roicols,roirows));
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
gmat.setTo(val);
|
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
cv::Mat cpu_dst;
|
||||
gmat_whole.download(cpu_dst);//download
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
if(j == 0)
|
||||
continue;
|
||||
totalgputick=t1+totalgputick;
|
||||
totalcputick=t0+totalcputick;
|
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
}
|
||||
if(k==0){cout<<"no roi\n";}else{cout<<"with roi\n";};
|
||||
cout << "average cpu runtime is " << totalcputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
}
|
||||
#else
|
||||
for(int j = 0; j < 2; j ++)
|
||||
{
|
||||
Has_roi(j);
|
||||
gmat_whole = mat;
|
||||
gmat = gmat_whole(Rect(srcx,srcy,roicols,roirows));
|
||||
|
||||
if(j==0){cout<<"no roi:";}else{cout<<"\nwith roi:";};
|
||||
gmat.setTo(val);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_P(SetTo, With_mask)
|
||||
{
|
||||
#ifndef PRINT_KERNEL_RUN_TIME
|
||||
double totalcputick=0;
|
||||
double totalgputick=0;
|
||||
double totalgputick_kernel=0;
|
||||
double t0=0;
|
||||
double t1=0;
|
||||
double t2=0;
|
||||
for(int k=0;k<2;k++){
|
||||
totalcputick=0;
|
||||
totalgputick=0;
|
||||
totalgputick_kernel=0;
|
||||
for(int j = 0; j < LOOP_TIMES+1; j ++)
|
||||
{
|
||||
Has_roi(k);
|
||||
|
||||
t0 = (double)cvGetTickCount();//cpu start
|
||||
mat_roi.setTo(val, mask_roi);
|
||||
t0 = (double)cvGetTickCount() - t0;//cpu end
|
||||
|
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
gmat_whole = mat;
|
||||
gmat = gmat_whole(Rect(srcx,srcy,roicols,roirows));
|
||||
|
||||
gmask = mask_roi;
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
gmat.setTo(val, gmask);
|
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
cv::Mat cpu_dst;
|
||||
gmat_whole.download(cpu_dst);//download
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
if(j == 0)
|
||||
continue;
|
||||
totalgputick=t1+totalgputick;
|
||||
totalcputick=t0+totalcputick;
|
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
}
|
||||
if(k==0){cout<<"no roi\n";}else{cout<<"with roi\n";};
|
||||
cout << "average cpu runtime is " << totalcputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
}
|
||||
#else
|
||||
for(int j = 0; j < 2; j ++)
|
||||
{
|
||||
Has_roi(j);
|
||||
gmat_whole = mat;
|
||||
gmat = gmat_whole(Rect(srcx,srcy,roicols,roirows));
|
||||
|
||||
gmask = mask_roi;
|
||||
|
||||
if(j==0){cout<<"no roi:";}else{cout<<"\nwith roi:";};
|
||||
gmat.setTo(val, gmask);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
//**********test************
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MatrixOperation, ConvertTo, Combine(
|
||||
Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
|
||||
Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MatrixOperation, CopyTo, Combine(
|
||||
Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
|
||||
Values(false))); // Values(false) is the reserved parameter
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MatrixOperation, SetTo, Combine(
|
||||
Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
|
||||
Values(false))); // Values(false) is the reserved parameter
|
||||
#endif
|
455
modules/ocl/perf/test_split_merge.cpp
Normal file
455
modules/ocl/perf/test_split_merge.cpp
Normal file
@ -0,0 +1,455 @@
|
||||
/*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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
//
|
||||
// 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 oclMaterials 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 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 "precomp.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
using namespace cvtest;
|
||||
using namespace testing;
|
||||
using namespace std;
|
||||
using namespace cv::ocl;
|
||||
PARAM_TEST_CASE(MergeTestBase, MatType, int)
|
||||
{
|
||||
int type;
|
||||
int channels;
|
||||
|
||||
//src mat
|
||||
cv::Mat mat1;
|
||||
cv::Mat mat2;
|
||||
cv::Mat mat3;
|
||||
cv::Mat mat4;
|
||||
|
||||
//dst mat
|
||||
cv::Mat dst;
|
||||
|
||||
// set up roi
|
||||
int roicols;
|
||||
int roirows;
|
||||
int src1x;
|
||||
int src1y;
|
||||
int src2x;
|
||||
int src2y;
|
||||
int src3x;
|
||||
int src3y;
|
||||
int src4x;
|
||||
int src4y;
|
||||
int dstx;
|
||||
int dsty;
|
||||
|
||||
//src mat with roi
|
||||
cv::Mat mat1_roi;
|
||||
cv::Mat mat2_roi;
|
||||
cv::Mat mat3_roi;
|
||||
cv::Mat mat4_roi;
|
||||
|
||||
//dst mat with roi
|
||||
cv::Mat dst_roi;
|
||||
std::vector<cv::ocl::Info> oclinfo;
|
||||
//ocl dst mat for testing
|
||||
cv::ocl::oclMat gdst_whole;
|
||||
|
||||
//ocl mat with roi
|
||||
cv::ocl::oclMat gmat1;
|
||||
cv::ocl::oclMat gmat2;
|
||||
cv::ocl::oclMat gmat3;
|
||||
cv::ocl::oclMat gmat4;
|
||||
cv::ocl::oclMat gdst;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
channels = GET_PARAM(1);
|
||||
|
||||
cv::RNG& rng = TS::ptr()->get_rng();
|
||||
cv::Size size(MWIDTH, MHEIGHT);
|
||||
|
||||
mat1 = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false);
|
||||
mat2 = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false);
|
||||
mat3 = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false);
|
||||
mat4 = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false);
|
||||
dst = randomMat(rng, size, CV_MAKETYPE(type, channels), 5, 16, false);
|
||||
int devnums = getDevice(oclinfo);
|
||||
CV_Assert(devnums > 0);
|
||||
//if you want to use undefault device, set it here
|
||||
//setDevice(oclinfo[0]);
|
||||
setBinpath(CLBINPATH);
|
||||
}
|
||||
void Has_roi(int b)
|
||||
{
|
||||
//cv::RNG& rng = TS::ptr()->get_rng();
|
||||
if(b)
|
||||
{
|
||||
//randomize ROI
|
||||
roicols = mat1.cols-1; //start
|
||||
roirows = mat1.rows-1;
|
||||
src1x = 1;
|
||||
src1y = 1;
|
||||
src2x = 1;
|
||||
src2y = 1;
|
||||
src3x = 1;
|
||||
src3y = 1;
|
||||
src4x = 1;
|
||||
src4y = 1;
|
||||
dstx = 1;
|
||||
dsty =1;
|
||||
|
||||
}else
|
||||
{
|
||||
roicols = mat1.cols;
|
||||
roirows = mat1.rows;
|
||||
src1x = 0;
|
||||
src1y = 0;
|
||||
src2x = 0;
|
||||
src2y = 0;
|
||||
src3x = 0;
|
||||
src3y = 0;
|
||||
src4x = 0;
|
||||
src4y = 0;
|
||||
dstx = 0;
|
||||
dsty = 0;
|
||||
};
|
||||
|
||||
mat1_roi = mat1(Rect(src1x,src1y,roicols,roirows));
|
||||
mat2_roi = mat2(Rect(src2x,src2y,roicols,roirows));
|
||||
mat3_roi = mat3(Rect(src3x,src3y,roicols,roirows));
|
||||
mat4_roi = mat4(Rect(src4x,src4y,roicols,roirows));
|
||||
|
||||
|
||||
dst_roi = dst(Rect(dstx,dsty,roicols,roirows));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct Merge : MergeTestBase {};
|
||||
|
||||
TEST_P(Merge, Accuracy)
|
||||
{
|
||||
#ifndef PRINT_KERNEL_RUN_TIME
|
||||
double totalcputick=0;
|
||||
double totalgputick=0;
|
||||
double totalgputick_kernel=0;
|
||||
double t0=0;
|
||||
double t1=0;
|
||||
double t2=0;
|
||||
for(int k=0;k<2;k++){
|
||||
totalcputick=0;
|
||||
totalgputick=0;
|
||||
totalgputick_kernel=0;
|
||||
for(int j = 0; j < LOOP_TIMES+1; j ++)
|
||||
{
|
||||
Has_roi(k);
|
||||
std::vector<cv::Mat> dev_src;
|
||||
dev_src.push_back(mat1_roi);
|
||||
dev_src.push_back(mat2_roi);
|
||||
dev_src.push_back(mat3_roi);
|
||||
dev_src.push_back(mat4_roi);
|
||||
t0 = (double)cvGetTickCount();//cpu start
|
||||
cv::merge(dev_src, dst_roi);
|
||||
t0 = (double)cvGetTickCount() - t0;//cpu end
|
||||
|
||||
t1 = (double)cvGetTickCount();//gpu start1 ]
|
||||
gmat1 = mat1_roi;
|
||||
gmat2 = mat2_roi;
|
||||
gmat3 = mat3_roi;
|
||||
gmat4 = mat4_roi;
|
||||
gdst_whole = dst;
|
||||
gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
std::vector<cv::ocl::oclMat> dev_gsrc;
|
||||
dev_gsrc.push_back(gmat1);
|
||||
dev_gsrc.push_back(gmat2);
|
||||
dev_gsrc.push_back(gmat3);
|
||||
dev_gsrc.push_back(gmat4);
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
cv::ocl::merge(dev_gsrc, gdst);
|
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
cv::Mat cpu_dst;
|
||||
gdst_whole.download (cpu_dst);//download
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
|
||||
if(j == 0)
|
||||
continue;
|
||||
|
||||
totalgputick=t1+totalgputick;
|
||||
totalcputick=t0+totalcputick;
|
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
}
|
||||
if(k==0){cout<<"no roi\n";}else{cout<<"with roi\n";};
|
||||
cout << "average cpu runtime is " << totalcputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
}
|
||||
#else
|
||||
for(int j = 0; j < 2; j ++)
|
||||
{
|
||||
Has_roi(j);
|
||||
gmat1 = mat1_roi;
|
||||
gmat2 = mat2_roi;
|
||||
gmat3 = mat3_roi;
|
||||
gmat4 = mat4_roi;
|
||||
gdst_whole = dst;
|
||||
gdst = gdst_whole(Rect(dstx,dsty,roicols,roirows));
|
||||
std::vector<cv::ocl::oclMat> dev_gsrc;
|
||||
dev_gsrc.push_back(gmat1);
|
||||
dev_gsrc.push_back(gmat2);
|
||||
dev_gsrc.push_back(gmat3);
|
||||
dev_gsrc.push_back(gmat4);
|
||||
|
||||
if(j==0){cout<<"no roi:";}else{cout<<"\nwith roi:";};
|
||||
cv::ocl::merge(dev_gsrc, gdst);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PARAM_TEST_CASE(SplitTestBase, MatType, int)
|
||||
{
|
||||
int type;
|
||||
int channels;
|
||||
|
||||
//src mat
|
||||
cv::Mat mat;
|
||||
|
||||
//dstmat
|
||||
cv::Mat dst1;
|
||||
cv::Mat dst2;
|
||||
cv::Mat dst3;
|
||||
cv::Mat dst4;
|
||||
|
||||
// set up roi
|
||||
int roicols;
|
||||
int roirows;
|
||||
int srcx;
|
||||
int srcy;
|
||||
int dst1x;
|
||||
int dst1y;
|
||||
int dst2x;
|
||||
int dst2y;
|
||||
int dst3x;
|
||||
int dst3y;
|
||||
int dst4x;
|
||||
int dst4y;
|
||||
|
||||
//src mat with roi
|
||||
cv::Mat mat_roi;
|
||||
|
||||
//dst mat with roi
|
||||
cv::Mat dst1_roi;
|
||||
cv::Mat dst2_roi;
|
||||
cv::Mat dst3_roi;
|
||||
cv::Mat dst4_roi;
|
||||
std::vector<cv::ocl::Info> oclinfo;
|
||||
//ocl dst mat for testing
|
||||
cv::ocl::oclMat gdst1_whole;
|
||||
cv::ocl::oclMat gdst2_whole;
|
||||
cv::ocl::oclMat gdst3_whole;
|
||||
cv::ocl::oclMat gdst4_whole;
|
||||
|
||||
//ocl mat with roi
|
||||
cv::ocl::oclMat gmat;
|
||||
cv::ocl::oclMat gdst1;
|
||||
cv::ocl::oclMat gdst2;
|
||||
cv::ocl::oclMat gdst3;
|
||||
cv::ocl::oclMat gdst4;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
channels = GET_PARAM(1);
|
||||
|
||||
cv::RNG& rng = TS::ptr()->get_rng();
|
||||
cv::Size size(MWIDTH, MHEIGHT);
|
||||
|
||||
mat = randomMat(rng, size, CV_MAKETYPE(type, channels), 5, 16, false);
|
||||
dst1 = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false);
|
||||
dst2 = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false);
|
||||
dst3 = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false);
|
||||
dst4 = randomMat(rng, size, CV_MAKETYPE(type, 1), 5, 16, false);
|
||||
int devnums = getDevice(oclinfo);
|
||||
CV_Assert(devnums > 0);
|
||||
//if you want to use undefault device, set it here
|
||||
//setDevice(oclinfo[0]);
|
||||
setBinpath(CLBINPATH);
|
||||
}
|
||||
|
||||
void Has_roi(int b)
|
||||
{
|
||||
//cv::RNG& rng = TS::ptr()->get_rng();
|
||||
if(b)
|
||||
{
|
||||
//randomize ROI
|
||||
roicols = mat.cols-1; //start
|
||||
roirows = mat.rows-1;
|
||||
srcx = 1;
|
||||
srcx = 1;
|
||||
dst1x = 1;
|
||||
dst1y =1;
|
||||
dst2x = 1;
|
||||
dst2y =1;
|
||||
dst3x = 1;
|
||||
dst3y =1;
|
||||
dst4x = 1;
|
||||
dst4y =1;
|
||||
}else
|
||||
{
|
||||
roicols = mat.cols;
|
||||
roirows = mat.rows;
|
||||
srcx = 0;
|
||||
srcy = 0;
|
||||
dst1x = 0;
|
||||
dst1y = 0;
|
||||
dst2x = 0;
|
||||
dst2y =0;
|
||||
dst3x = 0;
|
||||
dst3y =0;
|
||||
dst4x = 0;
|
||||
dst4y =0;
|
||||
};
|
||||
|
||||
mat_roi = mat(Rect(srcx,srcy,roicols,roirows));
|
||||
|
||||
dst1_roi = dst1(Rect(dst1x,dst1y,roicols,roirows));
|
||||
dst2_roi = dst2(Rect(dst2x,dst2y,roicols,roirows));
|
||||
dst3_roi = dst3(Rect(dst3x,dst3y,roicols,roirows));
|
||||
dst4_roi = dst4(Rect(dst4x,dst4y,roicols,roirows));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct Split :SplitTestBase {};
|
||||
|
||||
TEST_P(Split, Accuracy)
|
||||
{
|
||||
#ifndef PRINT_KERNEL_RUN_TIME
|
||||
double totalcputick=0;
|
||||
double totalgputick=0;
|
||||
double totalgputick_kernel=0;
|
||||
double t0=0;
|
||||
double t1=0;
|
||||
double t2=0;
|
||||
for(int k=0;k<2;k++){
|
||||
totalcputick=0;
|
||||
totalgputick=0;
|
||||
totalgputick_kernel=0;
|
||||
for(int j = 0; j < LOOP_TIMES+1; j ++)
|
||||
{
|
||||
Has_roi(k);
|
||||
cv::Mat dev_dst[4] = {dst1_roi, dst2_roi, dst3_roi, dst4_roi};
|
||||
cv::ocl::oclMat dev_gdst[4] = {gdst1, gdst2, gdst3, gdst4};
|
||||
t0 = (double)cvGetTickCount();//cpu start
|
||||
cv::split(mat_roi, dev_dst);
|
||||
t0 = (double)cvGetTickCount() - t0;//cpu end
|
||||
|
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
gdst1_whole = dst1;
|
||||
gdst1 = gdst1_whole(Rect(dst1x,dst1y,roicols,roirows));
|
||||
|
||||
gdst2_whole = dst2;
|
||||
gdst2 = gdst2_whole(Rect(dst2x,dst2y,roicols,roirows));
|
||||
|
||||
gdst3_whole = dst3;
|
||||
gdst3 = gdst3_whole(Rect(dst3x,dst3y,roicols,roirows));
|
||||
|
||||
gdst4_whole = dst4;
|
||||
gdst4 = gdst4_whole(Rect(dst4x,dst4y,roicols,roirows));
|
||||
|
||||
gmat = mat_roi;
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
cv::ocl::split(gmat, dev_gdst);
|
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
cv::Mat cpu_dst1;
|
||||
cv::Mat cpu_dst2;
|
||||
cv::Mat cpu_dst3;
|
||||
cv::Mat cpu_dst4;
|
||||
gdst1_whole.download(cpu_dst1);
|
||||
gdst2_whole.download(cpu_dst2);
|
||||
gdst3_whole.download(cpu_dst3);
|
||||
gdst4_whole.download(cpu_dst4);
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
if(j == 0)
|
||||
continue;
|
||||
totalgputick=t1+totalgputick;
|
||||
totalcputick=t0+totalcputick;
|
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
}
|
||||
if(k==0){cout<<"no roi\n";}else{cout<<"with roi\n";};
|
||||
cout << "average cpu runtime is " << totalcputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl;
|
||||
}
|
||||
#else
|
||||
for(int j = 0; j < 2; j ++)
|
||||
{
|
||||
Has_roi(j);
|
||||
cv::Mat dev_dst[4] = {dst1_roi, dst2_roi, dst3_roi, dst4_roi};
|
||||
cv::ocl::oclMat dev_gdst[4] = {gdst1, gdst2, gdst3, gdst4};
|
||||
gdst1_whole = dst1;
|
||||
gdst1 = gdst1_whole(Rect(dst1x,dst1y,roicols,roirows));
|
||||
|
||||
gdst2_whole = dst2;
|
||||
gdst2 = gdst2_whole(Rect(dst2x,dst2y,roicols,roirows));
|
||||
|
||||
gdst3_whole = dst3;
|
||||
gdst3 = gdst3_whole(Rect(dst3x,dst3y,roicols,roirows));
|
||||
|
||||
gdst4_whole = dst4;
|
||||
gdst4 = gdst4_whole(Rect(dst4x,dst4y,roicols,roirows));
|
||||
gmat = mat_roi;
|
||||
if(j==0){cout<<"no roi:";}else{cout<<"\nwith roi:";};
|
||||
cv::ocl::split(gmat, dev_gdst);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************test*****************
|
||||
INSTANTIATE_TEST_CASE_P(SplitMerge, Merge, Combine(
|
||||
Values(CV_8UC4, CV_32FC4), Values(1, 4)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SplitMerge, Split , Combine(
|
||||
Values(CV_8U, CV_32S, CV_32F), Values(1, 4)));
|
||||
|
||||
#endif // HAVE_OPENCL
|
265
modules/ocl/perf/utility.cpp
Normal file
265
modules/ocl/perf/utility.cpp
Normal file
@ -0,0 +1,265 @@
|
||||
/*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 "precomp.hpp"
|
||||
#define VARNAME(A) #A
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
using namespace cvtest;
|
||||
|
||||
|
||||
//std::string generateVarList(int first,...)
|
||||
//{
|
||||
// vector<std::string> varname;
|
||||
//
|
||||
// va_list argp;
|
||||
// string s;
|
||||
// stringstream ss;
|
||||
// va_start(argp,first);
|
||||
// int i=first;
|
||||
// while(i!=-1)
|
||||
// {
|
||||
// ss<<i<<",";
|
||||
// i=va_arg(argp,int);
|
||||
// };
|
||||
// s=ss.str();
|
||||
// va_end(argp);
|
||||
// return s;
|
||||
//};
|
||||
|
||||
//std::string generateVarList(int& p1,int& p2)
|
||||
//{
|
||||
// stringstream ss;
|
||||
// ss<<VARNAME(p1)<<":"<<src1x<<","<<VARNAME(p2)<<":"<<src1y;
|
||||
// return ss.str();
|
||||
//};
|
||||
|
||||
int randomInt(int minVal, int maxVal)
|
||||
{
|
||||
RNG& rng = TS::ptr()->get_rng();
|
||||
return rng.uniform(minVal, maxVal);
|
||||
}
|
||||
|
||||
double randomDouble(double minVal, double maxVal)
|
||||
{
|
||||
RNG& rng = TS::ptr()->get_rng();
|
||||
return rng.uniform(minVal, maxVal);
|
||||
}
|
||||
|
||||
Size randomSize(int minVal, int maxVal)
|
||||
{
|
||||
return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal));
|
||||
}
|
||||
|
||||
Scalar randomScalar(double minVal, double maxVal)
|
||||
{
|
||||
return Scalar(randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal));
|
||||
}
|
||||
|
||||
Mat randomMat(Size size, int type, double minVal, double maxVal)
|
||||
{
|
||||
return randomMat(TS::ptr()->get_rng(), size, type, minVal, maxVal, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void showDiff(InputArray gold_, InputArray actual_, double eps)
|
||||
{
|
||||
Mat gold;
|
||||
if (gold_.kind() == _InputArray::MAT)
|
||||
gold = gold_.getMat();
|
||||
else
|
||||
gold_.getGpuMat().download(gold);
|
||||
|
||||
Mat actual;
|
||||
if (actual_.kind() == _InputArray::MAT)
|
||||
actual = actual_.getMat();
|
||||
else
|
||||
actual_.getGpuMat().download(actual);
|
||||
|
||||
Mat diff;
|
||||
absdiff(gold, actual, diff);
|
||||
threshold(diff, diff, eps, 255.0, cv::THRESH_BINARY);
|
||||
|
||||
namedWindow("gold", WINDOW_NORMAL);
|
||||
namedWindow("actual", WINDOW_NORMAL);
|
||||
namedWindow("diff", WINDOW_NORMAL);
|
||||
|
||||
imshow("gold", gold);
|
||||
imshow("actual", actual);
|
||||
imshow("diff", diff);
|
||||
|
||||
waitKey();
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
bool supportFeature(const DeviceInfo& info, FeatureSet feature)
|
||||
{
|
||||
return TargetArchs::builtWith(feature) && info.supports(feature);
|
||||
}
|
||||
|
||||
const vector<DeviceInfo>& devices()
|
||||
{
|
||||
static vector<DeviceInfo> devs;
|
||||
static bool first = true;
|
||||
|
||||
if (first)
|
||||
{
|
||||
int deviceCount = getCudaEnabledDeviceCount();
|
||||
|
||||
devs.reserve(deviceCount);
|
||||
|
||||
for (int i = 0; i < deviceCount; ++i)
|
||||
{
|
||||
DeviceInfo info(i);
|
||||
if (info.isCompatible())
|
||||
devs.push_back(info);
|
||||
}
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
||||
return devs;
|
||||
}
|
||||
|
||||
vector<DeviceInfo> devices(FeatureSet feature)
|
||||
{
|
||||
const vector<DeviceInfo>& d = devices();
|
||||
|
||||
vector<DeviceInfo> devs_filtered;
|
||||
|
||||
if (TargetArchs::builtWith(feature))
|
||||
{
|
||||
devs_filtered.reserve(d.size());
|
||||
|
||||
for (size_t i = 0, size = d.size(); i < size; ++i)
|
||||
{
|
||||
const DeviceInfo& info = d[i];
|
||||
|
||||
if (info.supports(feature))
|
||||
devs_filtered.push_back(info);
|
||||
}
|
||||
}
|
||||
|
||||
return devs_filtered;
|
||||
}
|
||||
*/
|
||||
|
||||
vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end)
|
||||
{
|
||||
vector<MatType> v;
|
||||
|
||||
v.reserve((depth_end - depth_start + 1) * (cn_end - cn_start + 1));
|
||||
|
||||
for (int depth = depth_start; depth <= depth_end; ++depth)
|
||||
{
|
||||
for (int cn = cn_start; cn <= cn_end; ++cn)
|
||||
{
|
||||
v.push_back(CV_MAKETYPE(depth, cn));
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
const vector<MatType>& all_types()
|
||||
{
|
||||
static vector<MatType> v = types(CV_8U, CV_64F, 1, 4);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
Mat readImage(const string& fileName, int flags)
|
||||
{
|
||||
return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags);
|
||||
}
|
||||
|
||||
Mat readImageType(const string& fname, int type)
|
||||
{
|
||||
Mat src = readImage(fname, CV_MAT_CN(type) == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR);
|
||||
if (CV_MAT_CN(type) == 4)
|
||||
{
|
||||
Mat temp;
|
||||
cvtColor(src, temp, cv::COLOR_BGR2BGRA);
|
||||
swap(src, temp);
|
||||
}
|
||||
src.convertTo(src, CV_MAT_DEPTH(type));
|
||||
return src;
|
||||
}
|
||||
|
||||
double checkNorm(const Mat& m)
|
||||
{
|
||||
return norm(m, NORM_INF);
|
||||
}
|
||||
|
||||
double checkNorm(const Mat& m1, const Mat& m2)
|
||||
{
|
||||
return norm(m1, m2, NORM_INF);
|
||||
}
|
||||
|
||||
double checkSimilarity(const Mat& m1, const Mat& m2)
|
||||
{
|
||||
Mat diff;
|
||||
matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED);
|
||||
return std::abs(diff.at<float>(0, 0) - 1.f);
|
||||
}
|
||||
|
||||
/*
|
||||
void cv::ocl::PrintTo(const DeviceInfo& info, ostream* os)
|
||||
{
|
||||
(*os) << info.name();
|
||||
}
|
||||
*/
|
||||
|
||||
void PrintTo(const Inverse& inverse, std::ostream* os)
|
||||
{
|
||||
if (inverse)
|
||||
(*os) << "inverse";
|
||||
else
|
||||
(*os) << "direct";
|
||||
}
|
177
modules/ocl/perf/utility.hpp
Normal file
177
modules/ocl/perf/utility.hpp
Normal file
@ -0,0 +1,177 @@
|
||||
/*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 __OPENCV_TEST_UTILITY_HPP__
|
||||
#define __OPENCV_TEST_UTILITY_HPP__
|
||||
//#define PRINT_KERNEL_RUN_TIME
|
||||
#ifdef PRINT_KERNEL_RUN_TIME
|
||||
#define LOOP_TIMES 1
|
||||
#else
|
||||
#define LOOP_TIMES 1
|
||||
#endif
|
||||
#define MWIDTH 2557
|
||||
#define MHEIGHT 2579
|
||||
#define CLBINPATH ".\\"
|
||||
int randomInt(int minVal, int maxVal);
|
||||
double randomDouble(double minVal, double maxVal);
|
||||
|
||||
//std::string generateVarList(int first,...);
|
||||
std::string generateVarList(int& p1,int& p2);
|
||||
cv::Size randomSize(int minVal, int maxVal);
|
||||
cv::Scalar randomScalar(double minVal, double maxVal);
|
||||
cv::Mat randomMat(cv::Size size, int type, double minVal = 0.0, double maxVal = 255.0);
|
||||
|
||||
void showDiff(cv::InputArray gold, cv::InputArray actual, double eps);
|
||||
|
||||
//! return true if device supports specified feature and gpu module was built with support the feature.
|
||||
//bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature);
|
||||
|
||||
//! return all devices compatible with current gpu module build.
|
||||
//const std::vector<cv::ocl::DeviceInfo>& devices();
|
||||
//! return all devices compatible with current gpu module build which support specified feature.
|
||||
//std::vector<cv::ocl::DeviceInfo> devices(cv::gpu::FeatureSet feature);
|
||||
|
||||
//! read image from testdata folder.
|
||||
cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR);
|
||||
cv::Mat readImageType(const std::string& fname, int type);
|
||||
|
||||
double checkNorm(const cv::Mat& m);
|
||||
double checkNorm(const cv::Mat& m1, const cv::Mat& m2);
|
||||
double checkSimilarity(const cv::Mat& m1, const cv::Mat& m2);
|
||||
|
||||
#define EXPECT_MAT_NORM(mat, eps) \
|
||||
{ \
|
||||
EXPECT_LE(checkNorm(cv::Mat(mat)), eps) \
|
||||
}
|
||||
|
||||
//#define EXPECT_MAT_NEAR(mat1, mat2, eps) \
|
||||
//{ \
|
||||
// ASSERT_EQ(mat1.type(), mat2.type()); \
|
||||
// ASSERT_EQ(mat1.size(), mat2.size()); \
|
||||
// EXPECT_LE(checkNorm(cv::Mat(mat1), cv::Mat(mat2)), eps); \
|
||||
//}
|
||||
|
||||
#define EXPECT_MAT_NEAR(mat1, mat2, eps,s) \
|
||||
{ \
|
||||
ASSERT_EQ(mat1.type(), mat2.type()); \
|
||||
ASSERT_EQ(mat1.size(), mat2.size()); \
|
||||
EXPECT_LE(checkNorm(cv::Mat(mat1), cv::Mat(mat2)), eps)<<s; \
|
||||
}
|
||||
|
||||
#define EXPECT_MAT_SIMILAR(mat1, mat2, eps) \
|
||||
{ \
|
||||
ASSERT_EQ(mat1.type(), mat2.type()); \
|
||||
ASSERT_EQ(mat1.size(), mat2.size()); \
|
||||
EXPECT_LE(checkSimilarity(cv::Mat(mat1), cv::Mat(mat2)), eps); \
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace ocl
|
||||
{
|
||||
// void PrintTo(const DeviceInfo& info, std::ostream* os);
|
||||
}
|
||||
}
|
||||
|
||||
using perf::MatDepth;
|
||||
using perf::MatType;
|
||||
|
||||
//! return vector with types from specified range.
|
||||
std::vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end);
|
||||
|
||||
//! return vector with all types (depth: CV_8U-CV_64F, channels: 1-4).
|
||||
const std::vector<MatType>& all_types();
|
||||
|
||||
class Inverse
|
||||
{
|
||||
public:
|
||||
inline Inverse(bool val = false) : val_(val) {}
|
||||
|
||||
inline operator bool() const { return val_; }
|
||||
|
||||
private:
|
||||
bool val_;
|
||||
};
|
||||
|
||||
void PrintTo(const Inverse& useRoi, std::ostream* os);
|
||||
|
||||
CV_ENUM(CmpCode, cv::CMP_EQ, cv::CMP_GT, cv::CMP_GE, cv::CMP_LT, cv::CMP_LE, cv::CMP_NE)
|
||||
|
||||
CV_ENUM(NormCode, cv::NORM_INF, cv::NORM_L1, cv::NORM_L2, cv::NORM_TYPE_MASK, cv::NORM_RELATIVE, cv::NORM_MINMAX)
|
||||
|
||||
enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
|
||||
CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
|
||||
|
||||
CV_ENUM(ReduceOp, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN)
|
||||
|
||||
CV_FLAGS(GemmFlags, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T);
|
||||
|
||||
CV_ENUM(MorphOp, cv::MORPH_OPEN, cv::MORPH_CLOSE, cv::MORPH_GRADIENT, cv::MORPH_TOPHAT, cv::MORPH_BLACKHAT)
|
||||
|
||||
CV_ENUM(ThreshOp, cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV)
|
||||
|
||||
CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC)
|
||||
|
||||
CV_ENUM(Border, cv::BORDER_REFLECT101, cv::BORDER_REPLICATE, cv::BORDER_CONSTANT, cv::BORDER_REFLECT, cv::BORDER_WRAP)
|
||||
|
||||
CV_FLAGS(WarpFlags, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::WARP_INVERSE_MAP)
|
||||
|
||||
CV_ENUM(TemplateMethod, cv::TM_SQDIFF, cv::TM_SQDIFF_NORMED, cv::TM_CCORR, cv::TM_CCORR_NORMED, cv::TM_CCOEFF, cv::TM_CCOEFF_NORMED)
|
||||
|
||||
CV_FLAGS(DftFlags, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT)
|
||||
|
||||
void run_perf_test();
|
||||
|
||||
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
|
||||
|
||||
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
|
||||
|
||||
#define ALL_DEVICES testing::ValuesIn(devices())
|
||||
#define DEVICES(feature) testing::ValuesIn(devices(feature))
|
||||
|
||||
#define ALL_TYPES testing::ValuesIn(all_types())
|
||||
#define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end))
|
||||
|
||||
#define DIFFERENT_SIZES testing::Values(cv::Size(128, 128), cv::Size(113, 113))
|
||||
|
||||
#define DIRECT_INVERSE testing::Values(Inverse(false), Inverse(true))
|
||||
|
||||
#endif // __OPENCV_TEST_UTILITY_HPP__
|
Loading…
Reference in New Issue
Block a user