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

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/samples/cpp/drawing.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
#include "opencv2/core.hpp"
 
2
#include "opencv2/imgproc.hpp"
 
3
#include "opencv2/highgui.hpp"
 
4
#include <stdio.h>
 
5
using namespace cv;
 
6
 
 
7
static void help()
 
8
{
 
9
    printf("\nThis program demonstrates OpenCV drawing and text output functions.\n"
 
10
    "Usage:\n"
 
11
    "   ./drawing\n");
 
12
}
 
13
static Scalar randomColor(RNG& rng)
 
14
{
 
15
    int icolor = (unsigned)rng;
 
16
    return Scalar(icolor&255, (icolor>>8)&255, (icolor>>16)&255);
 
17
}
 
18
 
 
19
int main(int argc, char** argv)
 
20
{
 
21
    cv::CommandLineParser parser(argc, argv, "{help h||}");
 
22
    if (parser.has("help"))
 
23
    {
 
24
        help();
 
25
        return 0;
 
26
    }
 
27
    char wndname[] = "Drawing Demo";
 
28
    const int NUMBER = 100;
 
29
    const int DELAY = 5;
 
30
    int lineType = LINE_AA; // change it to LINE_8 to see non-antialiased graphics
 
31
    int i, width = 1000, height = 700;
 
32
    int x1 = -width/2, x2 = width*3/2, y1 = -height/2, y2 = height*3/2;
 
33
    RNG rng(0xFFFFFFFF);
 
34
 
 
35
    Mat image = Mat::zeros(height, width, CV_8UC3);
 
36
    imshow(wndname, image);
 
37
    waitKey(DELAY);
 
38
 
 
39
    for (i = 0; i < NUMBER; i++)
 
40
    {
 
41
        Point pt1, pt2;
 
42
        pt1.x = rng.uniform(x1, x2);
 
43
        pt1.y = rng.uniform(y1, y2);
 
44
        pt2.x = rng.uniform(x1, x2);
 
45
        pt2.y = rng.uniform(y1, y2);
 
46
 
 
47
        line( image, pt1, pt2, randomColor(rng), rng.uniform(1,10), lineType );
 
48
 
 
49
        imshow(wndname, image);
 
50
        if(waitKey(DELAY) >= 0)
 
51
            return 0;
 
52
    }
 
53
 
 
54
    for (i = 0; i < NUMBER; i++)
 
55
    {
 
56
        Point pt1, pt2;
 
57
        pt1.x = rng.uniform(x1, x2);
 
58
        pt1.y = rng.uniform(y1, y2);
 
59
        pt2.x = rng.uniform(x1, x2);
 
60
        pt2.y = rng.uniform(y1, y2);
 
61
        int thickness = rng.uniform(-3, 10);
 
62
 
 
63
        rectangle( image, pt1, pt2, randomColor(rng), MAX(thickness, -1), lineType );
 
64
 
 
65
        imshow(wndname, image);
 
66
        if(waitKey(DELAY) >= 0)
 
67
            return 0;
 
68
    }
 
69
 
 
70
    for (i = 0; i < NUMBER; i++)
 
71
    {
 
72
        Point center;
 
73
        center.x = rng.uniform(x1, x2);
 
74
        center.y = rng.uniform(y1, y2);
 
75
        Size axes;
 
76
        axes.width = rng.uniform(0, 200);
 
77
        axes.height = rng.uniform(0, 200);
 
78
        double angle = rng.uniform(0, 180);
 
79
 
 
80
        ellipse( image, center, axes, angle, angle - 100, angle + 200,
 
81
                 randomColor(rng), rng.uniform(-1,9), lineType );
 
82
 
 
83
        imshow(wndname, image);
 
84
        if(waitKey(DELAY) >= 0)
 
85
            return 0;
 
86
    }
 
87
 
 
88
    for (i = 0; i< NUMBER; i++)
 
89
    {
 
90
        Point pt[2][3];
 
91
        pt[0][0].x = rng.uniform(x1, x2);
 
92
        pt[0][0].y = rng.uniform(y1, y2);
 
93
        pt[0][1].x = rng.uniform(x1, x2);
 
94
        pt[0][1].y = rng.uniform(y1, y2);
 
95
        pt[0][2].x = rng.uniform(x1, x2);
 
96
        pt[0][2].y = rng.uniform(y1, y2);
 
97
        pt[1][0].x = rng.uniform(x1, x2);
 
98
        pt[1][0].y = rng.uniform(y1, y2);
 
99
        pt[1][1].x = rng.uniform(x1, x2);
 
100
        pt[1][1].y = rng.uniform(y1, y2);
 
101
        pt[1][2].x = rng.uniform(x1, x2);
 
102
        pt[1][2].y = rng.uniform(y1, y2);
 
103
        const Point* ppt[2] = {pt[0], pt[1]};
 
104
        int npt[] = {3, 3};
 
105
 
 
106
        polylines(image, ppt, npt, 2, true, randomColor(rng), rng.uniform(1,10), lineType);
 
107
 
 
108
        imshow(wndname, image);
 
109
        if(waitKey(DELAY) >= 0)
 
110
            return 0;
 
111
    }
 
112
 
 
113
    for (i = 0; i< NUMBER; i++)
 
114
    {
 
115
        Point pt[2][3];
 
116
        pt[0][0].x = rng.uniform(x1, x2);
 
117
        pt[0][0].y = rng.uniform(y1, y2);
 
118
        pt[0][1].x = rng.uniform(x1, x2);
 
119
        pt[0][1].y = rng.uniform(y1, y2);
 
120
        pt[0][2].x = rng.uniform(x1, x2);
 
121
        pt[0][2].y = rng.uniform(y1, y2);
 
122
        pt[1][0].x = rng.uniform(x1, x2);
 
123
        pt[1][0].y = rng.uniform(y1, y2);
 
124
        pt[1][1].x = rng.uniform(x1, x2);
 
125
        pt[1][1].y = rng.uniform(y1, y2);
 
126
        pt[1][2].x = rng.uniform(x1, x2);
 
127
        pt[1][2].y = rng.uniform(y1, y2);
 
128
        const Point* ppt[2] = {pt[0], pt[1]};
 
129
        int npt[] = {3, 3};
 
130
 
 
131
        fillPoly(image, ppt, npt, 2, randomColor(rng), lineType);
 
132
 
 
133
        imshow(wndname, image);
 
134
        if(waitKey(DELAY) >= 0)
 
135
            return 0;
 
136
    }
 
137
 
 
138
    for (i = 0; i < NUMBER; i++)
 
139
    {
 
140
        Point center;
 
141
        center.x = rng.uniform(x1, x2);
 
142
        center.y = rng.uniform(y1, y2);
 
143
 
 
144
        circle(image, center, rng.uniform(0, 300), randomColor(rng),
 
145
               rng.uniform(-1, 9), lineType);
 
146
 
 
147
        imshow(wndname, image);
 
148
        if(waitKey(DELAY) >= 0)
 
149
            return 0;
 
150
    }
 
151
 
 
152
    for (i = 1; i < NUMBER; i++)
 
153
    {
 
154
        Point org;
 
155
        org.x = rng.uniform(x1, x2);
 
156
        org.y = rng.uniform(y1, y2);
 
157
 
 
158
        putText(image, "Testing text rendering", org, rng.uniform(0,8),
 
159
                rng.uniform(0,100)*0.05+0.1, randomColor(rng), rng.uniform(1, 10), lineType);
 
160
 
 
161
        imshow(wndname, image);
 
162
        if(waitKey(DELAY) >= 0)
 
163
            return 0;
 
164
    }
 
165
 
 
166
    Size textsize = getTextSize("OpenCV forever!", FONT_HERSHEY_COMPLEX, 3, 5, 0);
 
167
    Point org((width - textsize.width)/2, (height - textsize.height)/2);
 
168
 
 
169
    Mat image2;
 
170
    for( i = 0; i < 255; i += 2 )
 
171
    {
 
172
        image2 = image - Scalar::all(i);
 
173
        putText(image2, "OpenCV forever!", org, FONT_HERSHEY_COMPLEX, 3,
 
174
                Scalar(i, i, 255), 5, lineType);
 
175
 
 
176
        imshow(wndname, image2);
 
177
        if(waitKey(DELAY) >= 0)
 
178
            return 0;
 
179
    }
 
180
 
 
181
    waitKey();
 
182
    return 0;
 
183
}
 
184
 
 
185
#ifdef _EiC
 
186
main(1,"drawing.c");
 
187
#endif