質問編集履歴
2
試したこと追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,33 +8,29 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
###
|
11
|
+
###ソースコード
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
|
18
|
-
|
13
|
+
|
14
|
+
|
19
|
-
|
15
|
+
include <vector>
|
20
|
-
|
16
|
+
|
21
|
-
|
17
|
+
include <stdio.h>
|
22
|
-
|
18
|
+
|
23
|
-
|
19
|
+
include <iostream>
|
24
|
-
|
20
|
+
|
25
|
-
|
21
|
+
include <string.h>
|
26
|
-
|
22
|
+
|
27
|
-
|
23
|
+
include <opencv2/core/core.hpp>
|
28
|
-
|
24
|
+
|
29
|
-
|
25
|
+
include <opencv2/imgproc/imgproc.hpp>
|
30
|
-
|
26
|
+
|
31
|
-
|
27
|
+
include <opencv2/highgui/highgui.hpp>
|
32
|
-
|
28
|
+
|
33
|
-
|
29
|
+
include "opencv2/opencv.hpp"
|
34
|
-
|
30
|
+
|
35
|
-
|
31
|
+
include <opencv2/opencv.hpp>
|
36
|
-
|
32
|
+
|
37
|
-
|
33
|
+
pragma comment(lib, "opencv_world320d.lib")
|
38
34
|
|
39
35
|
|
40
36
|
|
@@ -92,7 +88,7 @@
|
|
92
88
|
|
93
89
|
cv::waitKey(1);
|
94
90
|
|
95
|
-
cv::imwrite("img.png", frame);
|
91
|
+
cv::imwrite("/Users/i-am-kaito/Downloads/img.png", frame);
|
96
92
|
|
97
93
|
}
|
98
94
|
|
@@ -104,11 +100,11 @@
|
|
104
100
|
|
105
101
|
//テンプレート画像とその名称
|
106
102
|
|
107
|
-
vector<Mat> img{ imread("im
|
103
|
+
vector<Mat> img{ imread("/Users/i-am-kaito/Downloads/IMG_4483.png"),
|
108
|
-
|
104
|
+
|
109
|
-
imread("im
|
105
|
+
imread("/Users/i-am-kaito/Downloads/IMG_4484.png"),
|
110
|
-
|
106
|
+
|
111
|
-
imread("im
|
107
|
+
imread("/Users/i-am-kaito/Downloads/IMG_4448.png")
|
112
108
|
|
113
109
|
};
|
114
110
|
|
@@ -118,7 +114,7 @@
|
|
118
114
|
|
119
115
|
//色情報
|
120
116
|
|
121
|
-
Mat src_image = imread("img.png", 1); // カラーで読み込む
|
117
|
+
Mat src_image = imread("/Users/i-am-kaito/Downloads/img.png", 1); // カラーで読み込む
|
122
118
|
|
123
119
|
|
124
120
|
|
@@ -128,13 +124,11 @@
|
|
128
124
|
|
129
125
|
|
130
126
|
|
131
|
-
// 画素値はBGRの順に格納
|
127
|
+
// 画素値はBGRの順に格納されている
|
132
128
|
|
133
129
|
cout << (int)pix[0] << "," << (int)pix[1] << "," << (int)pix[2] << endl;
|
134
130
|
|
135
|
-
|
136
|
-
|
137
|
-
|
131
|
+
|
138
132
|
|
139
133
|
while (1) {
|
140
134
|
|
@@ -148,7 +142,7 @@
|
|
148
142
|
|
149
143
|
//テンプレートマッチング
|
150
144
|
|
151
|
-
matchTemplate(src, img[num], mapCC, cv::TM_CCOEFF_NORMED);
|
145
|
+
matchTemplate(src, img[num], mapCC, cv::TM_CCOEFF_NORMED);//ZNCC法
|
152
146
|
|
153
147
|
double maxCC;
|
154
148
|
|
@@ -170,18 +164,32 @@
|
|
170
164
|
|
171
165
|
cv::FONT_HERSHEY_SIMPLEX, 1, 0, 2);
|
172
166
|
|
167
|
+
|
168
|
+
|
173
|
-
|
169
|
+
const int key = cv::waitKey(1);
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
if(key == 'k'){
|
174
|
+
|
175
|
+
cv::Rect roi(cv::Point(img[num].cols, img[num].rows), cv::Size(600,600));
|
176
|
+
|
177
|
+
cv::Mat subImg = src(roi);
|
178
|
+
|
179
|
+
imshow("kiri", src(roi));
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
else if(key == 'q'){
|
184
|
+
|
185
|
+
break;
|
186
|
+
|
187
|
+
}
|
174
188
|
|
175
189
|
}
|
176
190
|
|
177
|
-
imshow("sougosoukan" + name[num], mapCC);
|
178
|
-
|
179
191
|
|
180
192
|
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
193
|
imshow("Temp", src);
|
186
194
|
|
187
195
|
if (waitKey(20) == 27) break;
|
@@ -190,17 +198,19 @@
|
|
190
198
|
|
191
199
|
}
|
192
200
|
|
193
|
-
|
201
|
+
}
|
194
202
|
|
195
203
|
cv::destroyAllWindows();
|
196
204
|
|
197
205
|
return 0;
|
198
206
|
|
207
|
+
|
208
|
+
|
199
|
-
|
209
|
+
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
204
214
|
|
205
215
|
|
206
216
|
|
@@ -208,7 +218,11 @@
|
|
208
218
|
|
209
219
|
|
210
220
|
|
211
|
-
rectangleでマッチング箇所を四角形で囲っています。
|
221
|
+
rectangleでマッチング箇所を四角形で囲っています。
|
222
|
+
|
223
|
+
cv::Rect roi(cv::Point(x, y), cv::Size(600,600));
|
224
|
+
|
225
|
+
マッチング箇所だけを切り取る際はx,yに何を入れたらいいのでしょうか
|
212
226
|
|
213
227
|
|
214
228
|
|
1
ソースコードの記載不備
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,9 +14,191 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
```
|
17
|
+
```C++
|
18
|
+
|
18
|
-
|
19
|
+
#include <vector>
|
20
|
+
|
21
|
+
#include <stdio.h>
|
22
|
+
|
23
|
+
#include <iostream>
|
24
|
+
|
25
|
+
#include <string.h>
|
26
|
+
|
27
|
+
#include <opencv2/core/core.hpp>
|
28
|
+
|
29
|
+
#include <opencv2/imgproc/imgproc.hpp>
|
30
|
+
|
31
|
+
#include <opencv2/highgui/highgui.hpp>
|
32
|
+
|
33
|
+
#include "opencv2/opencv.hpp"
|
34
|
+
|
35
|
+
#include <opencv2/opencv.hpp>
|
36
|
+
|
37
|
+
#pragma comment(lib, "opencv_world320d.lib")
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
using namespace std;
|
42
|
+
|
43
|
+
using namespace cv;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
int main(int argh, char* argv[])
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
cv::VideoCapture cap(0);
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
if(!cap.isOpened())
|
56
|
+
|
57
|
+
{
|
58
|
+
|
59
|
+
cout << "ERROR: cannot open cam device." << endl;
|
60
|
+
|
61
|
+
return -1;
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
cv::Mat frame;
|
68
|
+
|
69
|
+
while(cap.read(frame))
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
cv::imshow("win", frame);
|
76
|
+
|
77
|
+
const int key = cv::waitKey(1);
|
78
|
+
|
79
|
+
if(key == 'q')
|
80
|
+
|
81
|
+
{
|
82
|
+
|
19
|
-
|
83
|
+
break;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
else if(key == 's')
|
90
|
+
|
91
|
+
{
|
92
|
+
|
93
|
+
cv::waitKey(1);
|
94
|
+
|
95
|
+
cv::imwrite("img.png", frame);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
Mat src;
|
104
|
+
|
105
|
+
//テンプレート画像とその名称
|
106
|
+
|
107
|
+
vector<Mat> img{ imread("img1.png"),
|
108
|
+
|
109
|
+
imread("img2.png"),
|
110
|
+
|
111
|
+
imread("img3.png")
|
112
|
+
|
113
|
+
};
|
114
|
+
|
115
|
+
vector<string> name{ "680","1000","150"};
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
//色情報
|
120
|
+
|
121
|
+
Mat src_image = imread("img.png", 1); // カラーで読み込む
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
// 画像の座標(0,0)の画素値を取得する
|
126
|
+
|
127
|
+
Vec3b pix = src_image.at<Vec3b>(Point(0, 0));
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
// 画素値はBGRの順に格納
|
132
|
+
|
133
|
+
cout << (int)pix[0] << "," << (int)pix[1] << "," << (int)pix[2] << endl;
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
while (1) {
|
140
|
+
|
141
|
+
cap >> src; if (src.empty()) break;
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
for (int num = 0; num < 3; num++){
|
146
|
+
|
147
|
+
Mat mapCC;
|
148
|
+
|
149
|
+
//テンプレートマッチング
|
150
|
+
|
151
|
+
matchTemplate(src, img[num], mapCC, cv::TM_CCOEFF_NORMED);
|
152
|
+
|
153
|
+
double maxCC;
|
154
|
+
|
155
|
+
Point maxLoc;
|
156
|
+
|
157
|
+
//相互相関係数の最大値探索
|
158
|
+
|
159
|
+
minMaxLoc(mapCC, NULL, &maxCC, NULL, &maxLoc);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
if (maxCC > 0.4){ //類似度が0.4以上なら枠描写
|
164
|
+
|
165
|
+
rectangle(src, maxLoc,
|
166
|
+
|
167
|
+
maxLoc + Point(img[num].cols, img[num].rows), 0, 4);
|
168
|
+
|
169
|
+
putText(src, name[num], maxLoc + Point(10, 30),
|
170
|
+
|
171
|
+
cv::FONT_HERSHEY_SIMPLEX, 1, 0, 2);
|
172
|
+
|
173
|
+
operator()( const cv::Rect );
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
imshow("sougosoukan" + name[num], mapCC);
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
imshow("Temp", src);
|
186
|
+
|
187
|
+
if (waitKey(20) == 27) break;
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
cv::destroyAllWindows();
|
196
|
+
|
197
|
+
return 0;
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
20
202
|
|
21
203
|
```
|
22
204
|
|