1
+ <?php
2
+ namespace CV ;
3
+
4
+ use CV \{
5
+ Mat , Point , Size , Scalar
6
+ };
7
+ use const CV \{
8
+ CV_8UC3 , LINE_8 , FILLED
9
+ };
10
+ use function CV \{
11
+ ellipse , circle , fillPoly , rectangleByPoint , line , imshow , moveWindow , waitKey
12
+ };
13
+
14
+ define ('w ' , 400 );
15
+
16
+ $ atom_window = "Drawing 1: Atom " ;
17
+ $ rook_window = "Drawing 2: Rook " ;
18
+ $ atom_image = Mat::zeros (w, w, CV_8UC3 );
19
+ $ rook_image = Mat::zeros (w, w, CV_8UC3 );
20
+ MyEllipse ($ atom_image , 90 );
21
+ MyEllipse ($ atom_image , 0 );
22
+ MyEllipse ($ atom_image , 45 );
23
+ MyEllipse ($ atom_image , -45 );
24
+ MyFilledCircle ($ atom_image , new Point (w / 2 , w / 2 ));
25
+ MyPolygon ($ rook_image );
26
+ rectangleByPoint (
27
+ $ rook_image ,
28
+ new Point (0 , 7 * w / 8 ),
29
+ new Point (w, w),
30
+ new Scalar (0 , 255 , 255 ),
31
+ FILLED ,
32
+ LINE_8 );
33
+ MyLine ($ rook_image , new Point (0 , 15 * w / 16 ), new Point (w, 15 * w / 16 ));
34
+ MyLine ($ rook_image , new Point (w / 4 , 7 * w / 8 ), new Point (w / 4 , w));
35
+ MyLine ($ rook_image , new Point (w / 2 , 7 * w / 8 ), new Point (w / 2 , w));
36
+ MyLine ($ rook_image , new Point (3 * w / 4 , 7 * w / 8 ), new Point (3 * w / 4 , w));
37
+ imshow ($ atom_window , $ atom_image );
38
+ moveWindow ($ atom_window , 0 , 200 );
39
+ imshow ($ rook_window , $ rook_image );
40
+ moveWindow ($ rook_window , w, 200 );
41
+ waitKey (0 );
42
+ return (0 );
43
+
44
+ function MyEllipse ($ img , $ angle )
45
+ {
46
+ $ thickness = 2 ;
47
+ $ lineType = 8 ;
48
+ ellipse (
49
+ $ img ,
50
+ new Point (w / 2 , w / 2 ),
51
+ new Size (w / 4 , w / 16 ),
52
+ $ angle ,
53
+ 0 ,
54
+ 360 ,
55
+ new Scalar (255 , 0 , 0 ),
56
+ $ thickness ,
57
+ $ lineType );
58
+ }
59
+
60
+ function MyFilledCircle ($ img , $ center )
61
+ {
62
+ circle (
63
+ $ img ,
64
+ $ center ,
65
+ w / 32 ,
66
+ new Scalar (0 , 0 , 255 ),
67
+ FILLED ,
68
+ LINE_8 );
69
+ }
70
+
71
+ function MyPolygon ($ img )
72
+ {
73
+ $ lineType = LINE_8 ;
74
+ $ rook_points [0 ] = new Point (w / 4 , 7 * w / 8 );
75
+ $ rook_points [1 ] = new Point (3 * w / 4 , 7 * w / 8 );
76
+ $ rook_points [2 ] = new Point (3 * w / 4 , 13 * w / 16 );
77
+ $ rook_points [3 ] = new Point (11 * w / 16 , 13 * w / 16 );
78
+ $ rook_points [4 ] = new Point (19 * w / 32 , 3 * w / 8 );
79
+ $ rook_points [5 ] = new Point (3 * w / 4 , 3 * w / 8 );
80
+ $ rook_points [6 ] = new Point (3 * w / 4 , w / 8 );
81
+ $ rook_points [7 ] = new Point (26 * w / 40 , w / 8 );
82
+ $ rook_points [8 ] = new Point (26 * w / 40 , w / 4 );
83
+ $ rook_points [9 ] = new Point (22 * w / 40 , w / 4 );
84
+ $ rook_points [10 ] = new Point (22 * w / 40 , w / 8 );
85
+ $ rook_points [11 ] = new Point (18 * w / 40 , w / 8 );
86
+ $ rook_points [12 ] = new Point (18 * w / 40 , w / 4 );
87
+ $ rook_points [13 ] = new Point (14 * w / 40 , w / 4 );
88
+ $ rook_points [14 ] = new Point (14 * w / 40 , w / 8 );
89
+ $ rook_points [15 ] = new Point (w / 4 , w / 8 );
90
+ $ rook_points [16 ] = new Point (w / 4 , 3 * w / 8 );
91
+ $ rook_points [17 ] = new Point (13 * w / 32 , 3 * w / 8 );
92
+ $ rook_points [18 ] = new Point (5 * w / 16 , 13 * w / 16 );
93
+ $ rook_points [19 ] = new Point (w / 4 , 13 * w / 16 );
94
+ fillPoly ($ img ,
95
+ $ rook_points ,
96
+ new Scalar (255 , 255 , 255 ),
97
+ $ lineType );
98
+ }
99
+
100
+ function MyLine ($ img , $ start , $ end )
101
+ {
102
+ $ thickness = 2 ;
103
+ $ lineType = LINE_8 ;
104
+ line (
105
+ $ img ,
106
+ $ start ,
107
+ $ end ,
108
+ new Scalar (0 , 0 , 0 ),
109
+ $ thickness ,
110
+ $ lineType );
111
+ }
0 commit comments