File: perf_contours.cpp

package info (click to toggle)
opencv 4.5.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268,248 kB
  • sloc: cpp: 969,170; xml: 682,525; python: 36,732; lisp: 30,170; java: 25,155; ansic: 7,927; javascript: 5,643; objc: 2,041; sh: 935; cs: 601; perl: 494; makefile: 145
file content (109 lines) | stat: -rw-r--r-- 3,397 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"

namespace opencv_test { namespace {

CV_ENUM(RetrMode, RETR_EXTERNAL, RETR_LIST, RETR_CCOMP, RETR_TREE)
CV_ENUM(ApproxMode, CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS)

typedef TestBaseWithParam< tuple<Size, RetrMode, ApproxMode, int> > TestFindContours;

PERF_TEST_P(TestFindContours, findContours,
            Combine(
               Values( szVGA, sz1080p ), // image size
               RetrMode::all(), // retrieval mode
               ApproxMode::all(), // approximation method
               Values( 32, 128 ) // blob count
            )
           )
{
    Size img_size = get<0>(GetParam());
    int retr_mode = get<1>(GetParam());
    int approx_method = get<2>(GetParam());
    int blob_count = get<3>(GetParam());

    RNG rng;
    Mat img = Mat::zeros(img_size, CV_8UC1);
    for(int i = 0; i < blob_count; i++ )
    {
        Point center;
        center.x = (unsigned)rng % (img.cols-2);
        center.y = (unsigned)rng % (img.rows-2);
        Size  axes;
        axes.width = ((unsigned)rng % 49 + 2)/2;
        axes.height = ((unsigned)rng % 49 + 2)/2;
        double angle = (unsigned)rng % 180;
        int brightness = (unsigned)rng % 2;

        // keep the border clear
        ellipse( img(Rect(1,1,img.cols-2,img.rows-2)), Point(center), Size(axes), angle, 0., 360., Scalar(brightness), -1);
    }
    vector< vector<Point> > contours;

    TEST_CYCLE() findContours( img, contours, retr_mode, approx_method );

    SANITY_CHECK_NOTHING();
}

typedef TestBaseWithParam< tuple<Size, ApproxMode, int> > TestFindContoursFF;

PERF_TEST_P(TestFindContoursFF, findContours,
    Combine(
        Values(szVGA, sz1080p), // image size
        ApproxMode::all(), // approximation method
        Values(32, 128) // blob count
    )
)
{
    Size img_size = get<0>(GetParam());
    int approx_method = get<1>(GetParam());
    int blob_count = get<2>(GetParam());

    RNG rng;
    Mat img = Mat::zeros(img_size, CV_32SC1);
    for (int i = 0; i < blob_count; i++)
    {
        Point center;
        center.x = (unsigned)rng % (img.cols - 2);
        center.y = (unsigned)rng % (img.rows - 2);
        Size  axes;
        axes.width = ((unsigned)rng % 49 + 2) / 2;
        axes.height = ((unsigned)rng % 49 + 2) / 2;
        double angle = (unsigned)rng % 180;
        int brightness = (unsigned)rng % 2;

        // keep the border clear
        ellipse(img(Rect(1, 1, img.cols - 2, img.rows - 2)), Point(center), Size(axes), angle, 0., 360., Scalar(brightness), -1);
    }
    vector< vector<Point> > contours;

    TEST_CYCLE() findContours(img, contours, RETR_FLOODFILL, approx_method);

    SANITY_CHECK_NOTHING();
}

typedef TestBaseWithParam< tuple<MatDepth, int> > TestBoundingRect;

PERF_TEST_P(TestBoundingRect, BoundingRect,
    Combine(
        testing::Values(CV_32S, CV_32F), // points type
        Values(400, 511, 1000, 10000, 100000) // points count
    )
)

{
    int ptType = get<0>(GetParam());
    int n = get<1>(GetParam());

    Mat pts(n, 2, ptType);
    declare.in(pts, WARMUP_RNG);

    cv::Rect rect;
    TEST_CYCLE() rect = boundingRect(pts);

    SANITY_CHECK_NOTHING();
}

} } // namespace