回答編集履歴
1
コード追加
test
CHANGED
@@ -3,3 +3,103 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
マスクを用意し,`cv::Mat::copyTo`で使う.
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
原理確認のサンプルコードを示す.
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```C++
|
18
|
+
|
19
|
+
class TestClass
|
20
|
+
|
21
|
+
{
|
22
|
+
|
23
|
+
public:
|
24
|
+
|
25
|
+
TestClass( int ImgW, int ImgH )
|
26
|
+
|
27
|
+
{
|
28
|
+
|
29
|
+
m_MasterImg = cv::Mat::zeros( ImgH, ImgW, CV_8UC3 );
|
30
|
+
|
31
|
+
m_TempCanvas = cv::Mat::zeros( m_MasterImg.size(), CV_8UC3 );
|
32
|
+
|
33
|
+
m_Mask = cv::Mat( m_MasterImg.size(), CV_8UC1 );
|
34
|
+
|
35
|
+
m_Mask = 255;
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
public:
|
42
|
+
|
43
|
+
const cv::Mat &CurrImg() const { return m_MasterImg; }
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
void DrawCircle( cv::Point Center, int Radius, cv::Scalar Color, int Thickness )
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
cv::circle( m_TempCanvas, Center, Radius, Color, Thickness );
|
52
|
+
|
53
|
+
m_TempCanvas.copyTo( m_MasterImg, m_Mask );
|
54
|
+
|
55
|
+
cv::circle( m_Mask, Center, Radius, cv::Scalar(0), Thickness );
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
private:
|
62
|
+
|
63
|
+
cv::Mat m_MasterImg;
|
64
|
+
|
65
|
+
cv::Mat m_Mask;
|
66
|
+
|
67
|
+
cv::Mat m_TempCanvas;
|
68
|
+
|
69
|
+
};
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
int main()
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
TestClass Test( 320, 240 );
|
80
|
+
|
81
|
+
//赤,緑,青 の順で描画
|
82
|
+
|
83
|
+
Test.DrawCircle( cv::Point(100,100), 60, cv::Scalar(0,0,255), -1 );
|
84
|
+
|
85
|
+
Test.DrawCircle( cv::Point(150,120), 50, cv::Scalar(0,255,0), 5 );
|
86
|
+
|
87
|
+
Test.DrawCircle( cv::Point(230,150), 100, cv::Scalar(255,32,32), 8 );
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
cv::imshow( "Result", Test.CurrImg() );
|
92
|
+
|
93
|
+
if( cv::waitKey() == 's' ){ cv::imwrite( "Result.png", Test.CurrImg() ); }
|
94
|
+
|
95
|
+
return 0;
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
結果:
|
104
|
+
|
105
|
+
![イメージ説明](f211005c75e938cf40fbfd8683d655dd.png)
|