Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/core/test/test_rotatedrect.cpp
16337 views
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
// Intel License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2000, Intel Corporation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of Intel Corporation may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#include "test_precomp.hpp"
43
44
namespace opencv_test { namespace {
45
46
class Core_RotatedRectConstructorTest : public cvtest::BaseTest
47
{
48
public:
49
Core_RotatedRectConstructorTest();
50
protected:
51
int prepare_test_case( int );
52
void run_func();
53
int validate_test_results( int );
54
float MAX_COORD_VAL;
55
Point2f a, b, c;
56
RotatedRect rec;
57
};
58
59
Core_RotatedRectConstructorTest::Core_RotatedRectConstructorTest()
60
{
61
test_case_count = 100;
62
MAX_COORD_VAL = 1000.0f;
63
}
64
65
int Core_RotatedRectConstructorTest::prepare_test_case( int test_case_idx )
66
{
67
cvtest::BaseTest::prepare_test_case( test_case_idx );
68
RNG& rng = ts->get_rng();
69
a = Point2f( rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL), rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL) );
70
do
71
{
72
b = Point2f( rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL), rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL) );
73
}
74
while( cv::norm(a - b) <= FLT_EPSILON );
75
Vec2f along(a - b);
76
Vec2f perp = Vec2f(-along[1], along[0]);
77
double d = (double) rng.uniform(1.0f, 5.0f);
78
if( cvtest::randInt(rng) % 2 == 0 ) d = -d;
79
c = Point2f( (float) ((double) b.x + d * perp[0]), (float) ((double) b.y + d * perp[1]) );
80
return 1;
81
}
82
83
void Core_RotatedRectConstructorTest::run_func()
84
{
85
rec = RotatedRect(a, b, c);
86
}
87
88
int Core_RotatedRectConstructorTest::validate_test_results( int )
89
{
90
Point2f vertices[4];
91
rec.points(vertices);
92
int count_match = 0;
93
for( int i = 0; i < 4; i++ )
94
{
95
if( cv::norm(vertices[i] - a) <= 0.001 ) count_match++;
96
else if( cv::norm(vertices[i] - b) <= 0.001 ) count_match++;
97
else if( cv::norm(vertices[i] - c) <= 0.001 ) count_match++;
98
}
99
if( count_match == 3 )
100
return cvtest::TS::OK;
101
ts->printf( cvtest::TS::LOG, "RotatedRect end points don't match those supplied in constructor");
102
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
103
return cvtest::TS::OK;
104
}
105
106
TEST(Core_RotatedRect, three_point_constructor) { Core_RotatedRectConstructorTest test; test.safe_run(); }
107
108
}} // namespace
109
110