質問編集履歴

4

削除の修正

2017/11/28 05:04

投稿

aiueoaiueoaiue
aiueoaiueoaiue

スコア94

test CHANGED
File without changes
test CHANGED
@@ -1 +1,251 @@
1
1
  #EclipseでJava用のOpenCVのプログラムを動かしたい
2
+
3
+ Eclipseで2つの画像を比較した時のヒストグラム値を算出するというプログラムを動かしたいのですが、エラーが出てしまいどうすればよいかわかりません。
4
+
5
+
6
+
7
+ ソースは以下に示した通りです。
8
+
9
+
10
+
11
+ ```ここに言語を入力
12
+
13
+ package def;
14
+
15
+
16
+
17
+ import java.util.ArrayList;
18
+
19
+ import java.util.List;
20
+
21
+
22
+
23
+ import org.opencv.core.*;
24
+
25
+ import org.opencv.imgcodecs.*;
26
+
27
+ import org.opencv.imgproc.Imgproc;
28
+
29
+
30
+
31
+ public class ImageComparison {
32
+
33
+ public static void main(String[] args) {
34
+
35
+ System.out.println("処理開始");
36
+
37
+ System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
38
+
39
+ new Demo().run();
40
+
41
+
42
+
43
+ System.out.println("処理終了");
44
+
45
+ }
46
+
47
+ }
48
+
49
+
50
+
51
+ class Demo {
52
+
53
+ public void run() {
54
+
55
+ List<Double> histList = new ArrayList<Double>();
56
+
57
+
58
+
59
+ System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
60
+
61
+ Mat image[] = new Mat[2];
62
+
63
+ image[0] = Imgcodecs.imread("source/name1.png");
64
+
65
+ image[1] = Imgcodecs.imread("source/name2.png");
66
+
67
+ Mat hist1 = new Mat();
68
+
69
+
70
+
71
+ Imgproc.cvtColor(image[0], image[0], Imgproc.COLOR_RGB2GRAY);
72
+
73
+ Imgproc.cvtColor(image[1], image[1], Imgproc.COLOR_RGB2GRAY);
74
+
75
+
76
+
77
+ List<Mat> src1 = new ArrayList<Mat>();
78
+
79
+ src1.add(image[0]);
80
+
81
+
82
+
83
+ Imgproc.calcHist(src1, new MatOfInt(0), new Mat(), hist1, new MatOfInt(256), new MatOfFloat(0, 64));
84
+
85
+
86
+
87
+ Mat hist2 = new Mat();
88
+
89
+ List<Mat> src2 = new ArrayList<Mat>();
90
+
91
+ src2.add(image[1]);
92
+
93
+
94
+
95
+ Imgproc.calcHist(src2, new MatOfInt(0), new Mat(), hist2, new MatOfInt(256), new MatOfFloat(0, 64));
96
+
97
+
98
+
99
+ histList.add(Imgproc.compareHist(hist1, hist2, 0));
100
+
101
+
102
+
103
+ Imgcodecs.imwrite("source/test.png", image[0]);
104
+
105
+ System.out.println(image[0]);
106
+
107
+ System.out.println(image[1]);
108
+
109
+ System.out.println(histList);
110
+
111
+ }
112
+
113
+
114
+
115
+
116
+
117
+ }
118
+
119
+ ```
120
+
121
+ #エラーメッセージ
122
+
123
+ Exception in thread "main" java.lang.Error: Unresolved compilation problem:
124
+
125
+ Core を変数に解決できません
126
+
127
+
128
+
129
+ at def.ImageComparison.main(ImageComparison.java:13)
130
+
131
+ #試したこと
132
+
133
+ teratailで似た質問を見かけ、変数のスコープが関係しているらしいというのはわかったのですが、何分初心者なものでよくわかりませんでした。
134
+
135
+ #最終的なソース
136
+
137
+ ```Java
138
+
139
+ package def;
140
+
141
+
142
+
143
+ import java.util.ArrayList;
144
+
145
+ import java.util.List;
146
+
147
+
148
+
149
+ import org.opencv.core.Core;
150
+
151
+ import org.opencv.core.Mat;
152
+
153
+ import org.opencv.core.MatOfFloat;
154
+
155
+ import org.opencv.core.MatOfInt;
156
+
157
+ import org.opencv.imgcodecs.Imgcodecs;
158
+
159
+ import org.opencv.imgproc.Imgproc;
160
+
161
+
162
+
163
+ public class ImageComparison {
164
+
165
+ public static void main(String[] args) {
166
+
167
+ System.out.println("処理開始");
168
+
169
+ System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
170
+
171
+ new Demo().run();
172
+
173
+
174
+
175
+ System.out.println("処理終了");
176
+
177
+ }
178
+
179
+ }
180
+
181
+
182
+
183
+ class Demo {
184
+
185
+ public void run() {
186
+
187
+ List<Double> histList = new ArrayList<Double>();
188
+
189
+
190
+
191
+ System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
192
+
193
+ Mat image[] = new Mat[2];
194
+
195
+ image[0] = Imgcodecs.imread("F:\yamauchi\opencv-IC\source\name1.png");
196
+
197
+ image[1] = Imgcodecs.imread("F:\yamauchi\opencv-IC\source\name2.png");
198
+
199
+ Mat hist1 = new Mat();
200
+
201
+
202
+
203
+ Imgproc.cvtColor(image[0], image[0], Imgproc.COLOR_RGB2GRAY); // 逕サ蜒上・繧ー繝ャ繝シ繧ケ繧ア繝シ繝ォ螟画鋤
204
+
205
+ Imgproc.cvtColor(image[1], image[1], Imgproc.COLOR_RGB2GRAY);
206
+
207
+
208
+
209
+ List<Mat> src1 = new ArrayList<Mat>();
210
+
211
+ src1.add(image[0]);
212
+
213
+
214
+
215
+ Imgproc.calcHist(src1, new MatOfInt(0), new Mat(), hist1, new MatOfInt(256), new MatOfFloat(0, 64));
216
+
217
+
218
+
219
+ Mat hist2 = new Mat();
220
+
221
+ List<Mat> src2 = new ArrayList<Mat>();
222
+
223
+ src2.add(image[1]);
224
+
225
+
226
+
227
+ Imgproc.calcHist(src2, new MatOfInt(0), new Mat(), hist2, new MatOfInt(256), new MatOfFloat(0, 64));
228
+
229
+
230
+
231
+ histList.add(Imgproc.compareHist(hist1, hist2, 0));
232
+
233
+
234
+
235
+ Imgcodecs.imwrite("source/test.png", image[0]);
236
+
237
+ System.out.println(image[0]);
238
+
239
+ System.out.println(image[1]);
240
+
241
+ System.out.println(histList);
242
+
243
+ }
244
+
245
+
246
+
247
+
248
+
249
+ }
250
+
251
+ ```

3

修正

2017/11/28 05:04

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,251 +1 @@
1
1
  #EclipseでJava用のOpenCVのプログラムを動かしたい
2
-
3
- Eclipseで2つの画像を比較した時のヒストグラム値を算出するというプログラムを動かしたいのですが、エラーが出てしまいどうすればよいかわかりません。
4
-
5
-
6
-
7
- ソースは以下に示した通りです。
8
-
9
-
10
-
11
- ```ここに言語を入力
12
-
13
- package def;
14
-
15
-
16
-
17
- import java.util.ArrayList;
18
-
19
- import java.util.List;
20
-
21
-
22
-
23
- import org.opencv.core.*;
24
-
25
- import org.opencv.imgcodecs.*;
26
-
27
- import org.opencv.imgproc.Imgproc;
28
-
29
-
30
-
31
- public class ImageComparison {
32
-
33
- public static void main(String[] args) {
34
-
35
- System.out.println("処理開始");
36
-
37
- System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
38
-
39
- new Demo().run();
40
-
41
-
42
-
43
- System.out.println("処理終了");
44
-
45
- }
46
-
47
- }
48
-
49
-
50
-
51
- class Demo {
52
-
53
- public void run() {
54
-
55
- List<Double> histList = new ArrayList<Double>();
56
-
57
-
58
-
59
- System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
60
-
61
- Mat image[] = new Mat[2];
62
-
63
- image[0] = Imgcodecs.imread("source/name1.png");
64
-
65
- image[1] = Imgcodecs.imread("source/name2.png");
66
-
67
- Mat hist1 = new Mat();
68
-
69
-
70
-
71
- Imgproc.cvtColor(image[0], image[0], Imgproc.COLOR_RGB2GRAY);
72
-
73
- Imgproc.cvtColor(image[1], image[1], Imgproc.COLOR_RGB2GRAY);
74
-
75
-
76
-
77
- List<Mat> src1 = new ArrayList<Mat>();
78
-
79
- src1.add(image[0]);
80
-
81
-
82
-
83
- Imgproc.calcHist(src1, new MatOfInt(0), new Mat(), hist1, new MatOfInt(256), new MatOfFloat(0, 64));
84
-
85
-
86
-
87
- Mat hist2 = new Mat();
88
-
89
- List<Mat> src2 = new ArrayList<Mat>();
90
-
91
- src2.add(image[1]);
92
-
93
-
94
-
95
- Imgproc.calcHist(src2, new MatOfInt(0), new Mat(), hist2, new MatOfInt(256), new MatOfFloat(0, 64));
96
-
97
-
98
-
99
- histList.add(Imgproc.compareHist(hist1, hist2, 0));
100
-
101
-
102
-
103
- Imgcodecs.imwrite("source/test.png", image[0]);
104
-
105
- System.out.println(image[0]);
106
-
107
- System.out.println(image[1]);
108
-
109
- System.out.println(histList);
110
-
111
- }
112
-
113
-
114
-
115
-
116
-
117
- }
118
-
119
- ```
120
-
121
- #エラーメッセージ
122
-
123
- Exception in thread "main" java.lang.Error: Unresolved compilation problem:
124
-
125
- Core を変数に解決できません
126
-
127
-
128
-
129
- at def.ImageComparison.main(ImageComparison.java:13)
130
-
131
- #試したこと
132
-
133
- teratailで似た質問を見かけ、変数のスコープが関係しているらしいというのはわかったのですが、何分初心者なものでよくわかりませんでした。
134
-
135
- #最終的なソース
136
-
137
- ```Java
138
-
139
- package def;
140
-
141
-
142
-
143
- import java.util.ArrayList;
144
-
145
- import java.util.List;
146
-
147
-
148
-
149
- import org.opencv.core.Core;
150
-
151
- import org.opencv.core.Mat;
152
-
153
- import org.opencv.core.MatOfFloat;
154
-
155
- import org.opencv.core.MatOfInt;
156
-
157
- import org.opencv.imgcodecs.Imgcodecs;
158
-
159
- import org.opencv.imgproc.Imgproc;
160
-
161
-
162
-
163
- public class ImageComparison {
164
-
165
- public static void main(String[] args) {
166
-
167
- System.out.println("処理開始");
168
-
169
- System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
170
-
171
- new Demo().run();
172
-
173
-
174
-
175
- System.out.println("処理終了");
176
-
177
- }
178
-
179
- }
180
-
181
-
182
-
183
- class Demo {
184
-
185
- public void run() {
186
-
187
- List<Double> histList = new ArrayList<Double>();
188
-
189
-
190
-
191
- System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
192
-
193
- Mat image[] = new Mat[2];
194
-
195
- image[0] = Imgcodecs.imread("F:\yamauchi\opencv-IC\source\name1.png");
196
-
197
- image[1] = Imgcodecs.imread("F:\yamauchi\opencv-IC\source\name2.png");
198
-
199
- Mat hist1 = new Mat();
200
-
201
-
202
-
203
- Imgproc.cvtColor(image[0], image[0], Imgproc.COLOR_RGB2GRAY); // 逕サ蜒上・繧ー繝ャ繝シ繧ケ繧ア繝シ繝ォ螟画鋤
204
-
205
- Imgproc.cvtColor(image[1], image[1], Imgproc.COLOR_RGB2GRAY);
206
-
207
-
208
-
209
- List<Mat> src1 = new ArrayList<Mat>();
210
-
211
- src1.add(image[0]);
212
-
213
-
214
-
215
- Imgproc.calcHist(src1, new MatOfInt(0), new Mat(), hist1, new MatOfInt(256), new MatOfFloat(0, 64));
216
-
217
-
218
-
219
- Mat hist2 = new Mat();
220
-
221
- List<Mat> src2 = new ArrayList<Mat>();
222
-
223
- src2.add(image[1]);
224
-
225
-
226
-
227
- Imgproc.calcHist(src2, new MatOfInt(0), new Mat(), hist2, new MatOfInt(256), new MatOfFloat(0, 64));
228
-
229
-
230
-
231
- histList.add(Imgproc.compareHist(hist1, hist2, 0));
232
-
233
-
234
-
235
- Imgcodecs.imwrite("source/test.png", image[0]);
236
-
237
- System.out.println(image[0]);
238
-
239
- System.out.println(image[1]);
240
-
241
- System.out.println(histList);
242
-
243
- }
244
-
245
-
246
-
247
-
248
-
249
- }
250
-
251
- ```

2

追記

2017/11/14 12:38

投稿

aiueoaiueoaiue
aiueoaiueoaiue

スコア94

test CHANGED
File without changes
test CHANGED
@@ -131,3 +131,121 @@
131
131
  #試したこと
132
132
 
133
133
  teratailで似た質問を見かけ、変数のスコープが関係しているらしいというのはわかったのですが、何分初心者なものでよくわかりませんでした。
134
+
135
+ #最終的なソース
136
+
137
+ ```Java
138
+
139
+ package def;
140
+
141
+
142
+
143
+ import java.util.ArrayList;
144
+
145
+ import java.util.List;
146
+
147
+
148
+
149
+ import org.opencv.core.Core;
150
+
151
+ import org.opencv.core.Mat;
152
+
153
+ import org.opencv.core.MatOfFloat;
154
+
155
+ import org.opencv.core.MatOfInt;
156
+
157
+ import org.opencv.imgcodecs.Imgcodecs;
158
+
159
+ import org.opencv.imgproc.Imgproc;
160
+
161
+
162
+
163
+ public class ImageComparison {
164
+
165
+ public static void main(String[] args) {
166
+
167
+ System.out.println("処理開始");
168
+
169
+ System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
170
+
171
+ new Demo().run();
172
+
173
+
174
+
175
+ System.out.println("処理終了");
176
+
177
+ }
178
+
179
+ }
180
+
181
+
182
+
183
+ class Demo {
184
+
185
+ public void run() {
186
+
187
+ List<Double> histList = new ArrayList<Double>();
188
+
189
+
190
+
191
+ System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
192
+
193
+ Mat image[] = new Mat[2];
194
+
195
+ image[0] = Imgcodecs.imread("F:\yamauchi\opencv-IC\source\name1.png");
196
+
197
+ image[1] = Imgcodecs.imread("F:\yamauchi\opencv-IC\source\name2.png");
198
+
199
+ Mat hist1 = new Mat();
200
+
201
+
202
+
203
+ Imgproc.cvtColor(image[0], image[0], Imgproc.COLOR_RGB2GRAY); // 逕サ蜒上・繧ー繝ャ繝シ繧ケ繧ア繝シ繝ォ螟画鋤
204
+
205
+ Imgproc.cvtColor(image[1], image[1], Imgproc.COLOR_RGB2GRAY);
206
+
207
+
208
+
209
+ List<Mat> src1 = new ArrayList<Mat>();
210
+
211
+ src1.add(image[0]);
212
+
213
+
214
+
215
+ Imgproc.calcHist(src1, new MatOfInt(0), new Mat(), hist1, new MatOfInt(256), new MatOfFloat(0, 64));
216
+
217
+
218
+
219
+ Mat hist2 = new Mat();
220
+
221
+ List<Mat> src2 = new ArrayList<Mat>();
222
+
223
+ src2.add(image[1]);
224
+
225
+
226
+
227
+ Imgproc.calcHist(src2, new MatOfInt(0), new Mat(), hist2, new MatOfInt(256), new MatOfFloat(0, 64));
228
+
229
+
230
+
231
+ histList.add(Imgproc.compareHist(hist1, hist2, 0));
232
+
233
+
234
+
235
+ Imgcodecs.imwrite("source/test.png", image[0]);
236
+
237
+ System.out.println(image[0]);
238
+
239
+ System.out.println(image[1]);
240
+
241
+ System.out.println(histList);
242
+
243
+ }
244
+
245
+
246
+
247
+
248
+
249
+ }
250
+
251
+ ```

1

ソースコードを見やすくした

2017/11/11 09:23

投稿

aiueoaiueoaiue
aiueoaiueoaiue

スコア94

test CHANGED
File without changes
test CHANGED
@@ -7,6 +7,8 @@
7
7
  ソースは以下に示した通りです。
8
8
 
9
9
 
10
+
11
+ ```ここに言語を入力
10
12
 
11
13
  package def;
12
14
 
@@ -66,7 +68,7 @@
66
68
 
67
69
 
68
70
 
69
- Imgproc.cvtColor(image[0], image[0], Imgproc.COLOR_RGB2GRAY); // 逕サ蜒上・繧ー繝ャ繝シ繧ケ繧ア繝シ繝ォ螟画鋤
71
+ Imgproc.cvtColor(image[0], image[0], Imgproc.COLOR_RGB2GRAY);
70
72
 
71
73
  Imgproc.cvtColor(image[1], image[1], Imgproc.COLOR_RGB2GRAY);
72
74
 
@@ -114,6 +116,8 @@
114
116
 
115
117
  }
116
118
 
119
+ ```
120
+
117
121
  #エラーメッセージ
118
122
 
119
123
  Exception in thread "main" java.lang.Error: Unresolved compilation problem: