Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
bc3dd245
Commit
bc3dd245
authored
Jul 31, 2013
by
Nghia Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test cpp
parent
61386e1a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
499 additions
and
0 deletions
+499
-0
intersection.png
modules/imgproc/doc/pics/intersection.png
+0
-0
test_intersection.cpp
modules/imgproc/test/test_intersection.cpp
+499
-0
No files found.
modules/imgproc/doc/pics/intersection.png
0 → 100644
View file @
bc3dd245
31.9 KB
modules/imgproc/test/test_intersection.cpp
0 → 100644
View file @
bc3dd245
/*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) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// @Authors
// Nghia Ho, nghiaho12@yahoo.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 materials provided with the distribution.
//
// * The name of OpenCV Foundation 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 OpenCV Foundation 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 "test_precomp.hpp"
using
namespace
cv
;
using
namespace
std
;
#define ACCURACY 0.00001
class
CV_RotatedRectangleIntersectionTest
:
public
cvtest
::
ArrayTest
{
public
:
protected
:
void
run
(
int
);
private
:
void
test1
();
void
test2
();
void
test3
();
void
test4
();
void
test5
();
void
test6
();
void
test7
();
void
test8
();
void
test9
();
};
void
CV_RotatedRectangleIntersectionTest
::
run
(
int
)
{
// See pics/intersection.png for the scenarios we are testing
// Test the following scenarios:
// 1 - no intersection
// 2 - partial intersection, rectangle translated
// 3 - partial intersection, rectangle rotated 45 degree on the corner, forms a triangle intersection
// 4 - full intersection, rectangles of same size directly on top of each other
// 5 - partial intersection, rectangle on top rotated 45 degrees
// 6 - partial intersection, rectangle on top of different size
// 7 - full intersection, rectangle fully enclosed in the other
// 8 - partial intersection, rectangle corner just touching. point contact
// 9 - partial intersetion. rectangle side by side, line contact
test1
();
test2
();
test3
();
test4
();
test5
();
test6
();
test7
();
test8
();
test9
();
}
void
CV_RotatedRectangleIntersectionTest
::
test1
()
{
// no intersection
RotatedRect
rect1
,
rect2
;
rect1
.
center
.
x
=
0
;
rect1
.
center
.
y
=
0
;
rect1
.
size
.
width
=
2
;
rect1
.
size
.
height
=
2
;
rect1
.
angle
=
12.0
f
;
rect2
.
center
.
x
=
10
;
rect2
.
center
.
y
=
10
;
rect2
.
size
.
width
=
2
;
rect2
.
size
.
height
=
2
;
rect2
.
angle
=
34.0
f
;
vector
<
Point2f
>
vertices
;
int
ret
=
rotatedRectangleIntersection
(
rect1
,
rect2
,
vertices
);
CV_Assert
(
ret
==
INTERSECT_NONE
);
CV_Assert
(
vertices
.
empty
());
}
void
CV_RotatedRectangleIntersectionTest
::
test2
()
{
// partial intersection, rectangles translated
RotatedRect
rect1
,
rect2
;
rect1
.
center
.
x
=
0
;
rect1
.
center
.
y
=
0
;
rect1
.
size
.
width
=
2
;
rect1
.
size
.
height
=
2
;
rect1
.
angle
=
0
;
rect2
.
center
.
x
=
1
;
rect2
.
center
.
y
=
1
;
rect2
.
size
.
width
=
2
;
rect2
.
size
.
height
=
2
;
rect2
.
angle
=
0
;
vector
<
Point2f
>
vertices
;
int
ret
=
rotatedRectangleIntersection
(
rect1
,
rect2
,
vertices
);
CV_Assert
(
ret
==
INTERSECT_PARTIAL
);
CV_Assert
(
vertices
.
size
()
==
4
);
vector
<
Point2f
>
possibleVertices
(
4
);
possibleVertices
[
0
]
=
Point2f
(
0.0
f
,
0.0
f
);
possibleVertices
[
1
]
=
Point2f
(
1.0
f
,
1.0
f
);
possibleVertices
[
2
]
=
Point2f
(
0.0
f
,
1.0
f
);
possibleVertices
[
3
]
=
Point2f
(
1.0
f
,
0.0
f
);
for
(
size_t
i
=
0
;
i
<
vertices
.
size
();
i
++
)
{
double
bestR
=
DBL_MAX
;
for
(
size_t
j
=
0
;
j
<
possibleVertices
.
size
();
j
++
)
{
double
dx
=
vertices
[
i
].
x
-
possibleVertices
[
j
].
x
;
double
dy
=
vertices
[
i
].
y
-
possibleVertices
[
j
].
y
;
double
r
=
sqrt
(
dx
*
dx
+
dy
*
dy
);
bestR
=
std
::
min
(
bestR
,
r
);
}
CV_Assert
(
bestR
<
ACCURACY
);
}
}
void
CV_RotatedRectangleIntersectionTest
::
test3
()
{
// partial intersection, rectangles rotated 45 degree on the corner, forms a triangle intersection
RotatedRect
rect1
,
rect2
;
rect1
.
center
.
x
=
0
;
rect1
.
center
.
y
=
0
;
rect1
.
size
.
width
=
2
;
rect1
.
size
.
height
=
2
;
rect1
.
angle
=
0
;
rect2
.
center
.
x
=
1
;
rect2
.
center
.
y
=
1
;
rect2
.
size
.
width
=
sqrt
(
2.0
f
);
rect2
.
size
.
height
=
20
;
rect2
.
angle
=
45.0
f
;
vector
<
Point2f
>
vertices
;
int
ret
=
rotatedRectangleIntersection
(
rect1
,
rect2
,
vertices
);
CV_Assert
(
ret
==
INTERSECT_PARTIAL
);
CV_Assert
(
vertices
.
size
()
==
3
);
vector
<
Point2f
>
possibleVertices
(
3
);
possibleVertices
[
0
]
=
Point2f
(
1.0
f
,
1.0
f
);
possibleVertices
[
1
]
=
Point2f
(
0.0
f
,
1.0
f
);
possibleVertices
[
2
]
=
Point2f
(
1.0
f
,
0.0
f
);
for
(
size_t
i
=
0
;
i
<
vertices
.
size
();
i
++
)
{
double
bestR
=
DBL_MAX
;
for
(
size_t
j
=
0
;
j
<
possibleVertices
.
size
();
j
++
)
{
double
dx
=
vertices
[
i
].
x
-
possibleVertices
[
j
].
x
;
double
dy
=
vertices
[
i
].
y
-
possibleVertices
[
j
].
y
;
double
r
=
sqrt
(
dx
*
dx
+
dy
*
dy
);
bestR
=
std
::
min
(
bestR
,
r
);
}
CV_Assert
(
bestR
<
ACCURACY
);
}
}
void
CV_RotatedRectangleIntersectionTest
::
test4
()
{
// full intersection, rectangles of same size directly on top of each other
RotatedRect
rect1
,
rect2
;
rect1
.
center
.
x
=
0
;
rect1
.
center
.
y
=
0
;
rect1
.
size
.
width
=
2
;
rect1
.
size
.
height
=
2
;
rect1
.
angle
=
0
;
rect2
.
center
.
x
=
0
;
rect2
.
center
.
y
=
0
;
rect2
.
size
.
width
=
2
;
rect2
.
size
.
height
=
2
;
rect2
.
angle
=
0
;
vector
<
Point2f
>
vertices
;
int
ret
=
rotatedRectangleIntersection
(
rect1
,
rect2
,
vertices
);
CV_Assert
(
ret
==
INTERSECT_FULL
);
CV_Assert
(
vertices
.
size
()
==
4
);
vector
<
Point2f
>
possibleVertices
(
4
);
possibleVertices
[
0
]
=
Point2f
(
-
1.0
f
,
1.0
f
);
possibleVertices
[
1
]
=
Point2f
(
1.0
f
,
-
1.0
f
);
possibleVertices
[
2
]
=
Point2f
(
-
1.0
f
,
-
1.0
f
);
possibleVertices
[
3
]
=
Point2f
(
1.0
f
,
1.0
f
);
for
(
size_t
i
=
0
;
i
<
vertices
.
size
();
i
++
)
{
double
bestR
=
DBL_MAX
;
for
(
size_t
j
=
0
;
j
<
possibleVertices
.
size
();
j
++
)
{
double
dx
=
vertices
[
i
].
x
-
possibleVertices
[
j
].
x
;
double
dy
=
vertices
[
i
].
y
-
possibleVertices
[
j
].
y
;
double
r
=
sqrt
(
dx
*
dx
+
dy
*
dy
);
bestR
=
std
::
min
(
bestR
,
r
);
}
CV_Assert
(
bestR
<
ACCURACY
);
}
}
void
CV_RotatedRectangleIntersectionTest
::
test5
()
{
// partial intersection, rectangle on top rotated 45 degrees
RotatedRect
rect1
,
rect2
;
rect1
.
center
.
x
=
0
;
rect1
.
center
.
y
=
0
;
rect1
.
size
.
width
=
2
;
rect1
.
size
.
height
=
2
;
rect1
.
angle
=
0
;
rect2
.
center
.
x
=
0
;
rect2
.
center
.
y
=
0
;
rect2
.
size
.
width
=
2
;
rect2
.
size
.
height
=
2
;
rect2
.
angle
=
45.0
f
;
vector
<
Point2f
>
vertices
;
int
ret
=
rotatedRectangleIntersection
(
rect1
,
rect2
,
vertices
);
CV_Assert
(
ret
==
INTERSECT_PARTIAL
);
CV_Assert
(
vertices
.
size
()
==
8
);
vector
<
Point2f
>
possibleVertices
(
8
);
possibleVertices
[
0
]
=
Point2f
(
-
1.0
f
,
-
0.414214
f
);
possibleVertices
[
1
]
=
Point2f
(
-
1.0
f
,
0.414214
f
);
possibleVertices
[
2
]
=
Point2f
(
-
0.414214
f
,
-
1.0
f
);
possibleVertices
[
3
]
=
Point2f
(
0.414214
f
,
-
1.0
f
);
possibleVertices
[
4
]
=
Point2f
(
1.0
f
,
-
0.414214
f
);
possibleVertices
[
5
]
=
Point2f
(
1.0
f
,
0.414214
f
);
possibleVertices
[
6
]
=
Point2f
(
0.414214
f
,
1.0
f
);
possibleVertices
[
7
]
=
Point2f
(
-
0.414214
f
,
1.0
f
);
for
(
size_t
i
=
0
;
i
<
vertices
.
size
();
i
++
)
{
double
bestR
=
DBL_MAX
;
for
(
size_t
j
=
0
;
j
<
possibleVertices
.
size
();
j
++
)
{
double
dx
=
vertices
[
i
].
x
-
possibleVertices
[
j
].
x
;
double
dy
=
vertices
[
i
].
y
-
possibleVertices
[
j
].
y
;
double
r
=
sqrt
(
dx
*
dx
+
dy
*
dy
);
bestR
=
std
::
min
(
bestR
,
r
);
}
CV_Assert
(
bestR
<
ACCURACY
);
}
}
void
CV_RotatedRectangleIntersectionTest
::
test6
()
{
// 6 - partial intersection, rectangle on top of different size
RotatedRect
rect1
,
rect2
;
rect1
.
center
.
x
=
0
;
rect1
.
center
.
y
=
0
;
rect1
.
size
.
width
=
2
;
rect1
.
size
.
height
=
2
;
rect1
.
angle
=
0
;
rect2
.
center
.
x
=
0
;
rect2
.
center
.
y
=
0
;
rect2
.
size
.
width
=
2
;
rect2
.
size
.
height
=
10
;
rect2
.
angle
=
0
;
vector
<
Point2f
>
vertices
;
int
ret
=
rotatedRectangleIntersection
(
rect1
,
rect2
,
vertices
);
CV_Assert
(
ret
==
INTERSECT_PARTIAL
);
CV_Assert
(
vertices
.
size
()
==
4
);
vector
<
Point2f
>
possibleVertices
(
4
);
possibleVertices
[
0
]
=
Point2f
(
1.0
f
,
1.0
f
);
possibleVertices
[
1
]
=
Point2f
(
1.0
f
,
-
1.0
f
);
possibleVertices
[
2
]
=
Point2f
(
-
1.0
f
,
-
1.0
f
);
possibleVertices
[
3
]
=
Point2f
(
-
1.0
f
,
1.0
f
);
for
(
size_t
i
=
0
;
i
<
vertices
.
size
();
i
++
)
{
double
bestR
=
DBL_MAX
;
for
(
size_t
j
=
0
;
j
<
possibleVertices
.
size
();
j
++
)
{
double
dx
=
vertices
[
i
].
x
-
possibleVertices
[
j
].
x
;
double
dy
=
vertices
[
i
].
y
-
possibleVertices
[
j
].
y
;
double
r
=
sqrt
(
dx
*
dx
+
dy
*
dy
);
bestR
=
std
::
min
(
bestR
,
r
);
}
CV_Assert
(
bestR
<
ACCURACY
);
}
}
void
CV_RotatedRectangleIntersectionTest
::
test7
()
{
// full intersection, rectangle fully enclosed in the other
RotatedRect
rect1
,
rect2
;
rect1
.
center
.
x
=
0
;
rect1
.
center
.
y
=
0
;
rect1
.
size
.
width
=
12.34
;
rect1
.
size
.
height
=
56.78
;
rect1
.
angle
=
0
;
rect2
.
center
.
x
=
0
;
rect2
.
center
.
y
=
0
;
rect2
.
size
.
width
=
2
;
rect2
.
size
.
height
=
2
;
rect2
.
angle
=
0
;
vector
<
Point2f
>
vertices
;
int
ret
=
rotatedRectangleIntersection
(
rect1
,
rect2
,
vertices
);
CV_Assert
(
ret
==
INTERSECT_FULL
);
CV_Assert
(
vertices
.
size
()
==
4
);
vector
<
Point2f
>
possibleVertices
(
4
);
possibleVertices
[
0
]
=
Point2f
(
1.0
f
,
1.0
f
);
possibleVertices
[
1
]
=
Point2f
(
1.0
f
,
-
1.0
f
);
possibleVertices
[
2
]
=
Point2f
(
-
1.0
f
,
-
1.0
f
);
possibleVertices
[
3
]
=
Point2f
(
-
1.0
f
,
1.0
f
);
for
(
size_t
i
=
0
;
i
<
vertices
.
size
();
i
++
)
{
double
bestR
=
DBL_MAX
;
for
(
size_t
j
=
0
;
j
<
possibleVertices
.
size
();
j
++
)
{
double
dx
=
vertices
[
i
].
x
-
possibleVertices
[
j
].
x
;
double
dy
=
vertices
[
i
].
y
-
possibleVertices
[
j
].
y
;
double
r
=
sqrt
(
dx
*
dx
+
dy
*
dy
);
bestR
=
std
::
min
(
bestR
,
r
);
}
CV_Assert
(
bestR
<
ACCURACY
);
}
}
void
CV_RotatedRectangleIntersectionTest
::
test8
()
{
// full intersection, rectangle fully enclosed in the other
RotatedRect
rect1
,
rect2
;
rect1
.
center
.
x
=
0
;
rect1
.
center
.
y
=
0
;
rect1
.
size
.
width
=
2
;
rect1
.
size
.
height
=
2
;
rect1
.
angle
=
0
;
rect2
.
center
.
x
=
2
;
rect2
.
center
.
y
=
2
;
rect2
.
size
.
width
=
2
;
rect2
.
size
.
height
=
2
;
rect2
.
angle
=
0
;
vector
<
Point2f
>
vertices
;
int
ret
=
rotatedRectangleIntersection
(
rect1
,
rect2
,
vertices
);
CV_Assert
(
ret
==
INTERSECT_PARTIAL
);
CV_Assert
(
vertices
.
size
()
==
1
);
double
dx
=
vertices
[
0
].
x
-
1
;
double
dy
=
vertices
[
0
].
y
-
1
;
double
r
=
sqrt
(
dx
*
dx
+
dy
*
dy
);
CV_Assert
(
r
<
ACCURACY
);
}
void
CV_RotatedRectangleIntersectionTest
::
test9
()
{
// full intersection, rectangle fully enclosed in the other
RotatedRect
rect1
,
rect2
;
rect1
.
center
.
x
=
0
;
rect1
.
center
.
y
=
0
;
rect1
.
size
.
width
=
2
;
rect1
.
size
.
height
=
2
;
rect1
.
angle
=
0
;
rect2
.
center
.
x
=
2
;
rect2
.
center
.
y
=
0
;
rect2
.
size
.
width
=
2
;
rect2
.
size
.
height
=
123.45
;
rect2
.
angle
=
0
;
vector
<
Point2f
>
vertices
;
int
ret
=
rotatedRectangleIntersection
(
rect1
,
rect2
,
vertices
);
CV_Assert
(
ret
==
INTERSECT_PARTIAL
);
CV_Assert
(
vertices
.
size
()
==
2
);
vector
<
Point2f
>
possibleVertices
(
2
);
possibleVertices
[
0
]
=
Point2f
(
1.0
f
,
1.0
f
);
possibleVertices
[
1
]
=
Point2f
(
1.0
f
,
-
1.0
f
);
for
(
size_t
i
=
0
;
i
<
vertices
.
size
();
i
++
)
{
double
bestR
=
DBL_MAX
;
for
(
size_t
j
=
0
;
j
<
possibleVertices
.
size
();
j
++
)
{
double
dx
=
vertices
[
i
].
x
-
possibleVertices
[
j
].
x
;
double
dy
=
vertices
[
i
].
y
-
possibleVertices
[
j
].
y
;
double
r
=
sqrt
(
dx
*
dx
+
dy
*
dy
);
bestR
=
std
::
min
(
bestR
,
r
);
}
CV_Assert
(
bestR
<
ACCURACY
);
}
}
TEST
(
Imgproc_RotatedRectangleIntersection
,
accuracy
)
{
CV_RotatedRectangleIntersectionTest
test
;
test
.
safe_run
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment