質問編集履歴
18
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,6 +64,14 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
+
|
68
|
+
|
69
|
+
コードをサンプルへ戻しました。
|
70
|
+
|
71
|
+
stereo_calib.xmlファイルの中は
|
72
|
+
|
73
|
+
|
74
|
+
|
67
75
|
<?xml version="1.0"?>
|
68
76
|
|
69
77
|
<opencv_storage>
|
@@ -128,7 +136,7 @@
|
|
128
136
|
|
129
137
|
|
130
138
|
|
131
|
-
|
139
|
+
です。
|
132
140
|
|
133
141
|
|
134
142
|
|
@@ -192,18 +200,22 @@
|
|
192
200
|
|
193
201
|
|
194
202
|
|
203
|
+
画像ファイルはOpenCVのサンプルで用意されたものを使っています。
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
エラーは一番最初のforのループ内で発生します。
|
210
|
+
|
195
211
|
http://whitecats.dip.jp/up/download/1468892458.zip/attach
|
196
212
|
|
197
|
-
|
198
|
-
|
199
213
|
へプロジェクトフォルダをアップしました。
|
200
214
|
|
201
215
|
パスワードは0000です。
|
202
216
|
|
203
217
|
|
204
218
|
|
205
|
-
画像ファイルはOpenCVのサンプルで用意されたものを使っています。
|
206
|
-
|
207
219
|
|
208
220
|
|
209
221
|
どうかよろしくお願いいたします。
|
17
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -134,57 +134,57 @@
|
|
134
134
|
|
135
135
|
work 内のファイルは
|
136
136
|
|
137
|
-
"
|
138
|
-
|
139
|
-
"
|
140
|
-
|
141
|
-
"
|
142
|
-
|
143
|
-
"
|
144
|
-
|
145
|
-
"
|
146
|
-
|
147
|
-
"
|
148
|
-
|
149
|
-
"
|
150
|
-
|
151
|
-
"
|
152
|
-
|
153
|
-
"
|
154
|
-
|
155
|
-
"
|
156
|
-
|
157
|
-
"
|
158
|
-
|
159
|
-
"
|
160
|
-
|
161
|
-
"
|
162
|
-
|
163
|
-
"
|
164
|
-
|
165
|
-
"
|
166
|
-
|
167
|
-
"
|
168
|
-
|
169
|
-
"
|
170
|
-
|
171
|
-
"
|
172
|
-
|
173
|
-
"
|
174
|
-
|
175
|
-
"
|
176
|
-
|
177
|
-
"
|
178
|
-
|
179
|
-
"
|
180
|
-
|
181
|
-
"
|
182
|
-
|
183
|
-
"
|
184
|
-
|
185
|
-
"
|
186
|
-
|
187
|
-
"
|
137
|
+
"left01.jpg"
|
138
|
+
|
139
|
+
"right01.jpg"
|
140
|
+
|
141
|
+
"left02.jpg"
|
142
|
+
|
143
|
+
"right02.jpg"
|
144
|
+
|
145
|
+
"left03.jpg"
|
146
|
+
|
147
|
+
"right03.jpg"
|
148
|
+
|
149
|
+
"left04.jpg"
|
150
|
+
|
151
|
+
"right04.jpg"
|
152
|
+
|
153
|
+
"left05.jpg"
|
154
|
+
|
155
|
+
"right05.jpg"
|
156
|
+
|
157
|
+
"left06.jpg"
|
158
|
+
|
159
|
+
"right06.jpg"
|
160
|
+
|
161
|
+
"left07.jpg"
|
162
|
+
|
163
|
+
"right07.jpg"
|
164
|
+
|
165
|
+
"left08.jpg"
|
166
|
+
|
167
|
+
"right08.jpg"
|
168
|
+
|
169
|
+
"left09.jpg"
|
170
|
+
|
171
|
+
"right09.jpg"
|
172
|
+
|
173
|
+
"left11.jpg"
|
174
|
+
|
175
|
+
"right11.jpg"
|
176
|
+
|
177
|
+
"left12.jpg"
|
178
|
+
|
179
|
+
"right12.jpg"
|
180
|
+
|
181
|
+
"left13.jpg"
|
182
|
+
|
183
|
+
"right13.jpg"
|
184
|
+
|
185
|
+
"left14.jpg"
|
186
|
+
|
187
|
+
"right14.jpg"
|
188
188
|
|
189
189
|
と”stereo_calib.xml”
|
190
190
|
|
16
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,11 +64,11 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
-
XMLファイルの内容は
|
68
|
-
|
69
|
-
|
67
|
+
<?xml version="1.0"?>
|
70
|
-
|
68
|
+
|
71
|
-
<opencv_storage>
|
69
|
+
<opencv_storage>
|
70
|
+
|
71
|
+
<imagelist>
|
72
72
|
|
73
73
|
"C:/work/left01.jpg"
|
74
74
|
|
@@ -82,11 +82,41 @@
|
|
82
82
|
|
83
83
|
"C:/work/right03.jpg"
|
84
84
|
|
85
|
-
|
85
|
+
"C:/work/left04.jpg"
|
86
|
+
|
86
|
-
|
87
|
+
"C:/work/right04.jpg"
|
88
|
+
|
87
|
-
|
89
|
+
"C:/work/left05.jpg"
|
90
|
+
|
88
|
-
|
91
|
+
"C:/work/right05.jpg"
|
92
|
+
|
89
|
-
|
93
|
+
"C:/work/left06.jpg"
|
94
|
+
|
95
|
+
"C:/work/right06.jpg"
|
96
|
+
|
97
|
+
"C:/work/left07.jpg"
|
98
|
+
|
99
|
+
"C:/work/right07.jpg"
|
100
|
+
|
101
|
+
"C:/work/left08.jpg"
|
102
|
+
|
103
|
+
"C:/work/right08.jpg"
|
104
|
+
|
105
|
+
"C:/work/left09.jpg"
|
106
|
+
|
107
|
+
"C:/work/right09.jpg"
|
108
|
+
|
109
|
+
"C:/work/left11.jpg"
|
110
|
+
|
111
|
+
"C:/work/right11.jpg"
|
112
|
+
|
113
|
+
"C:/work/left12.jpg"
|
114
|
+
|
115
|
+
"C:/work/right12.jpg"
|
116
|
+
|
117
|
+
"C:/work/left13.jpg"
|
118
|
+
|
119
|
+
"C:/work/right13.jpg"
|
90
120
|
|
91
121
|
"C:/work/left14.jpg"
|
92
122
|
|
@@ -96,17 +126,79 @@
|
|
96
126
|
|
97
127
|
</opencv_storage>
|
98
128
|
|
129
|
+
|
130
|
+
|
99
131
|
としました。
|
100
132
|
|
101
133
|
|
102
134
|
|
103
|
-
コードをサンプルそのままの状態へ戻し
|
104
|
-
|
105
|
-
|
135
|
+
work 内のファイルは
|
136
|
+
|
106
|
-
|
137
|
+
"C:/work/left01.jpg"
|
138
|
+
|
107
|
-
|
139
|
+
"C:/work/right01.jpg"
|
140
|
+
|
108
|
-
|
141
|
+
"C:/work/left02.jpg"
|
142
|
+
|
143
|
+
"C:/work/right02.jpg"
|
144
|
+
|
145
|
+
"C:/work/left03.jpg"
|
146
|
+
|
147
|
+
"C:/work/right03.jpg"
|
148
|
+
|
149
|
+
"C:/work/left04.jpg"
|
150
|
+
|
151
|
+
"C:/work/right04.jpg"
|
152
|
+
|
153
|
+
"C:/work/left05.jpg"
|
154
|
+
|
155
|
+
"C:/work/right05.jpg"
|
156
|
+
|
157
|
+
"C:/work/left06.jpg"
|
158
|
+
|
159
|
+
"C:/work/right06.jpg"
|
160
|
+
|
161
|
+
"C:/work/left07.jpg"
|
162
|
+
|
163
|
+
"C:/work/right07.jpg"
|
164
|
+
|
165
|
+
"C:/work/left08.jpg"
|
166
|
+
|
167
|
+
"C:/work/right08.jpg"
|
168
|
+
|
169
|
+
"C:/work/left09.jpg"
|
170
|
+
|
171
|
+
"C:/work/right09.jpg"
|
172
|
+
|
173
|
+
"C:/work/left11.jpg"
|
174
|
+
|
175
|
+
"C:/work/right11.jpg"
|
176
|
+
|
177
|
+
"C:/work/left12.jpg"
|
178
|
+
|
179
|
+
"C:/work/right12.jpg"
|
180
|
+
|
181
|
+
"C:/work/left13.jpg"
|
182
|
+
|
183
|
+
"C:/work/right13.jpg"
|
184
|
+
|
185
|
+
"C:/work/left14.jpg"
|
186
|
+
|
187
|
+
"C:/work/right14.jpg"
|
188
|
+
|
189
|
+
と”stereo_calib.xml”
|
190
|
+
|
191
|
+
です。
|
192
|
+
|
193
|
+
|
194
|
+
|
109
|
-
|
195
|
+
http://whitecats.dip.jp/up/download/1468892458.zip/attach
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
へプロジェクトフォルダをアップしました。
|
200
|
+
|
201
|
+
パスワードは0000です。
|
110
202
|
|
111
203
|
|
112
204
|
|
@@ -114,8 +206,4 @@
|
|
114
206
|
|
115
207
|
|
116
208
|
|
117
|
-
コマンドライン引数の使い方、XMLファイルの書き方などを教えていただけないでしょうか。
|
118
|
-
|
119
|
-
|
120
|
-
|
121
209
|
どうかよろしくお願いいたします。
|
15
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -100,7 +100,7 @@
|
|
100
100
|
|
101
101
|
|
102
102
|
|
103
|
-
サンプルそのままの状態へ戻し
|
103
|
+
コードをサンプルそのままの状態へ戻し
|
104
104
|
|
105
105
|
コマンドプロンプトを起動し
|
106
106
|
|
14
誤記
test
CHANGED
File without changes
|
test
CHANGED
@@ -106,7 +106,7 @@
|
|
106
106
|
|
107
107
|
streo_calib.exe c:/work/stereo_calib.xmlで実行しましたが
|
108
108
|
|
109
|
-
goodImageList.push_back(imagelist[i * 2]); のところで
|
109
|
+
10回目のループでgoodImageList.push_back(imagelist[i * 2]); のところでエラーが出ているようです。
|
110
110
|
|
111
111
|
|
112
112
|
|
13
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,4 +50,72 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
+
サンプルを修正した点は
|
54
|
+
|
55
|
+
実行をするとコマンドライン引数の入力を待たずソフトが走ってしまうため サンプルを
|
56
|
+
|
57
|
+
cv::CommandLineParser parser(argc, argv, "{w|9|}{h|6|}{nr||}{help||}{@input|C:/work/stereo_calib.xml|}");
|
58
|
+
|
59
|
+
と
|
60
|
+
|
61
|
+
StereoCalib(imagelist, boardSize, true, true, true);
|
62
|
+
|
63
|
+
を変更しました。
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
XMLファイルの内容は
|
68
|
+
|
69
|
+
<?xml version="1.0"?>
|
70
|
+
|
71
|
+
<opencv_storage> <imagelist>
|
72
|
+
|
73
|
+
"C:/work/left01.jpg"
|
74
|
+
|
75
|
+
"C:/work/right01.jpg"
|
76
|
+
|
77
|
+
"C:/work/left02.jpg"
|
78
|
+
|
79
|
+
"C:/work/right02.jpg"
|
80
|
+
|
81
|
+
"C:/work/left03.jpg"
|
82
|
+
|
83
|
+
"C:/work/right03.jpg"
|
84
|
+
|
85
|
+
・
|
86
|
+
|
87
|
+
・
|
88
|
+
|
89
|
+
・
|
90
|
+
|
91
|
+
"C:/work/left14.jpg"
|
92
|
+
|
93
|
+
"C:/work/right14.jpg"
|
94
|
+
|
95
|
+
</imagelist>
|
96
|
+
|
97
|
+
</opencv_storage>
|
98
|
+
|
99
|
+
としました。
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
サンプルそのままの状態へ戻し
|
104
|
+
|
105
|
+
コマンドプロンプトを起動し
|
106
|
+
|
107
|
+
streo_calib.exe c:/work/stereo_calib.xmlで実行しましたが
|
108
|
+
|
109
|
+
goodImageList.push_back(imagelist[i * 2]); のところで10回目のループでエラーが出ているようです。
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
画像ファイルはOpenCVのサンプルで用意されたものを使っています。
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
コマンドライン引数の使い方、XMLファイルの書き方などを教えていただけないでしょうか。
|
118
|
+
|
119
|
+
|
120
|
+
|
53
121
|
どうかよろしくお願いいたします。
|
12
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
Unhandled exception at 0x000007FEFD16A06D in ConsoleApplication1.exe: Microsoft C++ exception: cv::Exception at memory location 0x00000000002CAD80.
|
12
12
|
|
13
|
-
とエラーが表示されます。
|
13
|
+
とvisualstdioの画面にエラーが表示されます。
|
14
14
|
|
15
15
|
またコンソールにも
|
16
16
|
|
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
画像
|
47
|
+
drawChessboardCornersで画像を出力してコーナーを検出しているのを確認しています。
|
48
48
|
|
49
49
|
|
50
50
|
|
11
削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,16 +50,4 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
他にimagelistのアドレスが
|
54
|
-
|
55
|
-
C:/opencv/sources/samples/data/left01.jpg
|
56
|
-
|
57
|
-
のように長いとエラーなります。
|
58
|
-
|
59
|
-
またobjectPoints.resize(nimages);でもエラーが出たため
|
60
|
-
|
61
|
-
配置位置を先頭付近へ変えたらエラーがでなくなりました。
|
62
|
-
|
63
|
-
|
64
|
-
|
65
53
|
どうかよろしくお願いいたします。
|
10
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,7 +50,11 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
他にimagelistのアドレスが
|
53
|
+
他にimagelistのアドレスが
|
54
|
+
|
55
|
+
C:/opencv/sources/samples/data/left01.jpg
|
56
|
+
|
57
|
+
のように長いとエラーなります。
|
54
58
|
|
55
59
|
またobjectPoints.resize(nimages);でもエラーが出たため
|
56
60
|
|
9
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
の引数はimagelist, boardSize, true, true, true
|
36
36
|
|
37
|
-
imagelistはC:/
|
37
|
+
imagelistはC:/work/left01.jpg,C:/work/right01.jpg・・・・でxmlファイルから読んでいます。
|
38
38
|
|
39
39
|
boardSizeはwidth=9,height=6です。
|
40
40
|
|
8
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,6 +11,18 @@
|
|
11
11
|
Unhandled exception at 0x000007FEFD16A06D in ConsoleApplication1.exe: Microsoft C++ exception: cv::Exception at memory location 0x00000000002CAD80.
|
12
12
|
|
13
13
|
とエラーが表示されます。
|
14
|
+
|
15
|
+
またコンソールにも
|
16
|
+
|
17
|
+
OpenCV Error:Assertion failed(nimages>0 && nimages == (int)imagePoint1.tota
|
18
|
+
|
19
|
+
l() && (!imgPtMat2 || nimages == (int)imagePoint2.total()) in cv::collectCalib
|
20
|
+
|
21
|
+
rationData, file C: \buildslave64\win64_amdoc|\master_PackSlave-win64-vc14-shared
|
22
|
+
|
23
|
+
\opencv\modules\calib3d\src\calibration.cpp, line 3054
|
24
|
+
|
25
|
+
と表示されます。
|
14
26
|
|
15
27
|
|
16
28
|
|
7
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,6 +32,10 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
+
画像でコーナーを検出しているのを確認しています。
|
36
|
+
|
37
|
+
|
38
|
+
|
35
39
|
|
36
40
|
|
37
41
|
他にimagelistのアドレスが長いとエラーなります。
|
6
編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,9 +1,3 @@
|
|
1
|
-
質問へ対応していただきありがとうございます。
|
2
|
-
|
3
|
-
現状を説明いたします。
|
4
|
-
|
5
|
-
|
6
|
-
|
7
1
|
環境はWindow7、visualstdio2015Enterprise x64、OpenCV3.1,
|
8
2
|
|
9
3
|
OpenCVのsamplesディレクトリ内にあるstereo_calib.cppを実行させたところエラーになります。
|
5
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
の引数はimagelist, boardSize, true, true, true
|
30
30
|
|
31
|
-
imagelistはC:/
|
31
|
+
imagelistはC:/a/left01.jpg,C:/a/right01.jpg・・・・でxmlファイルから読んでいます。
|
32
32
|
|
33
33
|
boardSizeはwidth=9,height=6です。
|
34
34
|
|
4
わかりにくかったため改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,570 +1,14 @@
|
|
1
|
-
|
1
|
+
質問へ対応していただきありがとうございます。
|
2
|
+
|
3
|
+
現状を説明いたします。
|
4
|
+
|
5
|
+
|
2
6
|
|
3
7
|
環境はWindow7、visualstdio2015Enterprise x64、OpenCV3.1,
|
4
8
|
|
5
|
-
|
9
|
+
OpenCVのsamplesディレクトリ内にあるstereo_calib.cppを実行させたところエラーになります。
|
6
10
|
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
static void
|
12
|
-
|
13
|
-
StereoCalib(const vector<string>& imagelist, Size boardSize, bool displayCorners = false, bool useCalibrated = true, bool showRectified = true)
|
14
|
-
|
15
|
-
{
|
16
|
-
|
17
|
-
cout << "imagelist.size() = " << imagelist.size() << endl;
|
18
|
-
|
19
|
-
if (imagelist.size() % 2 != 0)
|
20
|
-
|
21
|
-
{
|
22
|
-
|
23
|
-
cout << "Error: the image list contains odd (non-even) number of elements\n";
|
24
|
-
|
25
|
-
return;
|
26
|
-
|
27
|
-
}
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
const int maxScale = 2;
|
32
|
-
|
33
|
-
const float squareSize = 1.f; // Set this to your actual square size
|
34
|
-
|
35
|
-
// ARRAY AND VECTOR STORAGE:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
Size imageSize;
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
int i, j, k, nimages = (int)imagelist.size() / 2;
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
vector<vector<Point2f> > imagePoints[2];
|
48
|
-
|
49
|
-
vector<vector<Point3f> > objectPoints;
|
50
|
-
|
51
|
-
imagePoints[0].resize(nimages);
|
52
|
-
|
53
|
-
imagePoints[1].resize(nimages);
|
54
|
-
|
55
|
-
objectPoints.resize(nimages);
|
56
|
-
|
57
|
-
vector<string> goodImageList;
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
for (i = j = 0; i < nimages; i++)
|
62
|
-
|
63
|
-
{
|
64
|
-
|
65
|
-
for (k = 0; k < 2; k++)
|
66
|
-
|
67
|
-
{
|
68
|
-
|
69
|
-
const string& filename = imagelist[i * 2 + k];
|
70
|
-
|
71
|
-
cout << "filename = " << filename << endl;
|
72
|
-
|
73
|
-
Mat img = imread(filename, IMREAD_GRAYSCALE);
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
if (img.empty())
|
78
|
-
|
79
|
-
break;
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
if (imageSize == Size())
|
84
|
-
|
85
|
-
imageSize = img.size();
|
86
|
-
|
87
|
-
else if (img.size() != imageSize)
|
88
|
-
|
89
|
-
{
|
90
|
-
|
91
|
-
cout << "The image " << filename << " has the size different from the first image size. Skipping the pair\n";
|
92
|
-
|
93
|
-
break;
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
bool found = false;
|
98
|
-
|
99
|
-
vector<Point2f>& corners = imagePoints[k][j];
|
100
|
-
|
101
|
-
for (int scale = 1; scale <= maxScale; scale++)
|
102
|
-
|
103
|
-
{
|
104
|
-
|
105
|
-
Mat timg;
|
106
|
-
|
107
|
-
if (scale == 1)
|
108
|
-
|
109
|
-
timg = img;
|
110
|
-
|
111
|
-
else
|
112
|
-
|
113
|
-
resize(img, timg, Size(), scale, scale);
|
114
|
-
|
115
|
-
found = findChessboardCorners(timg, boardSize, corners,
|
116
|
-
|
117
|
-
CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE);
|
118
|
-
|
119
|
-
if (found)
|
120
|
-
|
121
|
-
{
|
122
|
-
|
123
|
-
if (scale > 1)
|
124
|
-
|
125
|
-
{
|
126
|
-
|
127
|
-
Mat cornersMat(corners);
|
128
|
-
|
129
|
-
cornersMat *= 1. / scale;
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
break;
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
if (displayCorners)
|
144
|
-
|
145
|
-
{
|
146
|
-
|
147
|
-
cout << filename << endl;
|
148
|
-
|
149
|
-
Mat cimg, cimg1;
|
150
|
-
|
151
|
-
cvtColor(img, cimg, COLOR_GRAY2BGR);
|
152
|
-
|
153
|
-
drawChessboardCorners(cimg, boardSize, corners, found);
|
154
|
-
|
155
|
-
double sf = 640. / MAX(img.rows, img.cols);
|
156
|
-
|
157
|
-
resize(cimg, cimg1, Size(), sf, sf);
|
158
|
-
|
159
|
-
imshow("corners", cimg1);
|
160
|
-
|
161
|
-
char c = (char)waitKey(500);
|
162
|
-
|
163
|
-
if (c == 27 || c == 'q' || c == 'Q') //Allow ESC to quit
|
164
|
-
|
165
|
-
exit(-1);
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
else
|
170
|
-
|
171
|
-
putchar('.');
|
172
|
-
|
173
|
-
if (!found)
|
174
|
-
|
175
|
-
break;
|
176
|
-
|
177
|
-
cornerSubPix(img, corners, Size(11, 11), Size(-1, -1),
|
178
|
-
|
179
|
-
TermCriteria(TermCriteria::COUNT + TermCriteria::EPS,
|
180
|
-
|
181
|
-
30, 0.01));
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
if (k == 2)
|
186
|
-
|
187
|
-
{
|
188
|
-
|
189
|
-
goodImageList.push_back(imagelist[i * 2]);
|
190
|
-
|
191
|
-
goodImageList.push_back(imagelist[i * 2 + 1]);
|
192
|
-
|
193
|
-
j++;
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
cout << j << " pairs have been successfully detected.\n";
|
200
|
-
|
201
|
-
nimages = j;
|
202
|
-
|
203
|
-
if (nimages < 2)
|
204
|
-
|
205
|
-
{
|
206
|
-
|
207
|
-
cout << "Error: too little pairs to run the calibration\n";
|
208
|
-
|
209
|
-
return;
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
imagePoints[0].resize(nimages);
|
216
|
-
|
217
|
-
imagePoints[1].resize(nimages);
|
218
|
-
|
219
|
-
//objectPoints.resize(nimages);
|
220
|
-
|
221
|
-
for (i = 0; i < nimages; i++)
|
222
|
-
|
223
|
-
{
|
224
|
-
|
225
|
-
for (j = 0; j < boardSize.height; j++)
|
226
|
-
|
227
|
-
for (k = 0; k < boardSize.width; k++)
|
228
|
-
|
229
|
-
objectPoints[i].push_back(Point3f(k*squareSize, j*squareSize, 0));
|
230
|
-
|
231
|
-
}
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
cout << "Running stereo calibration ...\n";
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
Mat cameraMatrix[2], distCoeffs[2];
|
240
|
-
|
241
|
-
cameraMatrix[0] = initCameraMatrix2D(objectPoints, imagePoints[0], imageSize, 0.0);
|
242
|
-
|
243
|
-
cameraMatrix[1] = initCameraMatrix2D(objectPoints, imagePoints[1], imageSize, 0.0);
|
244
|
-
|
245
|
-
// cameraMatrix[0] = Mat::eye(3, 3, CV_64F);
|
246
|
-
|
247
|
-
// cameraMatrix[1] = Mat::eye(3, 3, CV_64F);
|
248
|
-
|
249
|
-
Mat R, T, E, F;
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
double rms = stereoCalibrate(objectPoints, imagePoints[0], imagePoints[1],
|
254
|
-
|
255
|
-
cameraMatrix[0], distCoeffs[0],
|
256
|
-
|
257
|
-
cameraMatrix[1], distCoeffs[1],
|
258
|
-
|
259
|
-
imageSize, R, T, E, F,
|
260
|
-
|
261
|
-
CALIB_FIX_ASPECT_RATIO +
|
262
|
-
|
263
|
-
CALIB_ZERO_TANGENT_DIST +
|
264
|
-
|
265
|
-
CALIB_USE_INTRINSIC_GUESS +
|
266
|
-
|
267
|
-
CALIB_SAME_FOCAL_LENGTH +
|
268
|
-
|
269
|
-
CALIB_RATIONAL_MODEL +
|
270
|
-
|
271
|
-
CALIB_FIX_K3 + CALIB_FIX_K4 + CALIB_FIX_K5,
|
272
|
-
|
273
|
-
TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, 1e-5));
|
274
|
-
|
275
|
-
cout << "done with RMS error=" << rms << endl;
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
// CALIBRATION QUALITY CHECK
|
280
|
-
|
281
|
-
// because the output fundamental matrix implicitly
|
282
|
-
|
283
|
-
// includes all the output information,
|
284
|
-
|
285
|
-
// we can check the quality of calibration using the
|
286
|
-
|
287
|
-
// epipolar geometry constraint: m2^t*F*m1=0
|
288
|
-
|
289
|
-
double err = 0;
|
290
|
-
|
291
|
-
int npoints = 0;
|
292
|
-
|
293
|
-
vector<Vec3f> lines[2];
|
294
|
-
|
295
|
-
for (i = 0; i < nimages; i++)
|
296
|
-
|
297
|
-
{
|
298
|
-
|
299
|
-
int npt = (int)imagePoints[0][i].size();
|
300
|
-
|
301
|
-
Mat imgpt[2];
|
302
|
-
|
303
|
-
for (k = 0; k < 2; k++)
|
304
|
-
|
305
|
-
{
|
306
|
-
|
307
|
-
imgpt[k] = Mat(imagePoints[k][i]);
|
308
|
-
|
309
|
-
undistortPoints(imgpt[k], imgpt[k], cameraMatrix[k], distCoeffs[k], Mat(), cameraMatrix[k]);
|
310
|
-
|
311
|
-
computeCorrespondEpilines(imgpt[k], k + 1, F, lines[k]);
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
for (j = 0; j < npt; j++)
|
316
|
-
|
317
|
-
{
|
318
|
-
|
319
|
-
double errij = fabs(imagePoints[0][i][j].x*lines[1][j][0] +
|
320
|
-
|
321
|
-
imagePoints[0][i][j].y*lines[1][j][1] + lines[1][j][2]) +
|
322
|
-
|
323
|
-
fabs(imagePoints[1][i][j].x*lines[0][j][0] +
|
324
|
-
|
325
|
-
imagePoints[1][i][j].y*lines[0][j][1] + lines[0][j][2]);
|
326
|
-
|
327
|
-
err += errij;
|
328
|
-
|
329
|
-
}
|
330
|
-
|
331
|
-
npoints += npt;
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
|
-
cout << "average epipolar err = " << err / npoints << endl;
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
// save intrinsic parameters
|
340
|
-
|
341
|
-
FileStorage fs("C:/work/intrinsics.yml", FileStorage::WRITE);
|
342
|
-
|
343
|
-
if (fs.isOpened())
|
344
|
-
|
345
|
-
{
|
346
|
-
|
347
|
-
fs << "M1" << cameraMatrix[0] << "D1" << distCoeffs[0] <<
|
348
|
-
|
349
|
-
"M2" << cameraMatrix[1] << "D2" << distCoeffs[1];
|
350
|
-
|
351
|
-
fs.release();
|
352
|
-
|
353
|
-
}
|
354
|
-
|
355
|
-
else
|
356
|
-
|
357
|
-
cout << "Error: can not save the intrinsic parameters\n";
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
Mat R1, R2, P1, P2, Q;
|
362
|
-
|
363
|
-
Rect validRoi[2];
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
stereoRectify(cameraMatrix[0], distCoeffs[0],
|
368
|
-
|
369
|
-
cameraMatrix[1], distCoeffs[1],
|
370
|
-
|
371
|
-
imageSize, R, T, R1, R2, P1, P2, Q,
|
372
|
-
|
373
|
-
CALIB_ZERO_DISPARITY, 1, imageSize, &validRoi[0], &validRoi[1]);
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
fs.open("C:/work/extrinsics.yml", FileStorage::WRITE);
|
378
|
-
|
379
|
-
if (fs.isOpened())
|
380
|
-
|
381
|
-
{
|
382
|
-
|
383
|
-
fs << "R" << R << "T" << T << "R1" << R1 << "R2" << R2 << "P1" << P1 << "P2" << P2 << "Q" << Q;
|
384
|
-
|
385
|
-
fs.release();
|
386
|
-
|
387
|
-
}
|
388
|
-
|
389
|
-
else
|
390
|
-
|
391
|
-
cout << "Error: can not save the extrinsic parameters\n";
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
// OpenCV can handle left-right
|
396
|
-
|
397
|
-
// or up-down camera arrangements
|
398
|
-
|
399
|
-
bool isVerticalStereo = fabs(P2.at<double>(1, 3)) > fabs(P2.at<double>(0, 3));
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
// COMPUTE AND DISPLAY RECTIFICATION
|
404
|
-
|
405
|
-
if (!showRectified)
|
406
|
-
|
407
|
-
return;
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
Mat rmap[2][2];
|
412
|
-
|
413
|
-
// IF BY CALIBRATED (BOUGUET'S METHOD)
|
414
|
-
|
415
|
-
if (useCalibrated)
|
416
|
-
|
417
|
-
{
|
418
|
-
|
419
|
-
// we already computed everything
|
420
|
-
|
421
|
-
}
|
422
|
-
|
423
|
-
// OR ELSE HARTLEY'S METHOD
|
424
|
-
|
425
|
-
else
|
426
|
-
|
427
|
-
// use intrinsic parameters of each camera, but
|
428
|
-
|
429
|
-
// compute the rectification transformation directly
|
430
|
-
|
431
|
-
// from the fundamental matrix
|
432
|
-
|
433
|
-
{
|
434
|
-
|
435
|
-
vector<Point2f> allimgpt[2];
|
436
|
-
|
437
|
-
for (k = 0; k < 2; k++)
|
438
|
-
|
439
|
-
{
|
440
|
-
|
441
|
-
for (i = 0; i < nimages; i++)
|
442
|
-
|
443
|
-
std::copy(imagePoints[k][i].begin(), imagePoints[k][i].end(), back_inserter(allimgpt[k]));
|
444
|
-
|
445
|
-
}
|
446
|
-
|
447
|
-
F = findFundamentalMat(Mat(allimgpt[0]), Mat(allimgpt[1]), FM_8POINT, 0, 0);
|
448
|
-
|
449
|
-
Mat H1, H2;
|
450
|
-
|
451
|
-
stereoRectifyUncalibrated(Mat(allimgpt[0]), Mat(allimgpt[1]), F, imageSize, H1, H2, 3);
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
R1 = cameraMatrix[0].inv()*H1*cameraMatrix[0];
|
456
|
-
|
457
|
-
R2 = cameraMatrix[1].inv()*H2*cameraMatrix[1];
|
458
|
-
|
459
|
-
P1 = cameraMatrix[0];
|
460
|
-
|
461
|
-
P2 = cameraMatrix[1];
|
462
|
-
|
463
|
-
}
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
//Precompute maps for cv::remap()
|
468
|
-
|
469
|
-
initUndistortRectifyMap(cameraMatrix[0], distCoeffs[0], R1, P1, imageSize, CV_16SC2, rmap[0][0], rmap[0][1]);
|
470
|
-
|
471
|
-
initUndistortRectifyMap(cameraMatrix[1], distCoeffs[1], R2, P2, imageSize, CV_16SC2, rmap[1][0], rmap[1][1]);
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
Mat canvas;
|
476
|
-
|
477
|
-
double sf;
|
478
|
-
|
479
|
-
int w, h;
|
480
|
-
|
481
|
-
if (!isVerticalStereo)
|
482
|
-
|
483
|
-
{
|
484
|
-
|
485
|
-
sf = 600. / MAX(imageSize.width, imageSize.height);
|
486
|
-
|
487
|
-
w = cvRound(imageSize.width*sf);
|
488
|
-
|
489
|
-
h = cvRound(imageSize.height*sf);
|
490
|
-
|
491
|
-
canvas.create(h, w * 2, CV_8UC3);
|
492
|
-
|
493
|
-
}
|
494
|
-
|
495
|
-
else
|
496
|
-
|
497
|
-
{
|
498
|
-
|
499
|
-
sf = 300. / MAX(imageSize.width, imageSize.height);
|
500
|
-
|
501
|
-
w = cvRound(imageSize.width*sf);
|
502
|
-
|
503
|
-
h = cvRound(imageSize.height*sf);
|
504
|
-
|
505
|
-
canvas.create(h * 2, w, CV_8UC3);
|
506
|
-
|
507
|
-
}
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
for (i = 0; i < nimages; i++)
|
512
|
-
|
513
|
-
{
|
514
|
-
|
515
|
-
for (k = 0; k < 2; k++)
|
516
|
-
|
517
|
-
{
|
518
|
-
|
519
|
-
Mat img = imread(goodImageList[i * 2 + k], 0), rimg, cimg;
|
520
|
-
|
521
|
-
remap(img, rimg, rmap[k][0], rmap[k][1], INTER_LINEAR);
|
522
|
-
|
523
|
-
cvtColor(rimg, cimg, COLOR_GRAY2BGR);
|
524
|
-
|
525
|
-
Mat canvasPart = !isVerticalStereo ? canvas(Rect(w*k, 0, w, h)) : canvas(Rect(0, h*k, w, h));
|
526
|
-
|
527
|
-
resize(cimg, canvasPart, canvasPart.size(), 0, 0, INTER_AREA);
|
528
|
-
|
529
|
-
if (useCalibrated)
|
530
|
-
|
531
|
-
{
|
532
|
-
|
533
|
-
Rect vroi(cvRound(validRoi[k].x*sf), cvRound(validRoi[k].y*sf),
|
534
|
-
|
535
|
-
cvRound(validRoi[k].width*sf), cvRound(validRoi[k].height*sf));
|
536
|
-
|
537
|
-
rectangle(canvasPart, vroi, Scalar(0, 0, 255), 3, 8);
|
538
|
-
|
539
|
-
}
|
540
|
-
|
541
|
-
}
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
if (!isVerticalStereo)
|
546
|
-
|
547
|
-
for (j = 0; j < canvas.rows; j += 16)
|
548
|
-
|
549
|
-
line(canvas, Point(0, j), Point(canvas.cols, j), Scalar(0, 255, 0), 1, 8);
|
550
|
-
|
551
|
-
else
|
552
|
-
|
553
|
-
for (j = 0; j < canvas.cols; j += 16)
|
554
|
-
|
555
|
-
line(canvas, Point(j, 0), Point(j, canvas.rows), Scalar(0, 255, 0), 1, 8);
|
556
|
-
|
557
|
-
imshow("rectified", canvas);
|
558
|
-
|
559
|
-
char c = (char)waitKey();
|
560
|
-
|
561
|
-
if (c == 27 || c == 'q' || c == 'Q')
|
562
|
-
|
563
|
-
break;
|
564
|
-
|
565
|
-
}
|
566
|
-
|
567
|
-
}
|
568
12
|
|
569
13
|
実行をすると
|
570
14
|
|
@@ -574,4 +18,34 @@
|
|
574
18
|
|
575
19
|
とエラーが表示されます。
|
576
20
|
|
21
|
+
|
22
|
+
|
23
|
+
static void
|
24
|
+
|
25
|
+
StereoCalib(const vector<string>& imagelist, Size boardSize, bool displayCorners = false, bool useCalibrated = true, bool showRectified = true)
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
の引数はimagelist, boardSize, true, true, true
|
30
|
+
|
31
|
+
imagelistはC:/work/left01.jpg,C:/work/right01.jpg・・・・でxmlファイルから読んでいます。
|
32
|
+
|
33
|
+
boardSizeはwidth=9,height=6です。
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
実行方法はVisualStdioでDebugに設定してLocal Window Debuggerを押して実行しています。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
他にimagelistのアドレスが長いとエラーなります。
|
44
|
+
|
45
|
+
またobjectPoints.resize(nimages);でもエラーが出たため
|
46
|
+
|
47
|
+
配置位置を先頭付近へ変えたらエラーがでなくなりました。
|
48
|
+
|
49
|
+
|
50
|
+
|
577
51
|
どうかよろしくお願いいたします。
|
3
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,11 +72,7 @@
|
|
72
72
|
|
73
73
|
Mat img = imread(filename, IMREAD_GRAYSCALE);
|
74
74
|
|
75
|
-
|
75
|
+
|
76
|
-
|
77
|
-
//imshow("image", img);
|
78
|
-
|
79
|
-
//waitKey(0);
|
80
76
|
|
81
77
|
if (img.empty())
|
82
78
|
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
OpenCVでステレオ画像のキャリブレーションをしたいと考えています。
|
2
2
|
|
3
|
-
環境はWindow7、visualstdio2015Enterprise、OpenCV3.1,
|
3
|
+
環境はWindow7、visualstdio2015Enterprise x64、OpenCV3.1,
|
4
4
|
|
5
5
|
コードは
|
6
6
|
|
1
タグ追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|