質問編集履歴
1
キャンセル
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,198 +52,6 @@
|
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
-
/// 指定したフレーム番号の画像をimageに抜き出す
|
56
|
-
|
57
|
-
/// imageをグレースケールに変換
|
58
|
-
|
59
|
-
int GetGrayImage(cv::VideoCapture& video, int frameNo, cv::Mat& image)
|
60
|
-
|
61
|
-
{
|
62
|
-
|
63
|
-
const int x = 145, y = 45; // 抜き出す領域の中心点
|
64
|
-
|
65
|
-
const int w = 370, h = 370; // 抜き出す領域の幅(w*hが抜き出す幅となる)
|
66
|
-
|
67
|
-
CvRect rect = {x, y, w, h};
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
cv::Mat frame;
|
72
|
-
|
73
|
-
video.set( CV_CAP_PROP_POS_FRAMES, frameNo);
|
74
|
-
|
75
|
-
video >> frame;
|
76
|
-
|
77
|
-
ASSERT( !frame.empty(), "img2は空です");
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
cv::Mat cut(frame, rect);
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
cv::cvtColor(cut, image, CV_BGR2GRAY);
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
return 0;
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
//カラー画像切り取り用
|
96
|
-
|
97
|
-
int GetImage(cv::VideoCapture& video2, int n, cv::Mat& img)
|
98
|
-
|
99
|
-
{
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
CvRect rect = {145, 45, 370, 370};
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
cv::Mat frame;
|
108
|
-
|
109
|
-
video2.set( CV_CAP_PROP_POS_FRAMES, n);
|
110
|
-
|
111
|
-
video2 >> frame;
|
112
|
-
|
113
|
-
ASSERT( !frame.empty(), "img2は空です");
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
img = cv::Mat(frame,rect);
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
return 0;
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
///誤差を計算する関数
|
130
|
-
|
131
|
-
int gosa(cv::Point point1,cv::Point point2)
|
132
|
-
|
133
|
-
{
|
134
|
-
|
135
|
-
int t;
|
136
|
-
|
137
|
-
t = (point1.x-point2.x)*(point1.x-point2.x)+(point1.y-point2.y)*(point1.y-point2.y);
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
return t;
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
int main(void)
|
152
|
-
|
153
|
-
{
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
// 動画の読み込み
|
160
|
-
|
161
|
-
cv::VideoCapture video("data/mk/005.avi");
|
162
|
-
|
163
|
-
// 動画を書き込み用ファイル
|
164
|
-
|
165
|
-
cv::VideoWriter writeVideo("data/mk/1_4c_video.avi",-1,30.0,cv::Size(370,370));
|
166
|
-
|
167
|
-
// 動画のフレーム数を得る
|
168
|
-
|
169
|
-
const int FrameNum = (int)video.get(CV_CAP_PROP_FRAME_COUNT);
|
170
|
-
|
171
|
-
printf("動画フレーム数 : %d\n", FrameNum);
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
cv::Mat img1;
|
176
|
-
|
177
|
-
cv::Mat img2;
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
int a = 0,b = (FrameNum-1);
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
GetGrayImage(video, a, img1); //a番目のフレーム番号のデータをimg1に入れる
|
188
|
-
|
189
|
-
GetImage(video, a, img2);
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
//着目点を設定する
|
194
|
-
|
195
|
-
cv::Point trackingPoint[100];
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
//画像上で着目点を設定
|
200
|
-
|
201
|
-
//for(int i = 0;i < 2;i++){
|
202
|
-
|
203
|
-
SetViewPoint(img2, trackingPoint[0]);
|
204
|
-
|
205
|
-
//}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
//SetViewPoint(img2, trackingPoint[1]); // 2つめのトラッキングポイント
|
210
|
-
|
211
|
-
//SetViewPoint(img2, trackingPoint[2]); //3つめのトラッキングポイント
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
//////////着目点の座標設定//////////
|
218
|
-
|
219
|
-
////////////////////////////////////
|
220
|
-
|
221
|
-
#if 0
|
222
|
-
|
223
|
-
int t,r;
|
224
|
-
|
225
|
-
printf("着目点のx座標=");
|
226
|
-
|
227
|
-
scanf("%d",&t);
|
228
|
-
|
229
|
-
printf("着目点のy座標=");
|
230
|
-
|
231
|
-
scanf("%d",&r);
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
//trackingPoint[0].x=147;
|
236
|
-
|
237
|
-
//trackingPoint[0].y=127;
|
238
|
-
|
239
|
-
////////////////////////////////////
|
240
|
-
|
241
|
-
////////////////////////////////////
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
以下省略。
|
246
|
-
|
247
55
|
|
248
56
|
|
249
57
|
|