1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
43
#include "test_precomp.hpp"
46
TestHaarCascadeLoader::TestHaarCascadeLoader(std::string testName_, std::string cascadeName_)
48
NCVTestProvider(testName_),
49
cascadeName(cascadeName_)
54
bool TestHaarCascadeLoader::toString(std::ofstream &strOut)
56
strOut << "cascadeName=" << cascadeName << std::endl;
61
bool TestHaarCascadeLoader::init()
67
bool TestHaarCascadeLoader::process()
72
Ncv32u numStages, numNodes, numFeatures;
73
Ncv32u numStages_2 = 0, numNodes_2 = 0, numFeatures_2 = 0;
75
ncvStat = ncvHaarGetClassifierSize(this->cascadeName, numStages, numNodes, numFeatures);
76
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
78
NCVVectorAlloc<HaarStage64> h_HaarStages(*this->allocatorCPU.get(), numStages);
79
ncvAssertReturn(h_HaarStages.isMemAllocated(), false);
80
NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes(*this->allocatorCPU.get(), numNodes);
81
ncvAssertReturn(h_HaarNodes.isMemAllocated(), false);
82
NCVVectorAlloc<HaarFeature64> h_HaarFeatures(*this->allocatorCPU.get(), numFeatures);
83
ncvAssertReturn(h_HaarFeatures.isMemAllocated(), false);
85
NCVVectorAlloc<HaarStage64> h_HaarStages_2(*this->allocatorCPU.get(), numStages);
86
ncvAssertReturn(h_HaarStages_2.isMemAllocated(), false);
87
NCVVectorAlloc<HaarClassifierNode128> h_HaarNodes_2(*this->allocatorCPU.get(), numNodes);
88
ncvAssertReturn(h_HaarNodes_2.isMemAllocated(), false);
89
NCVVectorAlloc<HaarFeature64> h_HaarFeatures_2(*this->allocatorCPU.get(), numFeatures);
90
ncvAssertReturn(h_HaarFeatures_2.isMemAllocated(), false);
92
HaarClassifierCascadeDescriptor haar;
93
HaarClassifierCascadeDescriptor haar_2;
95
NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
98
const std::string testNvbinName = cv::tempfile("test.nvbin");
99
ncvStat = ncvHaarLoadFromFile_host(this->cascadeName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
100
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
102
ncvStat = ncvHaarStoreNVBIN_host(testNvbinName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
103
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
105
ncvStat = ncvHaarGetClassifierSize(testNvbinName, numStages_2, numNodes_2, numFeatures_2);
106
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
108
ncvStat = ncvHaarLoadFromFile_host(testNvbinName, haar_2, h_HaarStages_2, h_HaarNodes_2, h_HaarFeatures_2);
109
ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
114
bool bLoopVirgin = true;
119
numStages_2 != numStages ||
120
numNodes_2 != numNodes ||
121
numFeatures_2 != numFeatures ||
122
haar.NumStages != haar_2.NumStages ||
123
haar.NumClassifierRootNodes != haar_2.NumClassifierRootNodes ||
124
haar.NumClassifierTotalNodes != haar_2.NumClassifierTotalNodes ||
125
haar.NumFeatures != haar_2.NumFeatures ||
126
haar.ClassifierSize.width != haar_2.ClassifierSize.width ||
127
haar.ClassifierSize.height != haar_2.ClassifierSize.height ||
128
haar.bNeedsTiltedII != haar_2.bNeedsTiltedII ||
129
haar.bHasStumpsOnly != haar_2.bHasStumpsOnly )
133
if (memcmp(h_HaarStages.ptr(), h_HaarStages_2.ptr(), haar.NumStages * sizeof(HaarStage64)) ||
134
memcmp(h_HaarNodes.ptr(), h_HaarNodes_2.ptr(), haar.NumClassifierTotalNodes * sizeof(HaarClassifierNode128)) ||
135
memcmp(h_HaarFeatures.ptr(), h_HaarFeatures_2.ptr(), haar.NumFeatures * sizeof(HaarFeature64)) )
150
bool TestHaarCascadeLoader::deinit()