~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/modules/cudalegacy/test/TestHaarCascadeLoader.cpp

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*M///////////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 
4
//
 
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.
 
8
//
 
9
//
 
10
//                           License Agreement
 
11
//                For Open Source Computer Vision Library
 
12
//
 
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.
 
16
//
 
17
// Redistribution and use in source and binary forms, with or without modification,
 
18
// are permitted provided that the following conditions are met:
 
19
//
 
20
//   * Redistribution's of source code must retain the above copyright notice,
 
21
//     this list of conditions and the following disclaimer.
 
22
//
 
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.
 
26
//
 
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.
 
29
//
 
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.
 
40
//
 
41
//M*/
 
42
 
 
43
#include "test_precomp.hpp"
 
44
 
 
45
 
 
46
TestHaarCascadeLoader::TestHaarCascadeLoader(std::string testName_, std::string cascadeName_)
 
47
    :
 
48
    NCVTestProvider(testName_),
 
49
    cascadeName(cascadeName_)
 
50
{
 
51
}
 
52
 
 
53
 
 
54
bool TestHaarCascadeLoader::toString(std::ofstream &strOut)
 
55
{
 
56
    strOut << "cascadeName=" << cascadeName << std::endl;
 
57
    return true;
 
58
}
 
59
 
 
60
 
 
61
bool TestHaarCascadeLoader::init()
 
62
{
 
63
    return true;
 
64
}
 
65
 
 
66
 
 
67
bool TestHaarCascadeLoader::process()
 
68
{
 
69
    NCVStatus ncvStat;
 
70
    bool rcode = false;
 
71
 
 
72
    Ncv32u numStages, numNodes, numFeatures;
 
73
    Ncv32u numStages_2 = 0, numNodes_2 = 0, numFeatures_2 = 0;
 
74
 
 
75
    ncvStat = ncvHaarGetClassifierSize(this->cascadeName, numStages, numNodes, numFeatures);
 
76
    ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
 
77
 
 
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);
 
84
 
 
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);
 
91
 
 
92
    HaarClassifierCascadeDescriptor haar;
 
93
    HaarClassifierCascadeDescriptor haar_2;
 
94
 
 
95
    NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting());
 
96
    NCV_SKIP_COND_BEGIN
 
97
 
 
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);
 
101
 
 
102
    ncvStat = ncvHaarStoreNVBIN_host(testNvbinName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures);
 
103
    ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
 
104
 
 
105
    ncvStat = ncvHaarGetClassifierSize(testNvbinName, numStages_2, numNodes_2, numFeatures_2);
 
106
    ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
 
107
 
 
108
    ncvStat = ncvHaarLoadFromFile_host(testNvbinName, haar_2, h_HaarStages_2, h_HaarNodes_2, h_HaarFeatures_2);
 
109
    ncvAssertReturn(ncvStat == NCV_SUCCESS, false);
 
110
 
 
111
    NCV_SKIP_COND_END
 
112
 
 
113
    //bit-to-bit check
 
114
    bool bLoopVirgin = true;
 
115
 
 
116
    NCV_SKIP_COND_BEGIN
 
117
 
 
118
    if (
 
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          )
 
130
    {
 
131
        bLoopVirgin = false;
 
132
    }
 
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)) )
 
136
    {
 
137
        bLoopVirgin = false;
 
138
    }
 
139
    NCV_SKIP_COND_END
 
140
 
 
141
    if (bLoopVirgin)
 
142
    {
 
143
        rcode = true;
 
144
    }
 
145
 
 
146
    return rcode;
 
147
}
 
148
 
 
149
 
 
150
bool TestHaarCascadeLoader::deinit()
 
151
{
 
152
    return true;
 
153
}