/*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, Multicoreware, Inc., all rights reserved. // Copyright (C) 2010-2012, Advanced Micro Devices, 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 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" #if GTEST_OS_WINDOWS #define NOMINMAX # include #endif // This program test most of the functions in ocl module and generate data metrix of x-factor in .csv files // All images needed in this test are in samples/gpu folder. // For haar template, haarcascade_frontalface_alt.xml shouold be in working directory void TestSystem::run() { if (is_list_mode_) { for (vector::iterator it = tests_.begin(); it != tests_.end(); ++it) { cout << (*it)->name() << endl; } return; } // Run test initializers for (vector::iterator it = inits_.begin(); it != inits_.end(); ++it) { if ((*it)->name().find(test_filter_, 0) != string::npos) { (*it)->run(); } } printHeading(); writeHeading(); // Run tests for (vector::iterator it = tests_.begin(); it != tests_.end(); ++it) { try { if ((*it)->name().find(test_filter_, 0) != string::npos) { cout << endl << (*it)->name() << ":\n"; setCurrentTest((*it)->name()); //fprintf(record_,"%s\n",(*it)->name().c_str()); (*it)->run(); finishCurrentSubtest(); } } catch (const Exception &) { // Message is printed via callback resetCurrentSubtest(); } catch (const runtime_error &e) { printError(e.what()); resetCurrentSubtest(); } } printSummary(); writeSummary(); } void TestSystem::finishCurrentSubtest() { if (cur_subtest_is_empty_) // There is no need to print subtest statistics { return; } int is_accurate = is_accurate_; double cpu_time = cpu_elapsed_ / getTickFrequency() * 1000.0; double gpu_time = gpu_elapsed_ / getTickFrequency() * 1000.0; double gpu_full_time = gpu_full_elapsed_ / getTickFrequency() * 1000.0; double speedup = static_cast(cpu_elapsed_) / std::max(1.0, gpu_elapsed_); speedup_total_ += speedup; double fullspeedup = static_cast(cpu_elapsed_) / std::max(1.0, gpu_full_elapsed_); speedup_full_total_ += fullspeedup; if (speedup > top_) { speedup_faster_count_++; } else if (speedup < bottom_) { speedup_slower_count_++; } else { speedup_equal_count_++; } if (fullspeedup > top_) { speedup_full_faster_count_++; } else if (fullspeedup < bottom_) { speedup_full_slower_count_++; } else { speedup_full_equal_count_++; } // compute min, max and std::sort(gpu_times_.begin(), gpu_times_.end()); double gpu_min = gpu_times_.front() / getTickFrequency() * 1000.0; double gpu_max = gpu_times_.back() / getTickFrequency() * 1000.0; double deviation = 0; if (gpu_times_.size() > 1) { double sum = 0; for (size_t i = 0; i < gpu_times_.size(); i++) { int64 diff = gpu_times_[i] - static_cast(gpu_elapsed_); double diff_time = diff * 1000 / getTickFrequency(); sum += diff_time * diff_time; } deviation = std::sqrt(sum / gpu_times_.size()); } printMetrics(is_accurate, cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup); writeMetrics(is_accurate, cpu_time, gpu_time, gpu_full_time, speedup, fullspeedup, gpu_min, gpu_max, deviation); num_subtests_called_++; resetCurrentSubtest(); } double TestSystem::meanTime(const vector &samples) { double sum = accumulate(samples.begin(), samples.end(), 0.); return sum / samples.size(); } void TestSystem::printHeading() { cout << endl; cout<< setiosflags(ios_base::left); #if 0 cout< 0&&n <= cols * rows); assert(type == CV_8UC1||type == CV_8UC3||type == CV_8UC4 ||type == CV_32FC1||type == CV_32FC3||type == CV_32FC4); RNG rng; //generate random position without duplication std::vector pos; for(int i = 0; i < cols * rows; i++) { pos.push_back(i); } for(int i = 0; i < cols * rows; i++) { int temp = i + rng.uniform(0, cols * rows - 1 - i); int temp1 = pos[temp]; pos[temp]= pos[i]; pos[i] = temp1; } std::vector selected_pos; for(int i = 0; i < n; i++) { selected_pos.push_back(pos[i]); } pos.clear(); //end of generating random y without duplication if(type == CV_8UC1) { typedef struct coorStruct_ { int x; int y; uchar xy; }coorStruct; coorStruct coor_struct; std::vector coor; for(int i = 0; i < n; i++) { coor_struct.x = -1; coor_struct.y = -1; coor_struct.xy = (uchar)rng.uniform(low, high); coor.push_back(coor_struct); } for(int i = 0; i < n; i++) { coor[i].y = selected_pos[i]/cols; coor[i].x = selected_pos[i]%cols; } selected_pos.clear(); mat.create(rows, cols, type); mat.setTo(0); for(int i = 0; i < n; i++) { mat.at(coor[i].y, coor[i].x) = coor[i].xy; } } if(type == CV_8UC4 || type == CV_8UC3) { mat.create(rows, cols, type); mat.setTo(0); typedef struct Coor { int x; int y; uchar r; uchar g; uchar b; uchar alpha; }coor; std::vector coor_vect; coor xy_coor; for(int i = 0; i < n; i++) { xy_coor.r = (uchar)rng.uniform(low, high); xy_coor.g = (uchar)rng.uniform(low, high); xy_coor.b = (uchar)rng.uniform(low, high); if(type == CV_8UC4) xy_coor.alpha = (uchar)rng.uniform(low, high); coor_vect.push_back(xy_coor); } for(int i = 0; i < n; i++) { coor_vect[i].y = selected_pos[i]/((int)mat.step1()/mat.elemSize()); coor_vect[i].x = selected_pos[i]%((int)mat.step1()/mat.elemSize()); //printf("coor_vect[%d] = (%d, %d)\n", i, coor_vect[i].y, coor_vect[i].x); } if(type == CV_8UC4) { for(int i = 0; i < n; i++) { mat.at(coor_vect[i].y, 4 * coor_vect[i].x) = coor_vect[i].r; mat.at(coor_vect[i].y, 4 * coor_vect[i].x + 1) = coor_vect[i].g; mat.at(coor_vect[i].y, 4 * coor_vect[i].x + 2) = coor_vect[i].b; mat.at(coor_vect[i].y, 4 * coor_vect[i].x + 3) = coor_vect[i].alpha; } }else if(type == CV_8UC3) { for(int i = 0; i < n; i++) { mat.at(coor_vect[i].y, 3 * coor_vect[i].x) = coor_vect[i].r; mat.at(coor_vect[i].y, 3 * coor_vect[i].x + 1) = coor_vect[i].g; mat.at(coor_vect[i].y, 3 * coor_vect[i].x + 2) = coor_vect[i].b; } } } } #endif string abspath(const string &relpath) { return TestSystem::instance().workingDir() + relpath; } 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, TM_CCORR_NORMED); return std::abs(diff.at(0, 0) - 1.f); } int ExpectedMatNear(cv::Mat dst, cv::Mat cpu_dst, double eps) { assert(dst.type() == cpu_dst.type()); assert(dst.size() == cpu_dst.size()); if(checkNorm(cv::Mat(dst), cv::Mat(cpu_dst)) < eps ||checkNorm(cv::Mat(dst), cv::Mat(cpu_dst)) == eps) return 1; return 0; } int ExceptDoubleNear(double val1, double val2, double abs_error) { const double diff = fabs(val1 - val2); if (diff <= abs_error) return 1; return 0; } int ExceptedMatSimilar(cv::Mat dst, cv::Mat cpu_dst, double eps) { assert(dst.type() == cpu_dst.type()); assert(dst.size() == cpu_dst.size()); if(checkSimilarity(cv::Mat(cpu_dst), cv::Mat(dst)) <= eps) return 1; return 0; }